@bitbybit-dev/base
Version:
Bit By Bit Developers Base CAD Library to Program Geometry
369 lines (368 loc) • 16.3 kB
TypeScript
import { GeometryHelper } from "./geometry-helper";
import * as Inputs from "../inputs";
import { Transforms } from "./transforms";
import { Vector } from "./vector";
import * as Models from "../models";
import { Lists } from "./lists";
/**
* Contains various methods for points. Point in bitbybit is simply an array containing 3 numbers for [x, y, z].
* Because of this form Point can be interchanged with Vector, which also is an array in [x, y, z] form.
* When creating 2D points, z coordinate is simply set to 0 - [x, y, 0].
*/
export declare class Point {
private readonly geometryHelper;
private readonly transforms;
private readonly vector;
private readonly lists;
constructor(geometryHelper: GeometryHelper, transforms: Transforms, vector: Vector, lists: Lists);
/**
* Applies transformation matrix to a single point (rotates, scales, or translates).
* Example: point=[0,0,0] with translation [5,5,0] → [5,5,0]
* @param inputs Contains a point and the transformations to apply
* @returns Transformed point
* @group transforms
* @shortname transform point
* @drawable true
*/
transformPoint(inputs: Inputs.Point.TransformPointDto): Inputs.Base.Point3;
/**
* Applies same transformation matrix to multiple points (batch transform).
* Example: 5 points with rotation 90° → all 5 points rotated together
* @param inputs Contains points and the transformations to apply
* @returns Transformed points
* @group transforms
* @shortname transform points
* @drawable true
*/
transformPoints(inputs: Inputs.Point.TransformPointsDto): Inputs.Base.Point3[];
/**
* Applies different transformation matrices to corresponding points (one transform per point).
* Arrays must have equal length.
* Example: 3 points with 3 different translations → each point moved independently
* @param inputs Contains points and the transformations to apply
* @returns Transformed points
* @group transforms
* @shortname transforms for points
* @drawable true
*/
transformsForPoints(inputs: Inputs.Point.TransformsForPointsDto): Inputs.Base.Point3[];
/**
* Moves multiple points by a translation vector (same offset for all points).
* Example: points=[[0,0,0], [1,0,0]], translation=[5,5,0] → [[5,5,0], [6,5,0]]
* @param inputs Contains points and the translation vector
* @returns Translated points
* @group transforms
* @shortname translate points
* @drawable true
*/
translatePoints(inputs: Inputs.Point.TranslatePointsDto): Inputs.Base.Point3[];
/**
* Moves multiple points by corresponding translation vectors (one vector per point).
* Arrays must have equal length.
* Example: 3 points with 3 different vectors → each point moved by its corresponding vector
* @param inputs Contains points and the translation vector
* @returns Translated points
* @group transforms
* @shortname translate points with vectors
* @drawable true
*/
translatePointsWithVectors(inputs: Inputs.Point.TranslatePointsWithVectorsDto): Inputs.Base.Point3[];
/**
* Moves multiple points by separate X, Y, Z values (convenience method for translation).
* Example: points=[[0,0,0]], x=10, y=5, z=0 → [[10,5,0]]
* @param inputs Contains points and the translation in x y and z
* @returns Translated points
* @group transforms
* @shortname translate xyz points
* @drawable true
*/
translateXYZPoints(inputs: Inputs.Point.TranslateXYZPointsDto): Inputs.Base.Point3[];
/**
* Scales multiple points around a center point with different factors per axis.
* Example: points=[[10,0,0]], center=[5,0,0], scaleXyz=[2,1,1] → [[15,0,0]] (doubles X distance from center)
* @param inputs Contains points, center point and scale factors
* @returns Scaled points
* @group transforms
* @shortname scale points on center
* @drawable true
*/
scalePointsCenterXYZ(inputs: Inputs.Point.ScalePointsCenterXYZDto): Inputs.Base.Point3[];
/**
* Stretches multiple points along a direction from a center point (directional scaling).
* Example: points=[[10,0,0]], center=[0,0,0], direction=[1,0,0], scale=2 → [[20,0,0]]
* @param inputs Contains points, center point, direction and scale factor
* @returns Stretched points
* @group transforms
* @shortname stretch points dir from center
* @drawable true
*/
stretchPointsDirFromCenter(inputs: Inputs.Point.StretchPointsDirFromCenterDto): Inputs.Base.Point3[];
/**
* Rotates multiple points around a center point along a custom axis.
* Example: points=[[10,0,0]], center=[0,0,0], axis=[0,1,0], angle=90° → [[0,0,-10]]
* @param inputs Contains points, axis, center point and angle of rotation
* @returns Rotated points
* @group transforms
* @shortname rotate points center axis
* @drawable true
*/
rotatePointsCenterAxis(inputs: Inputs.Point.RotatePointsCenterAxisDto): Inputs.Base.Point3[];
/**
* Calculates axis-aligned bounding box containing all points (min, max, center, width, height, length).
* Example: points=[[0,0,0], [10,5,3]] → {min:[0,0,0], max:[10,5,3], center:[5,2.5,1.5], width:10, height:5, length:3}
* @param inputs Points
* @returns Bounding box of points
* @group extract
* @shortname bounding box pts
* @drawable true
*/
boundingBoxOfPoints(inputs: Inputs.Point.PointsDto): Inputs.Base.BoundingBox;
/**
* Calculates distance to the nearest point in a collection.
* Example: point=[0,0,0], points=[[5,0,0], [10,0,0], [3,0,0]] → 3 (distance to [3,0,0])
* @param inputs Point from which to measure and points to measure the distance against
* @returns Distance to closest point
* @group extract
* @shortname distance to closest pt
* @drawable false
*/
closestPointFromPointsDistance(inputs: Inputs.Point.ClosestPointFromPointsDto): number;
/**
* Finds array index of the nearest point in a collection (1-based index, not 0-based).
* Example: point=[0,0,0], points=[[5,0,0], [10,0,0], [3,0,0]] → 3 (index of [3,0,0])
* @param inputs Point from which to find the index in a collection of points
* @returns Closest point index
* @group extract
* @shortname index of closest pt
* @drawable false
*/
closestPointFromPointsIndex(inputs: Inputs.Point.ClosestPointFromPointsDto): number;
/**
* Finds the nearest point in a collection to a reference point.
* Example: point=[0,0,0], points=[[5,0,0], [10,0,0], [3,0,0]] → [3,0,0]
* @param inputs Point and points collection to find the closest point in
* @returns Closest point
* @group extract
* @shortname closest pt
* @drawable true
*/
closestPointFromPoints(inputs: Inputs.Point.ClosestPointFromPointsDto): Inputs.Base.Point3;
/**
* Calculates Euclidean distance between two points.
* Example: start=[0,0,0], end=[3,4,0] → 5 (using Pythagorean theorem: √(3²+4²))
* @param inputs Coordinates of start and end points
* @returns Distance
* @group measure
* @shortname distance
* @drawable false
*/
distance(inputs: Inputs.Point.StartEndPointsDto): number;
/**
* Calculates distances from a start point to multiple end points.
* Example: start=[0,0,0], endPoints=[[3,0,0], [0,4,0], [5,0,0]] → [3, 4, 5]
* @param inputs Coordinates of start and end points
* @returns Distances
* @group measure
* @shortname distances to points
* @drawable false
*/
distancesToPoints(inputs: Inputs.Point.StartEndPointsListDto): number[];
/**
* Duplicates a point N times (creates array with N copies of the same point).
* Example: point=[5,5,0], amountOfPoints=3 → [[5,5,0], [5,5,0], [5,5,0]]
* @param inputs The point to be multiplied and the amount of points to create
* @returns Distance
* @group transforms
* @shortname multiply point
* @drawable true
*/
multiplyPoint(inputs: Inputs.Point.MultiplyPointDto): Inputs.Base.Point3[];
/**
* Extracts X coordinate from a point.
* Example: point=[5,10,3] → 5
* @param inputs The point
* @returns X coordinate
* @group get
* @shortname x coord
* @drawable false
*/
getX(inputs: Inputs.Point.PointDto): number;
/**
* Extracts Y coordinate from a point.
* Example: point=[5,10,3] → 10
* @param inputs The point
* @returns Y coordinate
* @group get
* @shortname y coord
* @drawable false
*/
getY(inputs: Inputs.Point.PointDto): number;
/**
* Extracts Z coordinate from a point.
* Example: point=[5,10,3] → 3
* @param inputs The point
* @returns Z coordinate
* @group get
* @shortname z coord
* @drawable false
*/
getZ(inputs: Inputs.Point.PointDto): number;
/**
* Calculates centroid (average position) of multiple points.
* Example: points=[[0,0,0], [10,0,0], [10,10,0]] → [6.67,3.33,0]
* @param inputs The points
* @returns point
* @group extract
* @shortname average point
* @drawable true
*/
averagePoint(inputs: Inputs.Point.PointsDto): Inputs.Base.Point3;
/**
* Creates a 3D point from X, Y, Z coordinates.
* Example: x=10, y=5, z=3 → [10,5,3]
* @param inputs xyz information
* @returns point 3d
* @group create
* @shortname point xyz
* @drawable true
*/
pointXYZ(inputs: Inputs.Point.PointXYZDto): Inputs.Base.Point3;
/**
* Creates a 2D point from X, Y coordinates.
* Example: x=10, y=5 → [10,5]
* @param inputs xy information
* @returns point 3d
* @group create
* @shortname point xy
* @drawable false
*/
pointXY(inputs: Inputs.Point.PointXYDto): Inputs.Base.Point2;
/**
* Creates logarithmic spiral points using golden angle or custom widening factor.
* Generates natural spiral patterns common in nature (sunflower, nautilus shell).
* Example: numberPoints=100, radius=10, phi=1.618 → 100 points forming outward spiral
* @param inputs Spiral information
* @returns Specified number of points in the array along the spiral
* @group create
* @shortname spiral
* @drawable true
*/
spiral(inputs: Inputs.Point.SpiralDto): Inputs.Base.Point3[];
/**
* Creates hexagonal grid center points on XY plane (honeycomb pattern).
* Grid size controlled by number of hexagons, not width/height.
* Example: radiusHexagon=1, nrHexagonsX=3, nrHexagonsY=3 → 9 hex centers in grid pattern
* @param inputs Information about hexagon and the grid
* @returns Points in the array on the grid
* @group create
* @shortname hex grid
* @drawable true
*/
hexGrid(inputs: Inputs.Point.HexGridCentersDto): Inputs.Base.Point3[];
/**
* Creates hexagonal grid scaled to fit within specified width/height bounds (auto-calculates hex size).
* Returns center points and hex vertices. Supports pointy-top or flat-top orientation.
* Example: width=10, height=10, nrHexagonsInHeight=3 → hex grid filling 10×10 area with 3 rows
* @param inputs Information about the desired grid dimensions and hexagon counts.
* @returns An object containing the array of center points and an array of hexagon vertex arrays.
* @group create
* @shortname scaled hex grid to fit
* @drawable false
*/
hexGridScaledToFit(inputs: Inputs.Point.HexGridScaledToFitDto): Models.Point.HexGridData;
/**
* Calculates the maximum possible fillet radius at a corner formed by two line segments
* sharing an endpoint (C), such that the fillet arc is tangent to both segments
* and lies entirely within them.
* @param inputs three points and the tolerance
* @returns the maximum fillet radius
* @group fillet
* @shortname max fillet radius
* @drawable false
*/
maxFilletRadius(inputs: Inputs.Point.ThreePointsToleranceDto): number;
/**
* Calculates the maximum possible fillet radius at a corner C, such that the fillet arc
* is tangent to both segments (P1-C, P2-C) and the tangent points lie within
* the first half of each segment (measured from C).
* @param inputs three points and the tolerance
* @returns the maximum fillet radius
* @group fillet
* @shortname max fillet radius half line
* @drawable false
*/
maxFilletRadiusHalfLine(inputs: Inputs.Point.ThreePointsToleranceDto): number;
/**
* Calculates the maximum possible fillet radius at each corner of a polyline formed by
* formed by a series of points. The fillet radius is calculated for each internal
* corner and optionally for the closing corners if the polyline is closed.
* @param inputs Points, checkLastWithFirst flag, and tolerance
* @returns Array of maximum fillet radii for each corner
* @group fillet
* @shortname max fillets half line
* @drawable false
*/
maxFilletsHalfLine(inputs: Inputs.Point.PointsMaxFilletsHalfLineDto): number[];
/**
* Calculates the single safest maximum fillet radius that can be applied
* uniformly to all corners of collection of points, 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 points, whether it's closed, and an optional tolerance.
* @returns The smallest value from the results of pointsMaxFilletsHalfLine.
* Returns 0 if the polyline has fewer than 3 points or if any
* calculated maximum radius is 0.
* @group fillet
* @shortname safest fillet radii points
* @drawable false
*/
safestPointsMaxFilletHalfLine(inputs: Inputs.Point.PointsMaxFilletsHalfLineDto): number;
/**
* Removes consecutive duplicate points from array within tolerance.
* Example: [[0,0,0], [0,0,0], [1,0,0], [1,0,0], [2,0,0]] → [[0,0,0], [1,0,0], [2,0,0]]
* @param inputs points, tolerance and check first and last
* @returns Points in the array without consecutive duplicates
* @group clean
* @shortname remove duplicates
* @drawable true
*/
removeConsecutiveDuplicates(inputs: Inputs.Point.RemoveConsecutiveDuplicatesDto): Inputs.Base.Point3[];
/**
* Calculates normal vector from three points using cross product (perpendicular to plane).
* Example: p1=[0,0,0], p2=[1,0,0], p3=[0,1,0] → [0,0,1] (pointing up from XY plane)
* @param inputs Three points and the reverse normal flag
* @returns Normal vector
* @group create
* @shortname normal from 3 points
* @drawable true
*/
normalFromThreePoints(inputs: Inputs.Point.ThreePointsNormalDto): Inputs.Base.Vector3;
private closestPointFromPointData;
/**
* Checks if two points are approximately equal within tolerance (distance-based comparison).
* Example: point1=[1.0000001, 2.0, 3.0], point2=[1.0, 2.0, 3.0], tolerance=1e-6 → true
* @param inputs Two points and the tolerance
* @returns true if the points are almost equal
* @group measure
* @shortname two points almost equal
* @drawable false
*/
twoPointsAlmostEqual(inputs: Inputs.Point.TwoPointsToleranceDto): boolean;
/**
* Sorts points lexicographically (by X, then Y, then Z coordinates).
* Example: [[5,0,0], [1,0,0], [3,0,0]] → [[1,0,0], [3,0,0], [5,0,0]]
* @param inputs points
* @returns sorted points
* @group sort
* @shortname sort points
* @drawable true
*/
sortPoints(inputs: Inputs.Point.PointsDto): Inputs.Base.Point3[];
/**
* Calculates the 6 vertices of a regular flat-top hexagon.
* @param center The center point [x, y, z].
* @param radius The radius (distance from center to vertex).
* @returns An array of 6 Point3 vertices in counter-clockwise order.
*/
private getRegularHexagonVertices;
}