Release package version 0.0.4
All checks were successful
CI / build (push) Successful in 21s

Added scale and translate methods for rectangle
This commit is contained in:
Andrey Kernichniy 2026-03-15 19:27:42 +07:00
parent 4dbba31ed5
commit 8c0e798bc7
2 changed files with 22 additions and 1 deletions

View file

@ -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);
} }

View file

@ -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": {