mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
First implementation of element distance functions with failing tests
This commit is contained in:
parent
47cc842415
commit
d9ea7190ec
6 changed files with 275 additions and 173 deletions
|
@ -1,6 +1,8 @@
|
|||
import { invariant } from "../excalidraw/utils";
|
||||
import { cartesian2Polar, radians } from "./angle";
|
||||
import { ellipse, ellipseSegmentInterceptPoints } from "./ellipse";
|
||||
import { point } from "./point";
|
||||
import { point, pointDistance } from "./point";
|
||||
import { segment } from "./segment";
|
||||
import type { GenericPoint, Segment, Radians, Arc } from "./types";
|
||||
import { PRECISION } from "./utils";
|
||||
|
||||
|
@ -42,6 +44,25 @@ export function arcIncludesPoint<P extends GenericPoint>(
|
|||
: startAngle <= angle || endAngle >= angle;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param a
|
||||
* @param p
|
||||
*/
|
||||
export function arcDistanceFromPoint<Point extends GenericPoint>(
|
||||
a: Arc<Point>,
|
||||
p: Point,
|
||||
) {
|
||||
const intersectPoint = arcSegmentInterceptPoint(a, segment(p, a.center));
|
||||
|
||||
invariant(
|
||||
intersectPoint.length !== 1,
|
||||
"Arc distance intersector cannot have multiple intersections",
|
||||
);
|
||||
|
||||
return pointDistance(intersectPoint[0], p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the intersection point(s) of a line segment represented by a start
|
||||
* point and end point and a symmetric arc.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue