@visactor/vtable
Version:
canvas table width high performance
71 lines (66 loc) • 1.63 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.Rect = void 0;
const vutils_1 = require("@visactor/vutils");
class Rect {
constructor(left, top, width, height) {
this.bounds = new vutils_1.Bounds, this.bounds.set(left, top, left + width, top + height);
}
static bounds(left, top, right, bottom) {
return new Rect(left, top, Math.round(right - left), Math.round(bottom - top));
}
get left() {
return this.bounds.x1;
}
set left(left) {
this.bounds.x1 = left;
}
get top() {
return this.bounds.y1;
}
set top(top) {
this.bounds.y1 = top;
}
get right() {
return this.bounds.x2;
}
set right(right) {
this.bounds.x2 = right;
}
get bottom() {
return this.bounds.y2;
}
set bottom(bottom) {
this.bounds.y2 = bottom;
}
get width() {
return this.bounds.width();
}
set width(width) {
this.bounds.x2 = this.bounds.x1 + width;
}
get height() {
return this.bounds.height();
}
set height(height) {
this.bounds.y2 = this.bounds.y1 + height;
}
offsetLeft(offset) {
this.bounds.translate(offset, 0);
}
offsetTop(offset) {
this.bounds.translate(0, offset);
}
copy() {
return new Rect(this.left, this.top, this.width, this.height);
}
contains(another) {
return this.bounds.encloses(another.bounds);
}
inPoint(x, y) {
return this.bounds.contains(x, y);
}
}
exports.Rect = Rect;
//# sourceMappingURL=Rect.js.map