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)
64 lines • 1.36 kB
JavaScript
export class Line {
get x1() {
return this._x1;
}
get y1() {
return this._y1;
}
get x2() {
return this._x2;
}
get y2() {
return this._y2;
}
get dx() {
return this._x2 - this._x1;
}
get dy() {
return this._y2 - this._y1;
}
constructor(x1, y1, x2, y2) {
this._x1 = x1;
this._y1 = y1;
this._x2 = x2;
this._y2 = y2;
}
static from(other) {
return new Line(other.x1, other.y1, other.x2, other.y2);
}
movePoint1(x, y) {
this._x1 = x;
this._y1 = y;
}
movePoint2(x, y) {
this._x2 = x;
this._y2 = y;
}
swapXY1() {
const tmp = this._x1;
this._x1 = this._y1;
this._y1 = tmp;
}
swapXY2() {
const tmp = this._x2;
this._x2 = this._y2;
this._y2 = tmp;
}
flipX() {
const tmp = this._x1;
this._x1 = this._x2;
this._x2 = tmp;
}
flipY() {
const tmp = this._y1;
this._y1 = this._y2;
this._y2 = tmp;
}
clone() {
return new Line(this._x1, this._y1, this._x2, this._y2);
}
toString() {
return `${this.constructor.name} (x1: ${this._x1}, y1: ${this._y1}, x2: ${this._x2}, y2: ${this._y2})`;
}
}
//# sourceMappingURL=line.js.map