@bitbybit-dev/base
Version:
Bit By Bit Developers Base CAD Library to Program Geometry
177 lines (176 loc) • 6.84 kB
TypeScript
import { GeometryHelper } from "./geometry-helper";
import * as Inputs from "../inputs";
import { Point } from "./point";
import { Vector } from "./vector";
/**
* Contains various methods for lines and segments. Line in bitbybit is a simple object that has start and end point properties.
* { start: [ x, y, z ], end: [ x, y, z ] }
*/
export declare class Line {
private readonly vector;
private readonly point;
private readonly geometryHelper;
constructor(vector: Vector, point: Point, geometryHelper: GeometryHelper);
/**
* Extracts start point from a line.
* Example: line={start:[0,0,0], end:[10,5,0]} → [0,0,0]
* @param inputs a line
* @returns start point
* @group get
* @shortname line start point
* @drawable true
*/
getStartPoint(inputs: Inputs.Line.LineDto): Inputs.Base.Point3;
/**
* Extracts end point from a line.
* Example: line={start:[0,0,0], end:[10,5,0]} → [10,5,0]
* @param inputs a line
* @returns end point
* @group get
* @shortname line end point
* @drawable true
*/
getEndPoint(inputs: Inputs.Line.LineDto): Inputs.Base.Point3;
/**
* Calculates length (distance) of a line segment.
* Example: line={start:[0,0,0], end:[3,4,0]} → 5 (using Pythagorean theorem)
* @param inputs a line
* @returns line length
* @group get
* @shortname line length
* @drawable false
*/
length(inputs: Inputs.Line.LineDto): number;
/**
* Reverses line direction by swapping start and end points.
* Example: line={start:[0,0,0], end:[10,5,0]} → {start:[10,5,0], end:[0,0,0]}
* @param inputs a line
* @returns reversed line
* @group operations
* @shortname reversed line
* @drawable true
*/
reverse(inputs: Inputs.Line.LineDto): Inputs.Base.Line3;
/**
* Applies transformation matrix to line (rotates, scales, or translates both endpoints).
* Example: line={start:[0,0,0], end:[10,0,0]} with translation [5,5,0] → {start:[5,5,0], end:[15,5,0]}
* @param inputs a line
* @returns transformed line
* @group transforms
* @shortname transform line
* @drawable true
*/
transformLine(inputs: Inputs.Line.TransformLineDto): Inputs.Base.Line3;
/**
* Applies multiple transformations to multiple lines (one transform per line).
* Example: 3 lines with 3 different translation matrices → each line moved independently
* @param inputs lines
* @returns transformed lines
* @group transforms
* @shortname transform lines
* @drawable true
*/
transformsForLines(inputs: Inputs.Line.TransformsLinesDto): Inputs.Base.Line3[];
/**
* Creates a line from two points (line object with start and end properties).
* Example: start=[0,0,0], end=[10,5,0] → {start:[0,0,0], end:[10,5,0]}
* @param inputs start and end points of the line
* @returns line
* @group create
* @shortname line
* @drawable true
*/
create(inputs: Inputs.Line.LinePointsDto): Inputs.Base.Line3;
/**
* Creates a segment from two points (array format: [start, end]).
* Example: start=[0,0,0], end=[10,5,0] → [[0,0,0], [10,5,0]]
* @param inputs start and end points of the segment
* @returns segment
* @group create
* @shortname segment
* @drawable true
*/
createSegment(inputs: Inputs.Line.LinePointsDto): Inputs.Base.Segment3;
/**
* Calculates point at parameter t along line segment (0=start, 1=end, linear interpolation).
* Example: line={start:[0,0,0], end:[10,0,0]}, param=0.5 → [5,0,0] (midpoint)
* @param inputs line
* @returns point on line
* @group get
* @shortname point on line
* @drawable true
*/
getPointOnLine(inputs: Inputs.Line.PointOnLineDto): Inputs.Base.Point3;
/**
* Creates line segments connecting consecutive points in a list (forms a polyline path).
* Example: points=[[0,0,0], [5,0,0], [5,5,0]] → 2 lines: [0→5] and [5→5,5]
* @param inputs points
* @returns lines
* @group create
* @shortname lines between points
* @drawable true
*/
linesBetweenPoints(inputs: Inputs.Line.PointsLinesDto): Inputs.Base.Line3[];
/**
* Creates lines by pairing corresponding start and end points from two arrays.
* Filters out zero-length lines.
* Example: starts=[[0,0,0], [5,0,0]], ends=[[0,5,0], [5,5,0]] → 2 lines connecting paired points
* @param inputs start points and end points
* @returns lines
* @group create
* @shortname start and end points to lines
* @drawable true
*/
linesBetweenStartAndEndPoints(inputs: Inputs.Line.LineStartEndPointsDto): Inputs.Base.Line3[];
/**
* Converts line object to segment array format.
* Example: {start:[0,0,0], end:[10,5,0]} → [[0,0,0], [10,5,0]]
* @param inputs line
* @returns segment
* @group convert
* @shortname line to segment
* @drawable false
*/
lineToSegment(inputs: Inputs.Line.LineDto): Inputs.Base.Segment3;
/**
* Converts multiple line objects to segment array format (batch conversion).
* Example: 3 line objects → 3 segment arrays [[start1, end1], [start2, end2], ...]
* @param inputs lines
* @returns segments
* @group convert
* @shortname lines to segments
* @drawable false
*/
linesToSegments(inputs: Inputs.Line.LinesDto): Inputs.Base.Segment3[];
/**
* Converts segment array to line object format.
* Example: [[0,0,0], [10,5,0]] → {start:[0,0,0], end:[10,5,0]}
* @param inputs segment
* @returns line
* @group convert
* @shortname segment to line
* @drawable true
*/
segmentToLine(inputs: Inputs.Line.SegmentDto): Inputs.Base.Line3;
/**
* Converts multiple segment arrays to line object format (batch conversion).
* Example: 3 segment arrays → 3 line objects with start/end properties
* @param inputs segments
* @returns lines
* @group convert
* @shortname segments to lines
* @drawable true
*/
segmentsToLines(inputs: Inputs.Line.SegmentsDto): Inputs.Base.Line3[];
/**
* Calculates intersection point of two lines (or segments if checkSegmentsOnly=true).
* Returns undefined if lines are parallel, skew, or segments don't overlap.
* Example: line1={start:[0,0,0], end:[10,0,0]}, line2={start:[5,-5,0], end:[5,5,0]} → [5,0,0]
* @param inputs line1 and line2
* @returns intersection point or undefined if no intersection
* @group intersection
* @shortname line-line int
* @drawable true
*/
lineLineIntersection(inputs: Inputs.Line.LineLineIntersectionDto): Inputs.Base.Point3 | undefined;
}