image-in-browser
Version:
Package for encoding / decoding images, transforming images, applying filters, drawing primitives on images on the client side (no need for server Node.js)
49 lines • 1.35 kB
JavaScript
import { Point } from './point.js';
export class Rectangle {
get left() {
return this._left;
}
get top() {
return this._top;
}
get right() {
return this._right;
}
get bottom() {
return this._bottom;
}
get width() {
return this._right - this._left;
}
get height() {
return this._bottom - this._top;
}
get topLeft() {
return new Point(this._left, this._top);
}
get topRight() {
return new Point(this._right, this._top);
}
get bottomLeft() {
return new Point(this._left, this._bottom);
}
get bottomRight() {
return new Point(this._right, this._bottom);
}
constructor(x1, y1, x2, y2) {
this._left = Math.min(x1, x2);
this._top = Math.min(y1, y2);
this._right = Math.max(x1, x2);
this._bottom = Math.max(y1, y2);
}
static fromXYWH(x, y, width, height) {
return new Rectangle(x, y, x + width, y + height);
}
static from(other) {
return new Rectangle(other._left, other._top, other._right, other._bottom);
}
toString() {
return `${this.constructor.name} (l: ${this._left}, t: ${this._top}, r: ${this._right}, b: ${this._bottom}, w: ${this.width}, h: ${this.height})`;
}
}
//# sourceMappingURL=rectangle.js.map