import type { MultiFn2 } from "@thi.ng/defmulti" ; import { defmulti } from "@thi.ng/defmulti/defmulti" ; import type { IShape } from "@thi.ng/geom-api" ; import { Sampler } from "@thi.ng/geom-resample/sampler" ; import { cubicSplitAt } from "@thi.ng/geom-splines/cubic-split" ; import { quadraticSplitAt } from "@thi.ng/geom-splines/quadratic-split" ; import { fit01 } from "@thi.ng/math/fit" ; import { set } from "@thi.ng/vectors/set" ; import { Arc } from "./api/arc.js" ; import { Cubic } from "./api/cubic.js" ; import { Line } from "./api/line.js" ; import { Polyline } from "./api/polyline.js" ; import { Quadratic } from "./api/quadratic.js" ; import { __copyAttribs } from "./internal/copy.js" ; import { __dispatch } from "./internal/dispatch.js" ; import { __pointArraysAsShapes } from "./internal/points-as-shape.js" ; import { __splitLine } from "./internal/split.js" ; export const splitAt = defmulti < any , number , IShape [ ] | undefined > ( __dispatch , { } , { arc : ( $ , t ) => { const theta = fit01 ( t , $ . start , $ . end ) ; return [ new Arc ( set ( [ ] , $ . pos ) , set ( [ ] , $ . r ) , $ . axis , $ . start , theta , $ . xl , $ . cw , __copyAttribs ( $ ) ) , new Arc ( set ( [ ] , $ . pos ) , set ( [ ] , $ . r ) , $ . axis , theta , $ . end , $ . xl , $ . cw , __copyAttribs ( $ ) ) , ] ; } , cubic : ( { attribs , points } , t ) => cubicSplitAt ( points [ 0 ] , points [ 1 ] , points [ 2 ] , points [ 3 ] , t ) . map ( ( pts ) => new Cubic ( pts , { ... attribs } ) ) , line : ( { attribs , points } , t ) => __splitLine ( points [ 0 ] , points [ 1 ] , t ) . map ( ( pts ) => new Line ( pts , { ... attribs } ) ) , polyline : ( $ , t ) => __pointArraysAsShapes ( Polyline , new Sampler ( $ . points ) . splitAt ( t ) , $ . attribs ) , quadratic : ( { attribs , points } , t ) => quadraticSplitAt ( points [ 0 ] , points [ 1 ] , points [ 2 ] , t ) . map ( ( pts ) => new Quadratic ( pts , { ... attribs } ) ) , } ) ;