From 83abf2cd949bff4bbbf7dda5ffeebf3b488bc56d Mon Sep 17 00:00:00 2001 From: Mark Tolmacs Date: Mon, 19 May 2025 17:16:18 +0200 Subject: [PATCH] Clean up @excalidraw/math a bit --- packages/math/README.md | 12 +++++++++++- packages/math/global.d.ts | 3 --- packages/math/package.json | 4 ++-- packages/math/src/angle.ts | 2 +- packages/math/src/constants.ts | 2 ++ packages/math/src/ellipse.ts | 2 +- packages/math/src/point.ts | 2 +- packages/math/src/polygon.ts | 2 +- packages/math/src/segment.ts | 2 +- packages/math/src/utils.ts | 2 +- packages/math/tsconfig.json | 2 +- 11 files changed, 22 insertions(+), 13 deletions(-) delete mode 100644 packages/math/global.d.ts diff --git a/packages/math/README.md b/packages/math/README.md index 348a9de07..84027cb3f 100644 --- a/packages/math/README.md +++ b/packages/math/README.md @@ -1,4 +1,14 @@ -# @excalidraw/math +# @excalidraw/math - 2D Vector Graphics Math Library +The package contains a collection of (mostly) independent functions providing +the mathematical basis for Excalidraw's rendering, hit detection, bounds +checking and anything using math underneath. + +The philosophy of the library is to be self-contained and therefore there is no +dependency on any other package. It only contains pure functions. It also +prefers analytical solutions vs numberical wherever possible. Since this +library is used in a high performance context, we might chose to use a numerical +approximation, even if an analytical solution is available to preserve +performance. ## Install diff --git a/packages/math/global.d.ts b/packages/math/global.d.ts deleted file mode 100644 index 16ade7a7d..000000000 --- a/packages/math/global.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import "@excalidraw/excalidraw/global"; -import "@excalidraw/excalidraw/css"; diff --git a/packages/math/package.json b/packages/math/package.json index 5fac47bef..65473cbbc 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -1,6 +1,6 @@ { "name": "@excalidraw/math", - "version": "0.1.0", + "version": "0.2.0", "type": "module", "types": "./dist/types/math/src/index.d.ts", "main": "./dist/prod/index.js", @@ -19,7 +19,7 @@ "files": [ "dist/*" ], - "description": "Excalidraw math functions", + "description": "Excalidraw math library for 2D vector graphics.", "publishConfig": { "access": "public" }, diff --git a/packages/math/src/angle.ts b/packages/math/src/angle.ts index 353dc5dad..49abd4625 100644 --- a/packages/math/src/angle.ts +++ b/packages/math/src/angle.ts @@ -1,4 +1,4 @@ -import { PRECISION } from "./utils"; +import { PRECISION } from "./constants"; import type { Degrees, diff --git a/packages/math/src/constants.ts b/packages/math/src/constants.ts index 6ba5eb8f7..ce39e4268 100644 --- a/packages/math/src/constants.ts +++ b/packages/math/src/constants.ts @@ -1,3 +1,5 @@ +export const PRECISION = 10e-5; + // Legendre-Gauss abscissae (x values) and weights for n=24 // Refeerence: https://pomax.github.io/bezierinfo/legendre-gauss.html export const LegendreGaussN24TValues = [ diff --git a/packages/math/src/ellipse.ts b/packages/math/src/ellipse.ts index 741a77df3..546b120bf 100644 --- a/packages/math/src/ellipse.ts +++ b/packages/math/src/ellipse.ts @@ -4,7 +4,7 @@ import { pointFromVector, pointsEqual, } from "./point"; -import { PRECISION } from "./utils"; +import { PRECISION } from "./constants"; import { vector, vectorAdd, diff --git a/packages/math/src/point.ts b/packages/math/src/point.ts index b6054a10a..3c1adf43d 100644 --- a/packages/math/src/point.ts +++ b/packages/math/src/point.ts @@ -1,5 +1,5 @@ import { degreesToRadians } from "./angle"; -import { PRECISION } from "./utils"; +import { PRECISION } from "./constants"; import { vectorFromPoint, vectorScale } from "./vector"; import type { diff --git a/packages/math/src/polygon.ts b/packages/math/src/polygon.ts index a50d4e853..91099caab 100644 --- a/packages/math/src/polygon.ts +++ b/packages/math/src/polygon.ts @@ -1,6 +1,6 @@ import { pointsEqual } from "./point"; import { lineSegment, pointOnLineSegment } from "./segment"; -import { PRECISION } from "./utils"; +import { PRECISION } from "./constants"; import type { GlobalPoint, LocalPoint, Polygon } from "./types"; diff --git a/packages/math/src/segment.ts b/packages/math/src/segment.ts index dade79039..767df7140 100644 --- a/packages/math/src/segment.ts +++ b/packages/math/src/segment.ts @@ -5,7 +5,7 @@ import { pointFromVector, pointRotateRads, } from "./point"; -import { PRECISION } from "./utils"; +import { PRECISION } from "./constants"; import { vectorAdd, vectorCross, diff --git a/packages/math/src/utils.ts b/packages/math/src/utils.ts index 8807c275e..0c52f7307 100644 --- a/packages/math/src/utils.ts +++ b/packages/math/src/utils.ts @@ -1,4 +1,4 @@ -export const PRECISION = 10e-5; +import { PRECISION } from "./constants"; export const clamp = (value: number, min: number, max: number) => { return Math.min(Math.max(value, min), max); diff --git a/packages/math/tsconfig.json b/packages/math/tsconfig.json index 6450145b1..31a443ae3 100644 --- a/packages/math/tsconfig.json +++ b/packages/math/tsconfig.json @@ -3,6 +3,6 @@ "compilerOptions": { "outDir": "./dist/types" }, - "include": ["src/**/*", "global.d.ts"], + "include": ["src/**/*"], "exclude": ["**/*.test.*", "tests", "types", "examples", "dist"] }