@visactor/vrender-core
Version:
```typescript import { xxx } from '@visactor/vrender-core'; ```
53 lines (51 loc) • 1.89 kB
JavaScript
import { halfPi, tau } from "@visactor/vutils";
const circleThreshold = tau - 1e-8;
export 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 %= tau) < 0 && (sa += tau), (ea %= tau) < 0 && (ea += tau),
ea < sa && (ccw = !ccw, s = sa, sa = ea, ea = s), ccw) for (ea -= tau, s = sa - sa % halfPi,
i = 0; i < 4 && s > ea; ++i, s -= halfPi) update(s); else for (s = sa - sa % halfPi + halfPi,
i = 0; i < 4 && s < ea; ++i, s += 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) {}
}
//# sourceMappingURL=bounds-context.js.map