UNPKG

@thi.ng/geom-arc

Version:

2D circular / elliptic arc operations

36 lines (35 loc) 906 B
import { HALF_PI } from "@thi.ng/math/api"; import { inRange } from "@thi.ng/math/interval"; import { roundTo } from "@thi.ng/math/prec"; import { MAX2, MIN2 } from "@thi.ng/vectors/api"; import { max2 } from "@thi.ng/vectors/max"; import { min2 } from "@thi.ng/vectors/min"; import { set2 } from "@thi.ng/vectors/set"; import { pointAtTheta } from "./point-at.js"; const bounds = (pos, r, axis, start, end) => { const min = set2([], MAX2); const max = set2([], MIN2); const p = []; const update = (theta) => { pointAtTheta(pos, r, axis, theta, p); min2(null, min, p); max2(null, max, p); }; update(start); update(end); if (start > end) { const t = start; start = end; end = t; } for (let i = roundTo(start, HALF_PI), j = roundTo(end, HALF_PI); i < j; i += HALF_PI) { inRange(i, start, end) && update(i); } return [min, max]; }; export { bounds };