UNPKG

svg-path-d

Version:

SVG path data (path[d] attribute content) manipulation library.

50 lines 1.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.twoVectorsAngle = exports.addRect = exports.addPoint = exports.addY = exports.addX = exports.fromPoint = exports.isPointIn = exports.isPointOut = void 0; function isPointOut(rect, x, y) { return x < rect.left || x > rect.right || y < rect.top || y > rect.bottom; } exports.isPointOut = isPointOut; function isPointIn(rect, x, y) { return !isPointOut(rect, x, y); } exports.isPointIn = isPointIn; function fromPoint(x, y) { return { left: x, top: y, right: x, bottom: y }; } exports.fromPoint = fromPoint; function addX(rect, x) { rect.left = Math.min(rect.left, x); rect.right = Math.max(rect.right, x); } exports.addX = addX; function addY(rect, y) { rect.top = Math.min(rect.top, y); rect.bottom = Math.max(rect.bottom, y); } exports.addY = addY; function addPoint(rect, x, y) { addX(rect, x); addY(rect, y); } exports.addPoint = addPoint; function addRect(rect, addon) { addX(rect, addon.left); addX(rect, addon.right); addY(rect, addon.top); addY(rect, addon.bottom); } exports.addRect = addRect; // In general, the angle between two vectors (ux, uy) and (vx, vy) can be computed as // +- arccos(dot(u, v) / (u.length * v.length), // where the +- sign is the sign of (ux * vy − uy * vx). function twoVectorsAngle(ux, uy, vx, vy) { var a2 = Math.atan2(uy, ux); var a1 = Math.atan2(vy, vx); var sign = a1 > a2 ? -1 : 1; var angle1 = a1 - a2; var angle2 = angle1 + sign * Math.PI * 2; return Math.abs(angle2) < Math.abs(angle1) ? angle2 : angle1; } exports.twoVectorsAngle = twoVectorsAngle; //# sourceMappingURL=math2d.js.map