UNPKG

@thi.ng/geom

Version:

Functional, polymorphic API for 2D geometry types & SVG generation

18 lines (17 loc) 567 B
import { liangBarsky2 } from "@thi.ng/geom-clip-line/liang-barsky"; import { Line } from "./api/line.js"; import { Rect } from "./api/rect.js"; import { __pclike } from "./internal/pclike.js"; function line(...args) { return __pclike(Line, args); } const clippedLine = (l, bounds) => { const res = bounds instanceof Rect ? liangBarsky2(l.points[0], l.points[1], bounds.pos, bounds.max()) : liangBarsky2(l.points[0], l.points[1], bounds[0], bounds[1]); if (res) { return new Line([res[0], res[1]], { ...l.attribs }); } }; export { clippedLine, line };