UNPKG

@thi.ng/geom

Version:

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

74 lines 2.41 kB
import type { MultiFn2 } from "@thi.ng/defmulti"; import type { IShape } from "./api.js"; import { Group } from "./api/group.js"; /** * Function overrides for {@link splitArcLength}. */ export type SplitArcLengthFn = {} & MultiFn2<IShape, number, Group>; /** * Splits given shape into {@link Polyline} segments of given (max) arc length. * Returns a {@link Group} of shapes/polylines. * * @remarks * If the shape has a `__samples` attribute, it will be removed in the result to * avoid recursive application. * * Currently only implemented for: * * - {@link Group} * - {@link Polyline} * * Other shape types will be attempted to be auto-converted via * {@link asPolyline} first. Only shapes with a single boundary are supported. * * Nested groups are NOT supported. Groups are processing their child shapes and * forming new child groups of given max. arc lengths and potentially splitting * shapes if they don't fit within the current subgroup... * * @example * ```ts * import { circle, group, inscribedSquare, splitArcLength } from "@thi.ng/geom"; * * // circle (to be sampled as octagon) * const a = circle(100, { stroke: "red", __samples: 8 }); * * // inner square of circle * const b = inscribedSquare(a, { stroke: "blue" }); * * // process as group, split/partition into subgroups of arclength max. 200 * splitArcLength(group({}, [a, b]), 200); * ``` * * Result serialized to SVG: * * ```xml * <g> * <g> * <polyline fill="none" points="100,0 70.7,70.7 0.0,100 -43.4,82.0" stroke="red"/> * </g> * <g> * <polyline fill="none" points="-43.4,82.0 -70.7,70.7 -100,0.0 -70.7,-70.7 -54.7,-77.3" stroke="red"/> * </g> * <g> * <polyline fill="none" points="-54.7,-77.3 -0.0,-100 70.7,-70.7 95.3,-11.4" stroke="red"/> * </g> * <g> * <!-- last segment of circle --> * <polyline fill="none" points="95.3,-11.4 100,0" stroke="red"/> * <!-- first segment of rect --> * <polyline fill="none" points="-70.7,-70.7 70.7,-70.7 70.7,-24.4" stroke="blue"/> * </g> * <g> * <polyline fill="none" points="70.7,-24.4 70.7,70.7 -34.2,70.7" stroke="blue"/> * </g> * <g> * <polyline fill="none" points="-34.2,70.7 -70.7,70.7 -70.7,-70.7" stroke="blue"/> * </g> * </g> * ``` * * @param shape * @param dist */ export declare const splitArcLength: SplitArcLengthFn; //# sourceMappingURL=split-arclength.d.ts.map