mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Add visual debug support for arc
This commit is contained in:
parent
85611b8754
commit
2ec3374333
3 changed files with 67 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
|||
import type { Segment } from "../math";
|
||||
import type { Arc, Segment } from "../math";
|
||||
import { isSegment, segment, pointFrom, type GlobalPoint } from "../math";
|
||||
import { isBounds } from "./element/typeChecks";
|
||||
import type { Bounds } from "./element/types";
|
||||
|
@ -15,10 +15,24 @@ declare global {
|
|||
|
||||
export type DebugElement = {
|
||||
color: string;
|
||||
data: Segment<GlobalPoint>;
|
||||
data: Segment<GlobalPoint> | Arc<GlobalPoint>;
|
||||
permanent: boolean;
|
||||
};
|
||||
|
||||
export const debugDrawArc = (
|
||||
a: Arc<GlobalPoint>,
|
||||
opts?: {
|
||||
color?: string;
|
||||
permanent?: boolean;
|
||||
},
|
||||
) => {
|
||||
addToCurrentFrame({
|
||||
color: opts?.color ?? "blue",
|
||||
permanent: !!opts?.permanent,
|
||||
data: a,
|
||||
});
|
||||
};
|
||||
|
||||
export const debugDrawLine = (
|
||||
segment: Segment<GlobalPoint> | Segment<GlobalPoint>[],
|
||||
opts?: {
|
||||
|
|
|
@ -5,7 +5,7 @@ import {
|
|||
ellipseLineIntersectionPoints,
|
||||
ellipseSegmentInterceptPoints,
|
||||
} from "./ellipse";
|
||||
import { pointFrom, pointDistance } from "./point";
|
||||
import { pointFrom, pointDistance, isPoint } from "./point";
|
||||
import type { GenericPoint, Segment, Radians, Arc, Line } from "./types";
|
||||
import { PRECISION } from "./utils";
|
||||
|
||||
|
@ -135,3 +135,18 @@ export function arcLineInterceptPoints<Point extends GenericPoint>(
|
|||
: a.startAngle <= candidateAngle || a.endAngle >= candidateAngle;
|
||||
});
|
||||
}
|
||||
|
||||
export function isArc<Point extends GenericPoint>(v: unknown): v is Arc<Point> {
|
||||
return (
|
||||
v != null &&
|
||||
typeof v === "object" &&
|
||||
Object.hasOwn(v, "center") &&
|
||||
Object.hasOwn(v, "radius") &&
|
||||
Object.hasOwn(v, "startAngle") &&
|
||||
Object.hasOwn(v, "endAngle") &&
|
||||
isPoint((v as Arc<Point>).center) &&
|
||||
typeof (v as Arc<Point>).radius === "number" &&
|
||||
typeof (v as Arc<Point>).startAngle === "number" &&
|
||||
typeof (v as Arc<Point>).endAngle === "number"
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue