mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
chore: Unify math types, utils and functions (#8389)
Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
This commit is contained in:
parent
e3d1dee9d0
commit
f4dd23fc31
98 changed files with 4291 additions and 3661 deletions
|
@ -1,7 +1,7 @@
|
|||
import { isLineSegment, lineSegment, point, type GlobalPoint } from "../math";
|
||||
import type { LineSegment } from "../utils";
|
||||
import type { BoundingBox, Bounds } from "./element/bounds";
|
||||
import { isBounds, isLineSegment } from "./element/typeChecks";
|
||||
import type { Point } from "./types";
|
||||
import { isBounds } from "./element/typeChecks";
|
||||
|
||||
// The global data holder to collect the debug operations
|
||||
declare global {
|
||||
|
@ -15,18 +15,22 @@ declare global {
|
|||
|
||||
export type DebugElement = {
|
||||
color: string;
|
||||
data: LineSegment;
|
||||
data: LineSegment<GlobalPoint>;
|
||||
permanent: boolean;
|
||||
};
|
||||
|
||||
export const debugDrawLine = (
|
||||
segment: LineSegment | LineSegment[],
|
||||
segment: LineSegment<GlobalPoint> | LineSegment<GlobalPoint>[],
|
||||
opts?: {
|
||||
color?: string;
|
||||
permanent?: boolean;
|
||||
},
|
||||
) => {
|
||||
(isLineSegment(segment) ? [segment] : segment).forEach((data) =>
|
||||
const segments = (
|
||||
isLineSegment(segment) ? [segment] : segment
|
||||
) as LineSegment<GlobalPoint>[];
|
||||
|
||||
segments.forEach((data) =>
|
||||
addToCurrentFrame({
|
||||
color: opts?.color ?? "red",
|
||||
data,
|
||||
|
@ -36,7 +40,7 @@ export const debugDrawLine = (
|
|||
};
|
||||
|
||||
export const debugDrawPoint = (
|
||||
point: Point,
|
||||
p: GlobalPoint,
|
||||
opts?: {
|
||||
color?: string;
|
||||
permanent?: boolean;
|
||||
|
@ -47,20 +51,20 @@ export const debugDrawPoint = (
|
|||
const yOffset = opts?.fuzzy ? Math.random() * 3 : 0;
|
||||
|
||||
debugDrawLine(
|
||||
[
|
||||
[point[0] + xOffset - 10, point[1] + yOffset - 10],
|
||||
[point[0] + xOffset + 10, point[1] + yOffset + 10],
|
||||
],
|
||||
lineSegment(
|
||||
point<GlobalPoint>(p[0] + xOffset - 10, p[1] + yOffset - 10),
|
||||
point<GlobalPoint>(p[0] + xOffset + 10, p[1] + yOffset + 10),
|
||||
),
|
||||
{
|
||||
color: opts?.color ?? "cyan",
|
||||
permanent: opts?.permanent,
|
||||
},
|
||||
);
|
||||
debugDrawLine(
|
||||
[
|
||||
[point[0] + xOffset - 10, point[1] + yOffset + 10],
|
||||
[point[0] + xOffset + 10, point[1] + yOffset - 10],
|
||||
],
|
||||
lineSegment(
|
||||
point<GlobalPoint>(p[0] + xOffset - 10, p[1] + yOffset + 10),
|
||||
point<GlobalPoint>(p[0] + xOffset + 10, p[1] + yOffset - 10),
|
||||
),
|
||||
{
|
||||
color: opts?.color ?? "cyan",
|
||||
permanent: opts?.permanent,
|
||||
|
@ -78,22 +82,22 @@ export const debugDrawBoundingBox = (
|
|||
(Array.isArray(box) ? box : [box]).forEach((bbox) =>
|
||||
debugDrawLine(
|
||||
[
|
||||
[
|
||||
[bbox.minX, bbox.minY],
|
||||
[bbox.maxX, bbox.minY],
|
||||
],
|
||||
[
|
||||
[bbox.maxX, bbox.minY],
|
||||
[bbox.maxX, bbox.maxY],
|
||||
],
|
||||
[
|
||||
[bbox.maxX, bbox.maxY],
|
||||
[bbox.minX, bbox.maxY],
|
||||
],
|
||||
[
|
||||
[bbox.minX, bbox.maxY],
|
||||
[bbox.minX, bbox.minY],
|
||||
],
|
||||
lineSegment(
|
||||
point<GlobalPoint>(bbox.minX, bbox.minY),
|
||||
point<GlobalPoint>(bbox.maxX, bbox.minY),
|
||||
),
|
||||
lineSegment(
|
||||
point<GlobalPoint>(bbox.maxX, bbox.minY),
|
||||
point<GlobalPoint>(bbox.maxX, bbox.maxY),
|
||||
),
|
||||
lineSegment(
|
||||
point<GlobalPoint>(bbox.maxX, bbox.maxY),
|
||||
point<GlobalPoint>(bbox.minX, bbox.maxY),
|
||||
),
|
||||
lineSegment(
|
||||
point<GlobalPoint>(bbox.minX, bbox.maxY),
|
||||
point<GlobalPoint>(bbox.minX, bbox.minY),
|
||||
),
|
||||
],
|
||||
{
|
||||
color: opts?.color ?? "cyan",
|
||||
|
@ -113,22 +117,22 @@ export const debugDrawBounds = (
|
|||
(isBounds(box) ? [box] : box).forEach((bbox) =>
|
||||
debugDrawLine(
|
||||
[
|
||||
[
|
||||
[bbox[0], bbox[1]],
|
||||
[bbox[2], bbox[1]],
|
||||
],
|
||||
[
|
||||
[bbox[2], bbox[1]],
|
||||
[bbox[2], bbox[3]],
|
||||
],
|
||||
[
|
||||
[bbox[2], bbox[3]],
|
||||
[bbox[0], bbox[3]],
|
||||
],
|
||||
[
|
||||
[bbox[0], bbox[3]],
|
||||
[bbox[0], bbox[1]],
|
||||
],
|
||||
lineSegment(
|
||||
point<GlobalPoint>(bbox[0], bbox[1]),
|
||||
point<GlobalPoint>(bbox[2], bbox[1]),
|
||||
),
|
||||
lineSegment(
|
||||
point<GlobalPoint>(bbox[2], bbox[1]),
|
||||
point<GlobalPoint>(bbox[2], bbox[3]),
|
||||
),
|
||||
lineSegment(
|
||||
point<GlobalPoint>(bbox[2], bbox[3]),
|
||||
point<GlobalPoint>(bbox[0], bbox[3]),
|
||||
),
|
||||
lineSegment(
|
||||
point<GlobalPoint>(bbox[0], bbox[3]),
|
||||
point<GlobalPoint>(bbox[0], bbox[1]),
|
||||
),
|
||||
],
|
||||
{
|
||||
color: opts?.color ?? "green",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue