@thi.ng/geom
Version:
Functional, polymorphic API for 2D geometry types & SVG generation
29 lines (28 loc) • 1.11 kB
JavaScript
import { defmulti } from "@thi.ng/defmulti/defmulti";
import { Sampler } from "@thi.ng/geom-resample/sampler";
import { cubicTangentAt } from "@thi.ng/geom-splines/cubic-tangent";
import { quadraticTangentAt } from "@thi.ng/geom-splines/quadratic-tangent";
import { cossin } from "@thi.ng/math/angle";
import { HALF_PI, TAU } from "@thi.ng/math/api";
import { direction2 } from "@thi.ng/vectors/direction";
import { __dispatch } from "./internal/dispatch.js";
import { vertices } from "./vertices.js";
const tangentAt = defmulti(
__dispatch,
{
quad: "poly",
tri: "poly"
},
{
circle: (_, t) => cossin(TAU * t + HALF_PI),
cubic: ({ points }, t) => cubicTangentAt([], points[0], points[1], points[2], points[3], t),
line: ({ points }) => direction2([], points[0], points[1]),
poly: ($, t) => new Sampler($.points, true).tangentAt(t),
polyline: ($, t) => new Sampler($.points).tangentAt(t),
quadratic: ({ points }, t) => quadraticTangentAt([], points[0], points[1], points[2], t),
rect: ($, t) => new Sampler(vertices($), true).tangentAt(t)
}
);
export {
tangentAt
};