Clean up @excalidraw/math a bit

This commit is contained in:
Mark Tolmacs 2025-05-19 17:16:18 +02:00
parent 02b4fa1ca7
commit 83abf2cd94
No known key found for this signature in database
11 changed files with 22 additions and 13 deletions

View File

@ -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

View File

@ -1,3 +0,0 @@
/// <reference types="vite/client" />
import "@excalidraw/excalidraw/global";
import "@excalidraw/excalidraw/css";

View File

@ -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"
},

View File

@ -1,4 +1,4 @@
import { PRECISION } from "./utils";
import { PRECISION } from "./constants";
import type {
Degrees,

View File

@ -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 = [

View File

@ -4,7 +4,7 @@ import {
pointFromVector,
pointsEqual,
} from "./point";
import { PRECISION } from "./utils";
import { PRECISION } from "./constants";
import {
vector,
vectorAdd,

View File

@ -1,5 +1,5 @@
import { degreesToRadians } from "./angle";
import { PRECISION } from "./utils";
import { PRECISION } from "./constants";
import { vectorFromPoint, vectorScale } from "./vector";
import type {

View File

@ -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";

View File

@ -5,7 +5,7 @@ import {
pointFromVector,
pointRotateRads,
} from "./point";
import { PRECISION } from "./utils";
import { PRECISION } from "./constants";
import {
vectorAdd,
vectorCross,

View File

@ -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);

View File

@ -3,6 +3,6 @@
"compilerOptions": {
"outDir": "./dist/types"
},
"include": ["src/**/*", "global.d.ts"],
"include": ["src/**/*"],
"exclude": ["**/*.test.*", "tests", "types", "examples", "dist"]
}