UNPKG

@foblex/2d

Version:

An Angular library for 2D geometric computations, providing classes and utilities for manipulating points, lines, vectors, rectangles, arcs, and transformations.

75 lines (74 loc) 3.35 kB
import { IPoint } from './point'; import { IRoundedRect } from './rounded-rect'; /** * The GetIntersections class is designed to find intersection points between * line segments and various geometric shapes. Currently, it supports rectangles, * circles, and ellipses. In the future, support for additional shapes will be added. */ export declare class GetIntersections { /** * Finds the guaranteed intersection points between a line segment and a rounded rectangle. * @param from - Starting point of the line segment. * @param to - Ending point of the line segment. * @param rect - The rect to check for intersections. * @returns An array of intersection points. */ static getRoundedRectIntersections(from: IPoint, to: IPoint, rect: IRoundedRect): IPoint[]; /** * Finds the intersection points between a line segment and an SVG path. * @param path - The SVG path to check for intersections. * @param rect - The rect to check for intersections. * @returns An array of intersection points. */ static getRoundedRectIntersectionsWithSVGPath(path: SVGPathElement, rect: IRoundedRect): IPoint[]; /** * Finds the intersection points between an arc and a line segment. * @param arc - The arc to check for intersections. * @param from - Starting point of the line segment. * @param to - Ending point of the line segment. * @returns An array of intersection points. */ private static intersectArcWithLine; /** * Finds the intersection point between two line segments. * @param p1 - Starting point of the first line segment. * @param p2 - Ending point of the first line segment. * @param p3 - Starting point of the second line segment. * @param p4 - Ending point of the second line segment. * @returns The intersection point or null if there is no intersection. */ private static intersectLineSegments; /** * Filters intersection points to retain only those within the given arc. * @param points - The points to filter. * @param arc - The arc to check against. * @returns An array of points within the arc. */ private static filterPointsWithinArc; /** * Normalizes an angle to be within the range 0 to 2π. * @param radians - The angle in radians. * @returns The normalized angle. */ private static normalizeAngle; /** * Finds the intersection points between an ellipse and a line segment. * @param center - Center of the ellipse. * @param radiusX - X radius of the ellipse. * @param radiusY - Y radius of the ellipse. * @param pointA - Starting point of the line segment. * @param pointB - Ending point of the line segment. * @returns An array of intersection points. */ private static findEllipseLineIntersections; /** * Calculates the intersection points based on the discriminant. * @param discriminant - The discriminant value. * @param a - Coefficient 'a' in the quadratic equation. * @param b - Coefficient 'b' in the quadratic equation. * @param pointA - Starting point of the line segment. * @param pointB - Ending point of the line segment. * @returns An array of intersection points. */ private static calculateIntersectionPoints; }