UNPKG

@bitbybit-dev/base

Version:

Bit By Bit Developers Base CAD Library to Program Geometry

338 lines (337 loc) 13.3 kB
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); /** * Transforms the single point * @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; /** * Transforms multiple points * @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[]; /** * Transforms multiple points by multiple transformations * @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[]; /** * Translate multiple points * @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[]; /** * Translate multiple points * @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[]; /** * Translate multiple points by x, y, z values provided * @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[]; /** * Scale multiple points by providing center point and x, y, z scale factors * @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[]; /** * Stretch multiple points by providing center point, direction and uniform scale factor * @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[]; /** * Rotate multiple points by providing center point, axis and degrees of rotation * @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[]; /** * Gets a bounding box of the points * @param inputs Points * @returns Bounding box of points * @group extract * @shortname bounding box pts * @drawable true */ boundingBoxOfPoints(inputs: Inputs.Point.PointsDto): Inputs.Base.BoundingBox; /** * Measures the closest distance between a point and a collection of points * @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 the closest point index between a point and a collection of points. Caution, index is not 0 based, it starts with 1. * @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 closest point in a collection * @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; /** * Finds the distance between two points * @param inputs Coordinates of start and end points * @returns Distance * @group measure * @shortname distance * @drawable false */ distance(inputs: Inputs.Point.StartEndPointsDto): number; /** * Finds the distances between the start point and multiple end points * @param inputs Coordinates of start and end points * @returns Distances * @group measure * @shortname distances to points * @drawable false */ distancesToPoints(inputs: Inputs.Point.StartEndPointsListDto): number[]; /** * Multiply point by a specified amount * @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[]; /** * Get x coordinate of the point * @param inputs The point * @returns X coordinate * @group get * @shortname x coord * @drawable false */ getX(inputs: Inputs.Point.PointDto): number; /** * Get y coordinate of the point * @param inputs The point * @returns Y coordinate * @group get * @shortname y coord * @drawable false */ getY(inputs: Inputs.Point.PointDto): number; /** * Get z coordinate of the point * @param inputs The point * @returns Z coordinate * @group get * @shortname z coord * @drawable false */ getZ(inputs: Inputs.Point.PointDto): number; /** * Get average point of points * @param inputs The points * @returns point * @group extract * @shortname average point * @drawable true */ averagePoint(inputs: Inputs.Point.PointsDto): Inputs.Base.Point3; /** * Creates the xyz point * @param inputs xyz information * @returns point 3d * @group create * @shortname point xyz * @drawable true */ pointXYZ(inputs: Inputs.Point.PointXYZDto): Inputs.Base.Point3; /** * Creates the xy point * @param inputs xy information * @returns point 3d * @group create * @shortname point xy * @drawable false */ pointXY(inputs: Inputs.Point.PointXYDto): Inputs.Base.Point2; /** * Creates the spiral out of multiple points * @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 a flat point grid on XY plane. This grid contains center points for hexagons of the given radius. * Be aware that we control only the nr of hexagons to be made and not the length and width of the grid. * @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 a pointy-top or flat-top hexagon grid, scaling hexagons to fit specified dimensions exactly. * Returns both center points and the vertices of each (potentially scaled) hexagon. * Hexagons are ordered column-first, then row-first. * @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 duplicates from the point array with tolerance * @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[]; /** * Creates a normal vector from 3 points * @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 almost equal * @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 (X, then Y, then Z) * @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; }