@gravity-ui/graph
Version:
Modern graph editor component
43 lines (42 loc) • 1.02 kB
JavaScript
import isObject from "lodash/isObject";
export class Point {
constructor(x, y, origPoint) {
this.x = x;
this.y = y;
this.origPoint = origPoint || {
x,
y,
};
}
toArray() {
return [this.x, this.y];
}
toObject() {
return { x: this.x, y: this.y };
}
}
export function isTRect(rect) {
return (isObject(rect) &&
"x" in rect &&
typeof rect.x === "number" &&
"y" in rect &&
typeof rect.y === "number" &&
"width" in rect &&
typeof rect.width === "number" &&
"height" in rect &&
typeof rect.height === "number");
}
export class Rect {
constructor(x, y, width, height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
toArray() {
return [this.x, this.y, this.width, this.height];
}
toObject() {
return { x: this.x, y: this.y, width: this.width, height: this.height };
}
}