svg-pathdata
Version:
Manipulate SVG path data (path[d] attribute content) simply and efficiently.
40 lines (39 loc) • 2.07 kB
TypeScript
import { type CommandA, type CommandC } from './types.js';
export type Point = [x: number, y: number];
export declare function rotate([x, y]: Point, rad: number): number[];
export declare function assertNumbers(...numbers: number[]): boolean;
/**
* https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes
* Fixes rX and rY.
* Ensures lArcFlag and sweepFlag are 0 or 1
* Adds center coordinates: command.cX, command.cY (relative or absolute, depending on command.relative)
* Adds start and end arc parameters (in degrees): command.phi1, command.phi2; phi1 < phi2 iff. c.sweepFlag == true
*/
export declare function annotateArcCommand(c: CommandA, x1: number, y1: number): void;
/**
* Solves a quadratic system of equations of the form
* a * x + b * y = c
* x² + y² = 1
* This can be understood as the intersection of the unit circle with a line.
* => y = (c - a x) / b
* => x² + (c - a x)² / b² = 1
* => x² b² + c² - 2 c a x + a² x² = b²
* => (a² + b²) x² - 2 a c x + (c² - b²) = 0
*/
export declare function intersectionUnitCircleLine(a: number, b: number, c: number): [number, number][];
export declare const DEG: number;
export declare function lerp(a: number, b: number, t: number): number;
export declare function arcAt(c: number, x1: number, x2: number, phiDeg: number): number;
export declare function bezierRoot(x0: number, x1: number, x2: number, x3: number): number[];
export declare function bezierAt(x0: number, x1: number, x2: number, x3: number, t: number): number;
export declare function a2c(arc: CommandA, x0: number, y0: number): CommandC[];
/**
* Determines if three points are collinear (lie on the same straight line)
* and the middle point is on the line segment between the first and third points
*
* @param p1 First point [x, y]
* @param p2 Middle point that might be removed
* @param p3 Last point [x, y]
* @returns true if the points are collinear and p2 is on the segment p1-p3
*/
export declare function arePointsCollinear(p1: Point, p2: Point, p3: Point): boolean;