mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Further math refactor and simplifications
This commit is contained in:
parent
41885b4bb3
commit
0e2f8c958e
18 changed files with 262 additions and 175 deletions
|
@ -1,22 +1,29 @@
|
|||
import { cartesian2Polar } from "./angle";
|
||||
import type {
|
||||
GlobalPoint,
|
||||
LocalPoint,
|
||||
SymmetricArc,
|
||||
ViewportPoint,
|
||||
} from "./types";
|
||||
import type { GenericPoint, Radians, SymmetricArc } from "./types";
|
||||
import { PRECISION } from "./utils";
|
||||
|
||||
/**
|
||||
* Constructs a symmetric arc defined by the originating circle radius
|
||||
* the start angle and end angle with 0 radians being the "northest" point
|
||||
* of the circle.
|
||||
*
|
||||
* @param radius The radius of the circle this arc lies on
|
||||
* @param startAngle The start angle with 0 radians being the "northest" point
|
||||
* @param endAngle The end angle with 0 radians being the "northest" point
|
||||
* @returns The constructed symmetric arc
|
||||
*/
|
||||
export function arc(radius: number, startAngle: Radians, endAngle: Radians) {
|
||||
return { radius, startAngle, endAngle } as SymmetricArc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a cartesian point lies on a symmetric arc, i.e. an arc which
|
||||
* is part of a circle contour centered on 0, 0.
|
||||
*/
|
||||
export const isPointOnSymmetricArc = <
|
||||
P extends GlobalPoint | LocalPoint | ViewportPoint,
|
||||
>(
|
||||
export function isPointOnSymmetricArc<P extends GenericPoint>(
|
||||
{ radius: arcRadius, startAngle, endAngle }: SymmetricArc,
|
||||
point: P,
|
||||
): boolean => {
|
||||
): boolean {
|
||||
const [radius, angle] = cartesian2Polar(point);
|
||||
|
||||
return startAngle < endAngle
|
||||
|
@ -24,4 +31,4 @@ export const isPointOnSymmetricArc = <
|
|||
startAngle <= angle &&
|
||||
endAngle >= angle
|
||||
: startAngle <= angle || endAngle >= angle;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue