generated from gxc-solutions/gxc-template-repo
Added scale and translate methods for rectangle
This commit is contained in:
parent
4dbba31ed5
commit
8c0e798bc7
2 changed files with 22 additions and 1 deletions
|
|
@ -58,6 +58,27 @@ export class Rectangle {
|
||||||
throw new Error("Not implemented!");
|
throw new Error("Not implemented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scale(scaleX: number, scaleY: number, fromCenter = false): Rectangle {
|
||||||
|
if (fromCenter) {
|
||||||
|
const centerX = this.x + this.width / 2;
|
||||||
|
const centerY = this.y + this.height / 2;
|
||||||
|
|
||||||
|
const newWidth = this.width * scaleX;
|
||||||
|
const newHeight = this.height * scaleY;
|
||||||
|
|
||||||
|
const newX = centerX - newWidth / 2;
|
||||||
|
const newY = centerY - newHeight / 2;
|
||||||
|
|
||||||
|
return new Rectangle(newX, newY, newWidth, newHeight);
|
||||||
|
} else {
|
||||||
|
return new Rectangle(this.x, this.y, this.width * scaleX, this.height * scaleY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
translate(x: number, y: number): Rectangle {
|
||||||
|
return new Rectangle(this.x + x, this.y + y, this.width, this.height);
|
||||||
|
}
|
||||||
|
|
||||||
static fromPoints(left: number, top: number, right: number, bottom: number) {
|
static fromPoints(left: number, top: number, right: number, bottom: number) {
|
||||||
return new Rectangle(left, top, right - left, bottom - top);
|
return new Rectangle(left, top, right - left, bottom - top);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@gxc-solutions/math",
|
"name": "@gxc-solutions/math",
|
||||||
"version": "0.0.3",
|
"version": "0.0.4",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"author": "GXC Solutions",
|
"author": "GXC Solutions",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue