@bitbybit-dev/base
Version:
Bit By Bit Developers Base CAD Library to Program Geometry
166 lines (165 loc) • 7.12 kB
TypeScript
import { GeometryHelper } from "./geometry-helper";
import * as Inputs from "../inputs";
import { Point } from "./point";
import { Vector } from "./vector";
import { Line } from "./line";
/**
* Contains various methods for polyline. Polyline in bitbybit is a simple object that has points property containing an array of points.
* { points: number[][] }
*/
export declare class Polyline {
private readonly vector;
private readonly point;
private readonly line;
private readonly geometryHelper;
constructor(vector: Vector, point: Point, line: Line, geometryHelper: GeometryHelper);
/**
* Calculates total length of polyline by summing distances between consecutive points.
* Example: points=[[0,0,0], [3,0,0], [3,4,0]] → 3 + 4 = 7
* @param inputs a polyline
* @returns length
* @group get
* @shortname polyline length
* @drawable false
*/
length(inputs: Inputs.Polyline.PolylineDto): number;
/**
* Counts number of points in polyline.
* Example: polyline with points=[[0,0,0], [1,0,0], [1,1,0]] → 3
* @param inputs a polyline
* @returns nr of points
* @group get
* @shortname nr polyline points
* @drawable false
*/
countPoints(inputs: Inputs.Polyline.PolylineDto): number;
/**
* Extracts points array from polyline object.
* Example: polyline={points:[[0,0,0], [1,0,0]]} → [[0,0,0], [1,0,0]]
* @param inputs a polyline
* @returns points
* @group get
* @shortname points
* @drawable true
*/
getPoints(inputs: Inputs.Polyline.PolylineDto): Inputs.Base.Point3[];
/**
* Reverses point order of polyline (flips direction).
* Example: points=[[0,0,0], [1,0,0], [2,0,0]] → [[2,0,0], [1,0,0], [0,0,0]]
* @param inputs a polyline
* @returns reversed polyline
* @group convert
* @shortname reverse polyline
* @drawable true
*/
reverse(inputs: Inputs.Polyline.PolylineDto): Inputs.Polyline.PolylinePropertiesDto;
/**
* Applies transformation matrix to all points in polyline (rotates, scales, or translates).
* Example: polyline with 4 points, translation [5,0,0] → all points moved +5 in X direction
* @param inputs a polyline
* @returns transformed polyline
* @group transforms
* @shortname transform polyline
* @drawable true
*/
transformPolyline(inputs: Inputs.Polyline.TransformPolylineDto): Inputs.Polyline.PolylinePropertiesDto;
/**
* Creates a polyline from points array with optional isClosed flag.
* Example: points=[[0,0,0], [1,0,0], [1,1,0]], isClosed=true → {points:..., isClosed:true}
* @param inputs points and info if its closed
* @returns polyline
* @group create
* @shortname polyline
* @drawable true
*/
create(inputs: Inputs.Polyline.PolylineCreateDto): Inputs.Polyline.PolylinePropertiesDto;
/**
* Converts polyline to line segments (each segment as line object with start/end).
* Closed polylines include closing segment.
* Example: 3 points → 2 or 3 lines (depending on isClosed)
* @param inputs polyline
* @returns lines
* @group convert
* @shortname polyline to lines
* @drawable true
*/
polylineToLines(inputs: Inputs.Polyline.PolylineDto): Inputs.Base.Line3[];
/**
* Converts polyline to segment arrays (each segment as [point1, point2]).
* Closed polylines include closing segment if endpoints differ.
* Example: 4 points, closed → 4 segments connecting all points in a loop
* @param inputs polyline
* @returns segments
* @group convert
* @shortname polyline to segments
* @drawable false
*/
polylineToSegments(inputs: Inputs.Polyline.PolylineDto): Inputs.Base.Segment3[];
/**
* Finds points where polyline crosses itself (self-intersection points).
* Skips adjacent segments and deduplicates close points.
* Example: figure-8 shaped polyline → returns center crossing point
* @param inputs points of self intersection
* @returns polyline
* @group intersections
* @shortname polyline self intersections
* @drawable true
*/
polylineSelfIntersection(inputs: Inputs.Polyline.PolylineToleranceDto): Inputs.Base.Point3[];
/**
* Finds intersection points between two polylines (all segment-segment crossings).
* Tests all segment pairs and deduplicates close points.
* Example: crossing polylines forming an X → returns center intersection point
* @param inputs two polylines and tolerance
* @returns points
* @group intersection
* @shortname two polyline intersection
* @drawable true
*/
twoPolylineIntersection(inputs: Inputs.Polyline.TwoPolylinesToleranceDto): Inputs.Base.Point3[];
/**
* Sorts scrambled segments into connected polylines by matching endpoints.
* Uses spatial hashing for efficient connection finding.
* Example: 10 random segments that form 2 connected paths → 2 polylines
* @param inputs segments
* @returns polylines
* @group sort
* @shortname segments to polylines
* @drawable true
*/
sortSegmentsIntoPolylines(inputs: Inputs.Polyline.SegmentsToleranceDto): Inputs.Base.Polyline3[];
/**
* Calculates the maximum possible half-line fillet radius for each corner
* of a given polyline. For a closed polyline, it includes the corners
* connecting the last segment back to the first.
*
* The calculation uses the 'half-line' constraint, meaning the fillet's
* tangent points must lie within the first half of each segment connected
* to the corner.
*
* @param inputs Defines the polyline points, whether it's closed, and an optional tolerance.
* @returns An array containing the maximum fillet radius calculated for each corner.
* The order corresponds to corners P[1]...P[n-2] for open polylines,
* and P[1]...P[n-2], P[0], P[n-1] for closed polylines.
* Returns an empty array if the polyline has fewer than 3 points.
* @group fillet
* @shortname polyline max fillet radii
* @drawable false
*/
maxFilletsHalfLine(inputs: Inputs.Polyline.PolylineToleranceDto): number[];
/**
* Calculates the single safest maximum fillet radius that can be applied
* uniformly to all corners of a polyline, based on the 'half-line' constraint.
* This is determined by finding the minimum of the maximum possible fillet
* radii calculated for each individual corner.
*
* @param inputs Defines the polyline points, whether it's closed, and an optional tolerance.
* @returns The smallest value from the results of calculatePolylineMaxFillets.
* Returns 0 if the polyline has fewer than 3 points or if any
* calculated maximum radius is 0.
* @group fillet
* @shortname polyline safest fillet radius
* @drawable false
*/
safestFilletRadius(inputs: Inputs.Polyline.PolylineToleranceDto): number;
}