UNPKG

@thi.ng/geom

Version:

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

93 lines 3.79 kB
import type { Always } from "@thi.ng/api"; import type { Vec } from "@thi.ng/vectors"; import type { Attribs, IPath, PCLike, PCLikeConstructor, PathConstructor, PathSegment, PathSegment2, PathSegment3 } from "./api.js"; import { Path } from "./api/path.js"; import { Path3 } from "./api/path3.js"; import { arcFrom2Points } from "./arc.js"; /** @internal */ type PathGeoConstructor<S extends PathSegment> = PCLikeConstructor<Always<S["geo"]> & PCLike>; /** @internal */ type PathBuilderTypes<P extends IPath<any>, S extends P["segments"][0]> = { path: PathConstructor<P, S>; a?: typeof arcFrom2Points; c: PathGeoConstructor<S>; l: PathGeoConstructor<S>; q: PathGeoConstructor<S>; }; export interface PathBuilderOpts { /** * If true (default), "move" commands will start a new path and * {@link PathBuilder} might produce multiple {@link Path}s. In general, * it's NOT recommended to disable this behavior since various path related * operations will not function properly anymore. However, there're some use * cases where auto-splitting is undesirable and this option primarily * exists for those. */ autoSplit: boolean; } /** * Generic 2D/3D path builder. Use {@link pathBuilder} or {@link pathBuilder3} * to instantiate. */ export declare class PathBuilder<P extends IPath<any>, S extends P["segments"][0]> { protected ctors: PathBuilderTypes<P, S>; attribs?: Attribs | undefined; opts: Partial<PathBuilderOpts>; /** * Array of all paths which have been built already (incl. the current) */ paths: P[]; protected curr: P; protected currP: Vec; protected bezierP: Vec; protected startP: Vec; constructor(ctors: PathBuilderTypes<P, S>, attribs?: Attribs | undefined, opts?: Partial<PathBuilderOpts>); [Symbol.iterator](): Generator<P, void, unknown>; /** * Returns the current path being constructed. */ current(): P; /** * Starts a new path and makes it the current one. Any future build commands * will only act on this new path. */ newPath(): void; moveTo(p: Vec, relative?: boolean): this; lineTo(p: Vec, relative?: boolean): this; hlineTo(x: number, relative?: boolean): this; vlineTo(y: number, relative?: boolean): this; cubicTo(cp1: Vec, cp2: Vec, p: Vec, relative?: boolean): this; quadraticTo(cp: Vec, p: Vec, relative?: boolean): this; cubicChainTo(cp2: Vec, p: Vec, relative?: boolean): this; quadraticChainTo(p: Vec, relative?: boolean): this; arcTo(p: Vec, r: Vec, xaxis: number, xl: boolean, clockwise: boolean, relative?: boolean): this; close(): this; protected updateCurrent(p: Vec, relative: boolean): Vec<number>; protected absPoint(p: Vec, relative: boolean): Vec<number>; protected addHVLine(p: number, i: number, relative: boolean): void; protected addCubic(cp1: Vec, cp2: Vec, p: Vec, relative: boolean): void; protected addQuadratic(cp: Vec, p: Vec, relative: boolean): void; } /** * Creates a new {@link PathBuilder} instance to construct a path step-by-step * via a fluent builder API to append various segments and/or sub-paths. * * @remarks * Also see {@link pathFromSvg} and {@link roundedRect}. * * @param attribs * @param opts */ export declare const pathBuilder: (attribs?: Attribs, opts?: Partial<PathBuilderOpts>) => PathBuilder<Path, PathSegment2>; /** * Like {@link pathBuilder}, but for constructing 3D paths ({@link Path3}). * * @remarks * Does **not** support arc segments, but all other segment types. * * @param attribs * @param opts */ export declare const pathBuilder3: (attribs?: Attribs, opts?: Partial<PathBuilderOpts>) => PathBuilder<Path3, PathSegment3>; export {}; //# sourceMappingURL=path-builder.d.ts.map