UNPKG

@aurigma/design-atoms-model

Version:

Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.

77 lines 2.46 kB
import { ConvertDegreeToRadian, EqualsOfFloatNumbers } from "./Common"; export class PointF { constructor(x, y) { this.x = 0; this.y = 0; this.x = x || 0; this.y = y || 0; } rotate(angle) { return this.rotateAt(angle, new PointF(0, 0)); } rotateAt(angle, center) { if (!center) center = new PointF(0, 0); var radianAngle = ConvertDegreeToRadian(angle); var newX = Math.cos(radianAngle) * (this.x - center.x) - Math.sin(radianAngle) * (this.y - center.y) + center.x; var newY = Math.sin(radianAngle) * (this.x - center.x) + Math.cos(radianAngle) * (this.y - center.y) + center.y; this.x = newX; this.y = newY; return this; } translate(x, y) { this.x = this.x + x; this.y = this.y + y; return this; } scale(scaleX, scaleY) { this.x = this.x * scaleX; this.y = this.y * scaleY; return this; } clone() { return new PointF(this.x, this.y); } equals(pt, tolerance) { return pt != null && EqualsOfFloatNumbers(this.x, pt.x, tolerance) && EqualsOfFloatNumbers(this.y, pt.y, tolerance); } static isEqual(a, b, tolerance = 0.0001) { if (a == null && b == null) return true; if (a == null || b == null) return false; return a.equals(b); } distance(pt) { return Math.sqrt((this.x - pt.x) * (this.x - pt.x) + (this.y - pt.y) * (this.y - pt.y)); } transform(transform, center) { if (center == null) center = new PointF(); this.translate(-center.x, -center.y); this.scale(transform.scaleX, transform.scaleY); this.rotate(transform.angle); this.translate(transform.translateX, transform.translateY); this.translate(center.x, center.y); return this; } toString() { var p = [this.x.toFixed(2), this.y.toFixed(2)]; return p.join(","); } toIPoint() { return { x: this.x, y: this.y }; } static fromIPoint(point) { return new PointF(point.x, point.y); } round() { this.x = Math.round(this.x); this.y = Math.round(this.y); return this; } isOrigin() { return this.x === 0 && this.y === 0; } } //# sourceMappingURL=PointF.js.map