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.

80 lines 2.96 kB
import { ConvertDegreeToRadian, EqualsOfFloatNumbers } from "./Common"; var PointF = /** @class */ (function () { function PointF(x, y) { this.x = 0; this.y = 0; this.x = x || 0; this.y = y || 0; } PointF.prototype.rotate = function (angle) { return this.rotateAt(angle, new PointF(0, 0)); }; PointF.prototype.rotateAt = function (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; }; PointF.prototype.translate = function (x, y) { this.x = this.x + x; this.y = this.y + y; return this; }; PointF.prototype.scale = function (scaleX, scaleY) { this.x = this.x * scaleX; this.y = this.y * scaleY; return this; }; PointF.prototype.clone = function () { return new PointF(this.x, this.y); }; PointF.prototype.equals = function (pt, tolerance) { return pt != null && EqualsOfFloatNumbers(this.x, pt.x, tolerance) && EqualsOfFloatNumbers(this.y, pt.y, tolerance); }; PointF.isEqual = function (a, b, tolerance) { if (tolerance === void 0) { tolerance = 0.0001; } if (a == null && b == null) return true; if (a == null || b == null) return false; return a.equals(b); }; PointF.prototype.distance = function (pt) { return Math.sqrt((this.x - pt.x) * (this.x - pt.x) + (this.y - pt.y) * (this.y - pt.y)); }; PointF.prototype.transform = function (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; }; PointF.prototype.toString = function () { var p = [this.x.toFixed(2), this.y.toFixed(2)]; return p.join(","); }; PointF.prototype.toIPoint = function () { return { x: this.x, y: this.y }; }; PointF.fromIPoint = function (point) { return new PointF(point.x, point.y); }; PointF.prototype.round = function () { this.x = Math.round(this.x); this.y = Math.round(this.y); return this; }; PointF.prototype.isOrigin = function () { return this.x === 0 && this.y === 0; }; return PointF; }()); export { PointF }; //# sourceMappingURL=PointF.js.map