mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Replace intersection code
This commit is contained in:
parent
411deae176
commit
0c02972695
18 changed files with 507 additions and 687 deletions
|
@ -2,10 +2,11 @@ import { cartesian2Polar, normalizeRadians, radians } from "./angle";
|
|||
import {
|
||||
ellipse,
|
||||
ellipseDistanceFromPoint,
|
||||
ellipseLineIntersectionPoints,
|
||||
ellipseSegmentInterceptPoints,
|
||||
} from "./ellipse";
|
||||
import { point, pointDistance } from "./point";
|
||||
import type { GenericPoint, Segment, Radians, Arc } from "./types";
|
||||
import type { GenericPoint, Segment, Radians, Arc, Line } from "./types";
|
||||
import { PRECISION } from "./utils";
|
||||
|
||||
/**
|
||||
|
@ -85,7 +86,7 @@ export function arcDistanceFromPoint<Point extends GenericPoint>(
|
|||
|
||||
/**
|
||||
* Returns the intersection point(s) of a line segment represented by a start
|
||||
* point and end point and a symmetric arc.
|
||||
* point and end point and a symmetric arc
|
||||
*/
|
||||
export function arcSegmentInterceptPoints<Point extends GenericPoint>(
|
||||
a: Readonly<Arc<Point>>,
|
||||
|
@ -106,3 +107,31 @@ export function arcSegmentInterceptPoints<Point extends GenericPoint>(
|
|||
: a.startAngle <= candidateAngle || a.endAngle >= candidateAngle;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the intersection point(s) of a line segment represented by a start
|
||||
* point and end point and a symmetric arc
|
||||
*
|
||||
* @param a
|
||||
* @param l
|
||||
* @returns
|
||||
*/
|
||||
export function arcLineInterceptPoints<Point extends GenericPoint>(
|
||||
a: Readonly<Arc<Point>>,
|
||||
l: Readonly<Line<Point>>,
|
||||
): Point[] {
|
||||
return ellipseLineIntersectionPoints(
|
||||
ellipse(a.center, a.radius, a.radius),
|
||||
l,
|
||||
).filter((candidate) => {
|
||||
const [candidateRadius, candidateAngle] = cartesian2Polar(
|
||||
point(candidate[0] - a.center[0], candidate[1] - a.center[1]),
|
||||
);
|
||||
|
||||
return a.startAngle < a.endAngle
|
||||
? Math.abs(a.radius - candidateRadius) < PRECISION &&
|
||||
a.startAngle <= candidateAngle &&
|
||||
a.endAngle >= candidateAngle
|
||||
: a.startAngle <= candidateAngle || a.endAngle >= candidateAngle;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue