UNPKG

@visactor/vrender-core

Version:
60 lines (56 loc) 2.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.BoundsContext = void 0; const vutils_1 = require("@visactor/vutils"), circleThreshold = vutils_1.tau - 1e-8; class BoundsContext { constructor(bounds) { this.init(bounds); } init(bounds) { this.bounds = bounds; } arc(cx, cy, r, sa, ea, ccw) { if (Math.abs(ea - sa) > circleThreshold) return this.bounds.add(cx - r, cy - r), void this.bounds.add(cx + r, cy + r); let s, i, x, y, xmin = 1 / 0, xmax = -1 / 0, ymin = 1 / 0, ymax = -1 / 0; function update(a) { x = r * Math.cos(a), y = r * Math.sin(a), x < xmin && (xmin = x), x > xmax && (xmax = x), y < ymin && (ymin = y), y > ymax && (ymax = y); } if (update(sa), update(ea), ea !== sa) if ((sa %= vutils_1.tau) < 0 && (sa += vutils_1.tau), (ea %= vutils_1.tau) < 0 && (ea += vutils_1.tau), ea < sa && (ccw = !ccw, s = sa, sa = ea, ea = s), ccw) for (ea -= vutils_1.tau, s = sa - sa % vutils_1.halfPi, i = 0; i < 4 && s > ea; ++i, s -= vutils_1.halfPi) update(s); else for (s = sa - sa % vutils_1.halfPi + vutils_1.halfPi, i = 0; i < 4 && s < ea; ++i, s += vutils_1.halfPi) update(s); this.bounds.add(cx + xmin, cy + ymin), this.bounds.add(cx + xmax, cy + ymax); } arcTo(x1, y1, x2, y2, radius) { this.bounds.add(x1, y1); } bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) { this.bounds.add(cp1x, cp1y), this.bounds.add(cp2x, cp2y), this.bounds.add(x, y); } closePath() {} ellipse() { throw new Error("不支持ellipse"); } lineTo(x, y) { this.bounds.add(x, y); } moveTo(x, y) { this.bounds.add(x, y); } quadraticCurveTo(cpx, cpy, x, y) { this.bounds.add(cpx, cpy), this.bounds.add(x, y); } rect(x, y, w, h) { this.bounds.add(x, y), this.bounds.add(x + w, y + h); } clear() { this.bounds.clear(); } release(...params) {} } exports.BoundsContext = BoundsContext; //# sourceMappingURL=bounds-context.js.map