UNPKG

@technobuddha/library

Version:
21 lines (20 loc) 940 B
import { type Cartesian, type LineSegment } from './@types/geometry.ts'; /** * Calculates the intersection point of two line segments. * @param a - The first line segment. * @param b - The second line segment. * @param extend - If `true`, treats the segments as infinite lines; if `false`, only considers the actual segments. * @returns The intersection point as a `Point` object if the segments (or lines, if `extend` is `true`) intersect. * Returns `undefined` if the lines are parallel or coincident. * Returns `null` if the intersection is outside the segments and `extend` is `false`. * @example * ```typescript * lineIntersection( * { x0: 0, y0: 0, x1: 4, y1: 4 }, * { x0: 0, y0: 4, x1: 4, y1: 0 } * ); // { x: 2, y: 2 } * ``` * @group Geometry * @category Line Segment */ export declare function lineIntersection(a: LineSegment, b: LineSegment, extend?: boolean): Cartesian | null | undefined;