mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
refactor: Update generic constraint Point to use GenericPoint
- Changed existing generic constraints that used LocalPoint | GlobalPoint as Point to now use the unified GenericPoint type.
This commit is contained in:
parent
71e55dba9f
commit
85cb973936
21 changed files with 153 additions and 211 deletions
|
@ -2,21 +2,17 @@ import { pointsEqual } from "./point";
|
|||
import { lineSegment, pointOnLineSegment } from "./segment";
|
||||
import { PRECISION } from "./utils";
|
||||
|
||||
import type { GlobalPoint, LocalPoint, Polygon } from "./types";
|
||||
import type { GenericPoint, Polygon } from "./types";
|
||||
|
||||
export function polygon<Point extends GlobalPoint | LocalPoint>(
|
||||
...points: Point[]
|
||||
) {
|
||||
export function polygon<Point extends GenericPoint>(...points: Point[]) {
|
||||
return polygonClose(points) as Polygon<Point>;
|
||||
}
|
||||
|
||||
export function polygonFromPoints<Point extends GlobalPoint | LocalPoint>(
|
||||
points: Point[],
|
||||
) {
|
||||
export function polygonFromPoints<Point extends GenericPoint>(points: Point[]) {
|
||||
return polygonClose(points) as Polygon<Point>;
|
||||
}
|
||||
|
||||
export const polygonIncludesPoint = <Point extends LocalPoint | GlobalPoint>(
|
||||
export const polygonIncludesPoint = <Point extends GenericPoint>(
|
||||
point: Point,
|
||||
polygon: Polygon<Point>,
|
||||
) => {
|
||||
|
@ -69,7 +65,7 @@ export const polygonIncludesPointNonZero = <Point extends [number, number]>(
|
|||
return windingNumber !== 0;
|
||||
};
|
||||
|
||||
export const pointOnPolygon = <Point extends LocalPoint | GlobalPoint>(
|
||||
export const pointOnPolygon = <Point extends GenericPoint>(
|
||||
p: Point,
|
||||
poly: Polygon<Point>,
|
||||
threshold = PRECISION,
|
||||
|
@ -86,16 +82,12 @@ export const pointOnPolygon = <Point extends LocalPoint | GlobalPoint>(
|
|||
return on;
|
||||
};
|
||||
|
||||
function polygonClose<Point extends LocalPoint | GlobalPoint>(
|
||||
polygon: Point[],
|
||||
) {
|
||||
function polygonClose<Point extends GenericPoint>(polygon: Point[]) {
|
||||
return polygonIsClosed(polygon)
|
||||
? polygon
|
||||
: ([...polygon, polygon[0]] as Polygon<Point>);
|
||||
}
|
||||
|
||||
function polygonIsClosed<Point extends LocalPoint | GlobalPoint>(
|
||||
polygon: Point[],
|
||||
) {
|
||||
function polygonIsClosed<Point extends GenericPoint>(polygon: Point[]) {
|
||||
return pointsEqual(polygon[0], polygon[polygon.length - 1]);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue