@panyam/tsutils
Version:
Some basic TS utils for personal use
62 lines • 1.62 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Rect = exports.Insets = exports.Size = exports.Point = void 0;
class Point {
constructor(x = 0, y = 0) {
this.x = x;
this.y = y;
}
}
exports.Point = Point;
class Size {
constructor(w = 0, h = 0) {
this.width = 0;
this.height = 0;
this.width = w;
this.height = h;
}
}
exports.Size = Size;
class Insets {
constructor(left = 0, top = 0, right = 0, bottom = 0) {
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
}
exports.Insets = Insets;
class Rect {
constructor(x = 0, y = 0, width = 0, height = 0) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
static from(box) {
return new Rect(box.x, box.y, box.width, box.height);
}
copy() {
return Rect.from(this);
}
union(another) {
if (another) {
const minX = Math.min(this.x, another.x);
const minY = Math.min(this.y, another.y);
const maxX = Math.max(this.x + this.width, another.x + another.width);
const maxY = Math.max(this.y + this.height, another.y + another.height);
this.x = minX;
this.y = minY;
this.width = maxX - minX;
this.height = maxY - minY;
}
return this;
}
unionAll(...boxes) {
for (const b of boxes)
this.union(b);
return this;
}
}
exports.Rect = Rect;
//# sourceMappingURL=geom.js.map