@technobuddha/library
Version:
A large library of useful functions
15 lines (13 loc) • 648 B
text/typescript
import { type LineSegment } from './@types/geometry.ts';
/**
* Returns a {@link LineSegment} where the point with the higher y-coordinate is always the starting point (x0, y0).
* If the original line's y1 is greater than y0, the line is returned as-is.
* Otherwise, the start and end points are swapped.
* @param line - The line segment to process.
* @returns A {@link LineSegment} with the topmost point as the starting point.
* @group Geometry
* @category Line Segment
*/
export function normalizeLineSegment(line: LineSegment): LineSegment {
return line.y1 > line.y0 ? line : { x0: line.x1, y0: line.y1, x1: line.x0, y1: line.y0 };
}