@excalidraw/math 0.18.0-c65b684e9 → 0.18.0-d1f3982
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dev/index.js +58 -61
- package/dist/dev/index.js.map +3 -3
- package/dist/prod/index.js +1 -1
- package/dist/types/common/src/constants.d.ts +18 -15
- package/dist/types/common/src/editorInterface.d.ts +34 -0
- package/dist/types/common/src/index.d.ts +1 -0
- package/dist/types/common/src/utils.d.ts +2 -1
- package/dist/types/element/src/Scene.d.ts +6 -2
- package/dist/types/element/src/bounds.d.ts +1 -1
- package/dist/types/element/src/delta.d.ts +6 -4
- package/dist/types/element/src/index.d.ts +1 -0
- package/dist/types/element/src/positionElementsOnGrid.d.ts +2 -0
- package/dist/types/element/src/renderElement.d.ts +4 -1
- package/dist/types/element/src/resizeTest.d.ts +5 -4
- package/dist/types/element/src/store.d.ts +6 -1
- package/dist/types/element/src/textElement.d.ts +1 -1
- package/dist/types/element/src/transformHandles.d.ts +5 -4
- package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +21 -9
- package/dist/types/excalidraw/actions/actionBoundText.d.ts +14 -6
- package/dist/types/excalidraw/actions/actionCanvas.d.ts +94 -54
- package/dist/types/excalidraw/actions/actionClipboard.d.ts +42 -18
- package/dist/types/excalidraw/actions/actionCropEditor.d.ts +7 -3
- package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +22 -10
- package/dist/types/excalidraw/actions/actionDuplicateSelection.d.ts +1 -1
- package/dist/types/excalidraw/actions/actionElementLink.d.ts +7 -3
- package/dist/types/excalidraw/actions/actionElementLock.d.ts +14 -6
- package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +7 -3
- package/dist/types/excalidraw/actions/actionExport.d.ts +63 -27
- package/dist/types/excalidraw/actions/actionFinalize.d.ts +14 -6
- package/dist/types/excalidraw/actions/actionFrame.d.ts +28 -12
- package/dist/types/excalidraw/actions/actionGroup.d.ts +14 -6
- package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +8 -4
- package/dist/types/excalidraw/actions/actionLink.d.ts +5 -1
- package/dist/types/excalidraw/actions/actionMenu.d.ts +7 -369
- package/dist/types/excalidraw/actions/actionNavigate.d.ts +14 -6
- package/dist/types/excalidraw/actions/actionProperties.d.ts +122 -53
- package/dist/types/excalidraw/actions/actionSelectAll.d.ts +7 -3
- package/dist/types/excalidraw/actions/actionStyles.d.ts +7 -3
- package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +7 -3
- package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +7 -3
- package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +7 -3
- package/dist/types/excalidraw/actions/actionToggleStats.d.ts +7 -3
- package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +7 -3
- package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +7 -3
- package/dist/types/excalidraw/actions/index.d.ts +2 -2
- package/dist/types/excalidraw/actions/types.d.ts +1 -1
- package/dist/types/excalidraw/appState.d.ts +5 -1
- package/dist/types/excalidraw/clipboard.d.ts +64 -1
- package/dist/types/excalidraw/components/Actions.d.ts +17 -3
- package/dist/types/excalidraw/components/App.d.ts +28 -23
- package/dist/types/excalidraw/components/ColorPicker/Picker.d.ts +2 -0
- package/dist/types/excalidraw/components/ColorPicker/PickerColorList.d.ts +2 -1
- package/dist/types/excalidraw/components/ColorPicker/ShadeList.d.ts +2 -1
- package/dist/types/excalidraw/components/CommandPalette/CommandPalette.d.ts +1 -0
- package/dist/types/excalidraw/components/ExcalidrawLogo.d.ts +1 -1
- package/dist/types/excalidraw/components/FontPicker/FontPicker.d.ts +2 -1
- package/dist/types/excalidraw/components/FontPicker/FontPickerTrigger.d.ts +3 -1
- package/dist/types/excalidraw/components/HintViewer.d.ts +4 -3
- package/dist/types/excalidraw/components/InlineIcon.d.ts +3 -1
- package/dist/types/excalidraw/components/LayerUI.d.ts +2 -1
- package/dist/types/excalidraw/components/LibraryMenuSection.d.ts +1 -1
- package/dist/types/excalidraw/components/MobileMenu.d.ts +3 -5
- package/dist/types/excalidraw/components/MobileToolBar.d.ts +11 -0
- package/dist/types/excalidraw/components/Popover.d.ts +2 -1
- package/dist/types/excalidraw/components/PropertiesPopover.d.ts +1 -0
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogTrigger.d.ts +1 -2
- package/dist/types/excalidraw/components/TextField.d.ts +1 -0
- package/dist/types/excalidraw/components/ToolPopover.d.ts +25 -0
- package/dist/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +3 -2
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenu.d.ts +4 -2
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuContent.d.ts +2 -1
- package/dist/types/excalidraw/components/icons.d.ts +5 -0
- package/dist/types/excalidraw/components/live-collaboration/LiveCollaborationTrigger.d.ts +13 -1
- package/dist/types/excalidraw/components/main-menu/MainMenu.d.ts +0 -3
- package/dist/types/excalidraw/components/shapes.d.ts +129 -1
- package/dist/types/excalidraw/data/blob.d.ts +3 -7
- package/dist/types/excalidraw/data/reconcile.d.ts +1 -0
- package/dist/types/excalidraw/data/restore.d.ts +6 -1
- package/dist/types/excalidraw/data/types.d.ts +4 -1
- package/dist/types/excalidraw/hooks/useLibraryItemSvg.d.ts +1 -1
- package/dist/types/excalidraw/hooks/useTextEditorFocus.d.ts +14 -0
- package/dist/types/excalidraw/index.d.ts +3 -4
- package/dist/types/excalidraw/renderer/interactiveScene.d.ts +1 -1
- package/dist/types/excalidraw/scene/types.d.ts +3 -3
- package/dist/types/excalidraw/shortcut.d.ts +1 -0
- package/dist/types/excalidraw/types.d.ts +23 -17
- package/dist/types/math/src/segment.d.ts +1 -0
- package/package.json +2 -2
package/dist/dev/index.js
CHANGED
|
@@ -206,41 +206,41 @@ var LegendreGaussN24CValues = [
|
|
|
206
206
|
function curve(a, b, c, d) {
|
|
207
207
|
return [a, b, c, d];
|
|
208
208
|
}
|
|
209
|
-
function
|
|
210
|
-
return [
|
|
211
|
-
(f(t0 + delta, s0) - f(t0 - delta, s0)) / (2 * delta),
|
|
212
|
-
(f(t0, s0 + delta) - f(t0, s0 - delta)) / (2 * delta)
|
|
213
|
-
];
|
|
214
|
-
}
|
|
215
|
-
function solve(f, t0, s0, tolerance = 1e-3, iterLimit = 10) {
|
|
209
|
+
function solveWithAnalyticalJacobian(curve2, lineSegment2, t0, s0, tolerance = 1e-3, iterLimit = 10) {
|
|
216
210
|
let error = Infinity;
|
|
217
211
|
let iter = 0;
|
|
218
212
|
while (error >= tolerance) {
|
|
219
213
|
if (iter >= iterLimit) {
|
|
220
214
|
return null;
|
|
221
215
|
}
|
|
222
|
-
const
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
-
const
|
|
229
|
-
|
|
216
|
+
const bt = 1 - t0;
|
|
217
|
+
const bt2 = bt * bt;
|
|
218
|
+
const bt3 = bt2 * bt;
|
|
219
|
+
const t0_2 = t0 * t0;
|
|
220
|
+
const t0_3 = t0_2 * t0;
|
|
221
|
+
const bezierX = bt3 * curve2[0][0] + 3 * bt2 * t0 * curve2[1][0] + 3 * bt * t0_2 * curve2[2][0] + t0_3 * curve2[3][0];
|
|
222
|
+
const bezierY = bt3 * curve2[0][1] + 3 * bt2 * t0 * curve2[1][1] + 3 * bt * t0_2 * curve2[2][1] + t0_3 * curve2[3][1];
|
|
223
|
+
const lineX = lineSegment2[0][0] + s0 * (lineSegment2[1][0] - lineSegment2[0][0]);
|
|
224
|
+
const lineY = lineSegment2[0][1] + s0 * (lineSegment2[1][1] - lineSegment2[0][1]);
|
|
225
|
+
const fx = bezierX - lineX;
|
|
226
|
+
const fy = bezierY - lineY;
|
|
227
|
+
error = Math.abs(fx) + Math.abs(fy);
|
|
228
|
+
if (error < tolerance) {
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
const dfx_dt = -3 * bt2 * curve2[0][0] + 3 * bt2 * curve2[1][0] - 6 * bt * t0 * curve2[1][0] - 3 * t0_2 * curve2[2][0] + 6 * bt * t0 * curve2[2][0] + 3 * t0_2 * curve2[3][0];
|
|
232
|
+
const dfy_dt = -3 * bt2 * curve2[0][1] + 3 * bt2 * curve2[1][1] - 6 * bt * t0 * curve2[1][1] - 3 * t0_2 * curve2[2][1] + 6 * bt * t0 * curve2[2][1] + 3 * t0_2 * curve2[3][1];
|
|
233
|
+
const dfx_ds = -(lineSegment2[1][0] - lineSegment2[0][0]);
|
|
234
|
+
const dfy_ds = -(lineSegment2[1][1] - lineSegment2[0][1]);
|
|
235
|
+
const det = dfx_dt * dfy_ds - dfx_ds * dfy_dt;
|
|
236
|
+
if (Math.abs(det) < 1e-12) {
|
|
230
237
|
return null;
|
|
231
238
|
}
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
[iJ[0][0] * b[0][0] + iJ[0][1] * b[1][0]],
|
|
238
|
-
[iJ[1][0] * b[0][0] + iJ[1][1] * b[1][0]]
|
|
239
|
-
];
|
|
240
|
-
t0 = t0 + h[0][0];
|
|
241
|
-
s0 = s0 + h[1][0];
|
|
242
|
-
const [tErr, sErr] = f(t0, s0);
|
|
243
|
-
error = Math.max(Math.abs(tErr), Math.abs(sErr));
|
|
239
|
+
const invDet = 1 / det;
|
|
240
|
+
const dt = invDet * (dfy_ds * -fx - dfx_ds * -fy);
|
|
241
|
+
const ds = invDet * (-dfy_dt * -fx + dfx_dt * -fy);
|
|
242
|
+
t0 += dt;
|
|
243
|
+
s0 += ds;
|
|
244
244
|
iter += 1;
|
|
245
245
|
}
|
|
246
246
|
return [t0, s0];
|
|
@@ -249,47 +249,32 @@ var bezierEquation = (c, t) => pointFrom(
|
|
|
249
249
|
(1 - t) ** 3 * c[0][0] + 3 * (1 - t) ** 2 * t * c[1][0] + 3 * (1 - t) * t ** 2 * c[2][0] + t ** 3 * c[3][0],
|
|
250
250
|
(1 - t) ** 3 * c[0][1] + 3 * (1 - t) ** 2 * t * c[1][1] + 3 * (1 - t) * t ** 2 * c[2][1] + t ** 3 * c[3][1]
|
|
251
251
|
);
|
|
252
|
+
var initial_guesses = [
|
|
253
|
+
[0.5, 0],
|
|
254
|
+
[0.2, 0],
|
|
255
|
+
[0.8, 0]
|
|
256
|
+
];
|
|
257
|
+
var calculate = ([t0, s0], l, c) => {
|
|
258
|
+
const solution = solveWithAnalyticalJacobian(c, l, t0, s0, 0.01, 3);
|
|
259
|
+
if (!solution) {
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
const [t, s] = solution;
|
|
263
|
+
if (t < 0 || t > 1 || s < 0 || s > 1) {
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
return bezierEquation(c, t);
|
|
267
|
+
};
|
|
252
268
|
function curveIntersectLineSegment(c, l) {
|
|
253
|
-
|
|
254
|
-
l[0][0] + s * (l[1][0] - l[0][0]),
|
|
255
|
-
l[0][1] + s * (l[1][1] - l[0][1])
|
|
256
|
-
);
|
|
257
|
-
const initial_guesses = [
|
|
258
|
-
[0.5, 0],
|
|
259
|
-
[0.2, 0],
|
|
260
|
-
[0.8, 0]
|
|
261
|
-
];
|
|
262
|
-
const calculate = ([t0, s0]) => {
|
|
263
|
-
const solution2 = solve(
|
|
264
|
-
(t2, s2) => {
|
|
265
|
-
const bezier_point = bezierEquation(c, t2);
|
|
266
|
-
const line_point = line2(s2);
|
|
267
|
-
return [
|
|
268
|
-
bezier_point[0] - line_point[0],
|
|
269
|
-
bezier_point[1] - line_point[1]
|
|
270
|
-
];
|
|
271
|
-
},
|
|
272
|
-
t0,
|
|
273
|
-
s0
|
|
274
|
-
);
|
|
275
|
-
if (!solution2) {
|
|
276
|
-
return null;
|
|
277
|
-
}
|
|
278
|
-
const [t, s] = solution2;
|
|
279
|
-
if (t < 0 || t > 1 || s < 0 || s > 1) {
|
|
280
|
-
return null;
|
|
281
|
-
}
|
|
282
|
-
return bezierEquation(c, t);
|
|
283
|
-
};
|
|
284
|
-
let solution = calculate(initial_guesses[0]);
|
|
269
|
+
let solution = calculate(initial_guesses[0], l, c);
|
|
285
270
|
if (solution) {
|
|
286
271
|
return [solution];
|
|
287
272
|
}
|
|
288
|
-
solution = calculate(initial_guesses[1]);
|
|
273
|
+
solution = calculate(initial_guesses[1], l, c);
|
|
289
274
|
if (solution) {
|
|
290
275
|
return [solution];
|
|
291
276
|
}
|
|
292
|
-
solution = calculate(initial_guesses[2]);
|
|
277
|
+
solution = calculate(initial_guesses[2], l, c);
|
|
293
278
|
if (solution) {
|
|
294
279
|
return [solution];
|
|
295
280
|
}
|
|
@@ -697,6 +682,17 @@ function lineSegmentIntersectionPoints(l, s, threshold) {
|
|
|
697
682
|
}
|
|
698
683
|
return candidate;
|
|
699
684
|
}
|
|
685
|
+
function lineSegmentsDistance(s1, s2) {
|
|
686
|
+
if (lineSegmentIntersectionPoints(s1, s2)) {
|
|
687
|
+
return 0;
|
|
688
|
+
}
|
|
689
|
+
return Math.min(
|
|
690
|
+
distanceToLineSegment(s1[0], s2),
|
|
691
|
+
distanceToLineSegment(s1[1], s2),
|
|
692
|
+
distanceToLineSegment(s2[0], s1),
|
|
693
|
+
distanceToLineSegment(s2[1], s1)
|
|
694
|
+
);
|
|
695
|
+
}
|
|
700
696
|
|
|
701
697
|
// src/polygon.ts
|
|
702
698
|
function polygon(...points) {
|
|
@@ -855,6 +851,7 @@ export {
|
|
|
855
851
|
lineSegment,
|
|
856
852
|
lineSegmentIntersectionPoints,
|
|
857
853
|
lineSegmentRotate,
|
|
854
|
+
lineSegmentsDistance,
|
|
858
855
|
linesIntersectAt,
|
|
859
856
|
normalizeRadians,
|
|
860
857
|
offsetPointsForQuadraticBezier,
|
package/dist/dev/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils.ts", "../../src/angle.ts", "../../src/vector.ts", "../../src/point.ts", "../../src/constants.ts", "../../src/curve.ts", "../../src/ellipse.ts", "../../src/line.ts", "../../src/segment.ts", "../../src/polygon.ts", "../../src/range.ts", "../../src/rectangle.ts", "../../src/triangle.ts"],
|
|
4
|
-
"sourcesContent": ["export const PRECISION = 10e-5;\n\nexport const clamp = (value: number, min: number, max: number) => {\n return Math.min(Math.max(value, min), max);\n};\n\nexport const round = (\n value: number,\n precision: number,\n func: \"round\" | \"floor\" | \"ceil\" = \"round\",\n) => {\n const multiplier = Math.pow(10, precision);\n\n return Math[func]((value + Number.EPSILON) * multiplier) / multiplier;\n};\n\nexport const roundToStep = (\n value: number,\n step: number,\n func: \"round\" | \"floor\" | \"ceil\" = \"round\",\n): number => {\n const factor = 1 / step;\n return Math[func](value * factor) / factor;\n};\n\nexport const average = (a: number, b: number) => (a + b) / 2;\n\nexport const isFiniteNumber = (value: any): value is number => {\n return typeof value === \"number\" && Number.isFinite(value);\n};\n\nexport const isCloseTo = (a: number, b: number, precision = PRECISION) =>\n Math.abs(a - b) < precision;\n", "import { PRECISION } from \"./utils\";\n\nimport type {\n Degrees,\n GlobalPoint,\n LocalPoint,\n PolarCoords,\n Radians,\n} from \"./types\";\n\nexport const normalizeRadians = (angle: Radians): Radians =>\n angle < 0\n ? (((angle % (2 * Math.PI)) + 2 * Math.PI) as Radians)\n : ((angle % (2 * Math.PI)) as Radians);\n\n/**\n * Return the polar coordinates for the given cartesian point represented by\n * (x, y) for the center point 0,0 where the first number returned is the radius,\n * the second is the angle in radians.\n */\nexport const cartesian2Polar = <P extends GlobalPoint | LocalPoint>([\n x,\n y,\n]: P): PolarCoords => [\n Math.hypot(x, y),\n normalizeRadians(Math.atan2(y, x) as Radians),\n];\n\nexport function degreesToRadians(degrees: Degrees): Radians {\n return ((degrees * Math.PI) / 180) as Radians;\n}\n\nexport function radiansToDegrees(degrees: Radians): Degrees {\n return ((degrees * 180) / Math.PI) as Degrees;\n}\n\n/**\n * Determines if the provided angle is a right angle.\n *\n * @param rads The angle to measure\n * @returns TRUE if the provided angle is a right angle\n */\nexport function isRightAngleRads(rads: Radians): boolean {\n return Math.abs(Math.sin(2 * rads)) < PRECISION;\n}\n\nexport function radiansBetweenAngles(\n a: Radians,\n min: Radians,\n max: Radians,\n): boolean {\n a = normalizeRadians(a);\n min = normalizeRadians(min);\n max = normalizeRadians(max);\n\n if (min < max) {\n return a >= min && a <= max;\n }\n\n // The range wraps around the 0 angle\n return a >= min || a <= max;\n}\n\nexport function radiansDifference(a: Radians, b: Radians): Radians {\n a = normalizeRadians(a);\n b = normalizeRadians(b);\n\n let diff = a - b;\n\n if (diff < -Math.PI) {\n diff = (diff + 2 * Math.PI) as Radians;\n } else if (diff > Math.PI) {\n diff = (diff - 2 * Math.PI) as Radians;\n }\n\n return Math.abs(diff) as Radians;\n}\n", "import type { GlobalPoint, LocalPoint, Vector } from \"./types\";\n\n/**\n * Create a vector from the x and y coordiante elements.\n *\n * @param x The X aspect of the vector\n * @param y T Y aspect of the vector\n * @returns The constructed vector with X and Y as the coordinates\n */\nexport function vector(\n x: number,\n y: number,\n originX: number = 0,\n originY: number = 0,\n): Vector {\n return [x - originX, y - originY] as Vector;\n}\n\n/**\n * Turn a point into a vector with the origin point.\n *\n * @param p The point to turn into a vector\n * @param origin The origin point in a given coordiante system\n * @param threshold The threshold to consider the vector as 'undefined'\n * @param defaultValue The default value to return if the vector is 'undefined'\n * @returns The created vector from the point and the origin or default\n */\nexport function vectorFromPoint<Point extends GlobalPoint | LocalPoint>(\n p: Point,\n origin: Point = [0, 0] as Point,\n threshold?: number,\n defaultValue: Vector = [0, 1] as Vector,\n): Vector {\n const vec = vector(p[0] - origin[0], p[1] - origin[1]);\n\n if (threshold && vectorMagnitudeSq(vec) < threshold * threshold) {\n return defaultValue;\n }\n\n return vec;\n}\n\n/**\n * Cross product is a binary operation on two vectors in 2D space.\n * It results in a vector that is perpendicular to both vectors.\n *\n * @param a One of the vectors to use for the directed area calculation\n * @param b The other vector to use for the directed area calculation\n * @returns The directed area value for the two vectos\n */\nexport function vectorCross(a: Vector, b: Vector): number {\n return a[0] * b[1] - b[0] * a[1];\n}\n\n/**\n * Dot product is defined as the sum of the products of the\n * two vectors.\n *\n * @param a One of the vectors for which the sum of products is calculated\n * @param b The other vector for which the sum of products is calculated\n * @returns The sum of products of the two vectors\n */\nexport function vectorDot(a: Vector, b: Vector) {\n return a[0] * b[0] + a[1] * b[1];\n}\n\n/**\n * Determines if the value has the shape of a Vector.\n *\n * @param v The value to test\n * @returns TRUE if the value has the shape and components of a Vectors\n */\nexport function isVector(v: unknown): v is Vector {\n return (\n Array.isArray(v) &&\n v.length === 2 &&\n typeof v[0] === \"number\" &&\n !isNaN(v[0]) &&\n typeof v[1] === \"number\" &&\n !isNaN(v[1])\n );\n}\n\n/**\n * Add two vectors by adding their coordinates.\n *\n * @param a One of the vectors to add\n * @param b The other vector to add\n * @returns The sum vector of the two provided vectors\n */\nexport function vectorAdd(a: Readonly<Vector>, b: Readonly<Vector>): Vector {\n return [a[0] + b[0], a[1] + b[1]] as Vector;\n}\n\n/**\n * Add two vectors by adding their coordinates.\n *\n * @param start One of the vectors to add\n * @param end The other vector to add\n * @returns The sum vector of the two provided vectors\n */\nexport function vectorSubtract(\n start: Readonly<Vector>,\n end: Readonly<Vector>,\n): Vector {\n return [start[0] - end[0], start[1] - end[1]] as Vector;\n}\n\n/**\n * Scale vector by a scalar.\n *\n * @param v The vector to scale\n * @param scalar The scalar to multiply the vector components with\n * @returns The new scaled vector\n */\nexport function vectorScale(v: Vector, scalar: number): Vector {\n return vector(v[0] * scalar, v[1] * scalar);\n}\n\n/**\n * Calculates the sqare magnitude of a vector. Use this if you compare\n * magnitudes as it saves you an SQRT.\n *\n * @param v The vector to measure\n * @returns The scalar squared magnitude of the vector\n */\nexport function vectorMagnitudeSq(v: Vector) {\n return v[0] * v[0] + v[1] * v[1];\n}\n\n/**\n * Calculates the magnitude of a vector.\n *\n * @param v The vector to measure\n * @returns The scalar magnitude of the vector\n */\nexport function vectorMagnitude(v: Vector) {\n return Math.sqrt(vectorMagnitudeSq(v));\n}\n\n/**\n * Normalize the vector (i.e. make the vector magnitue equal 1).\n *\n * @param v The vector to normalize\n * @returns The new normalized vector\n */\nexport const vectorNormalize = (v: Vector): Vector => {\n const m = vectorMagnitude(v);\n\n if (m === 0) {\n return vector(0, 0);\n }\n\n return vector(v[0] / m, v[1] / m);\n};\n\n/**\n * Calculate the right-hand normal of the vector.\n */\nexport const vectorNormal = (v: Vector): Vector => vector(v[1], -v[0]);\n", "import { degreesToRadians } from \"./angle\";\nimport { PRECISION } from \"./utils\";\nimport { vectorFromPoint, vectorScale } from \"./vector\";\n\nimport type {\n LocalPoint,\n GlobalPoint,\n Radians,\n Degrees,\n Vector,\n} from \"./types\";\n\n/**\n * Create a properly typed Point instance from the X and Y coordinates.\n *\n * @param x The X coordinate\n * @param y The Y coordinate\n * @returns The branded and created point\n */\nexport function pointFrom<Point extends GlobalPoint | LocalPoint>(\n x: number,\n y: number,\n): Point {\n return [x, y] as Point;\n}\n\n/**\n * Converts and remaps an array containing a pair of numbers to Point.\n *\n * @param numberArray The number array to check and to convert to Point\n * @returns The point instance\n */\nexport function pointFromArray<Point extends GlobalPoint | LocalPoint>(\n numberArray: number[],\n): Point | undefined {\n return numberArray.length === 2\n ? pointFrom<Point>(numberArray[0], numberArray[1])\n : undefined;\n}\n\n/**\n * Converts and remaps a pair of numbers to Point.\n *\n * @param pair A number pair to convert to Point\n * @returns The point instance\n */\nexport function pointFromPair<Point extends GlobalPoint | LocalPoint>(\n pair: [number, number],\n): Point {\n return pair as Point;\n}\n\n/**\n * Convert a vector to a point.\n *\n * @param v The vector to convert\n * @returns The point the vector points at with origin 0,0\n */\nexport function pointFromVector<P extends GlobalPoint | LocalPoint>(\n v: Vector,\n offset: P = pointFrom(0, 0),\n): P {\n return pointFrom<P>(offset[0] + v[0], offset[1] + v[1]);\n}\n\n/**\n * Checks if the provided value has the shape of a Point.\n *\n * @param p The value to attempt verification on\n * @returns TRUE if the provided value has the shape of a local or global point\n */\nexport function isPoint(p: unknown): p is LocalPoint | GlobalPoint {\n return (\n Array.isArray(p) &&\n p.length === 2 &&\n typeof p[0] === \"number\" &&\n !isNaN(p[0]) &&\n typeof p[1] === \"number\" &&\n !isNaN(p[1])\n );\n}\n\n/**\n * Compare two points coordinate-by-coordinate and if\n * they are closer than INVERSE_PRECISION it returns TRUE.\n *\n * @param a Point The first point to compare\n * @param b Point The second point to compare\n * @returns TRUE if the points are sufficiently close to each other\n */\nexport function pointsEqual<Point extends GlobalPoint | LocalPoint>(\n a: Point,\n b: Point,\n tolerance: number = PRECISION,\n): boolean {\n const abs = Math.abs;\n return abs(a[0] - b[0]) < tolerance && abs(a[1] - b[1]) < tolerance;\n}\n\n/**\n * Rotate a point by [angle] radians.\n *\n * @param point The point to rotate\n * @param center The point to rotate around, the center point\n * @param angle The radians to rotate the point by\n * @returns The rotated point\n */\nexport function pointRotateRads<Point extends GlobalPoint | LocalPoint>(\n [x, y]: Point,\n [cx, cy]: Point,\n angle: Radians,\n): Point {\n return pointFrom(\n (x - cx) * Math.cos(angle) - (y - cy) * Math.sin(angle) + cx,\n (x - cx) * Math.sin(angle) + (y - cy) * Math.cos(angle) + cy,\n );\n}\n\n/**\n * Rotate a point by [angle] degree.\n *\n * @param point The point to rotate\n * @param center The point to rotate around, the center point\n * @param angle The degree to rotate the point by\n * @returns The rotated point\n */\nexport function pointRotateDegs<Point extends GlobalPoint | LocalPoint>(\n point: Point,\n center: Point,\n angle: Degrees,\n): Point {\n return pointRotateRads(point, center, degreesToRadians(angle));\n}\n\n/**\n * Translate a point by a vector.\n *\n * WARNING: This is not for translating Excalidraw element points!\n * You need to account for rotation on base coordinates\n * on your own.\n * CONSIDER USING AN APPROPRIATE ELEMENT-AWARE TRANSLATE!\n *\n * @param p The point to apply the translation on\n * @param v The vector to translate by\n * @returns\n */\n// TODO 99% of use is translating between global and local coords, which need to be formalized\nexport function pointTranslate<\n From extends GlobalPoint | LocalPoint,\n To extends GlobalPoint | LocalPoint,\n>(p: From, v: Vector = [0, 0] as Vector): To {\n return pointFrom(p[0] + v[0], p[1] + v[1]);\n}\n\n/**\n * Find the center point at equal distance from both points.\n *\n * @param a One of the points to create the middle point for\n * @param b The other point to create the middle point for\n * @returns The middle point\n */\nexport function pointCenter<P extends LocalPoint | GlobalPoint>(a: P, b: P): P {\n return pointFrom((a[0] + b[0]) / 2, (a[1] + b[1]) / 2);\n}\n\n/**\n * Calculate the distance between two points.\n *\n * @param a First point\n * @param b Second point\n * @returns The euclidean distance between the two points.\n */\nexport function pointDistance<P extends LocalPoint | GlobalPoint>(\n a: P,\n b: P,\n): number {\n return Math.hypot(b[0] - a[0], b[1] - a[1]);\n}\n\n/**\n * Calculate the squared distance between two points.\n *\n * Note: Use this if you only compare distances, it saves a square root.\n *\n * @param a First point\n * @param b Second point\n * @returns The euclidean distance between the two points.\n */\nexport function pointDistanceSq<P extends LocalPoint | GlobalPoint>(\n a: P,\n b: P,\n): number {\n const xDiff = b[0] - a[0];\n const yDiff = b[1] - a[1];\n\n return xDiff * xDiff + yDiff * yDiff;\n}\n\n/**\n * Scale a point from a given origin by the multiplier.\n *\n * @param p The point to scale\n * @param mid The origin to scale from\n * @param multiplier The scaling factor\n * @returns\n */\nexport const pointScaleFromOrigin = <P extends GlobalPoint | LocalPoint>(\n p: P,\n mid: P,\n multiplier: number,\n) => pointTranslate(mid, vectorScale(vectorFromPoint(p, mid), multiplier));\n\n/**\n * Returns whether `q` lies inside the segment/rectangle defined by `p` and `r`.\n * This is an approximation to \"does `q` lie on a segment `pr`\" check.\n *\n * @param p The first point to compare against\n * @param q The actual point this function checks whether is in between\n * @param r The other point to compare against\n * @returns TRUE if q is indeed between p and r\n */\nexport const isPointWithinBounds = <P extends GlobalPoint | LocalPoint>(\n p: P,\n q: P,\n r: P,\n) => {\n return (\n q[0] <= Math.max(p[0], r[0]) &&\n q[0] >= Math.min(p[0], r[0]) &&\n q[1] <= Math.max(p[1], r[1]) &&\n q[1] >= Math.min(p[1], r[1])\n );\n};\n", "export const PRECISION = 10e-5;\n\n// Legendre-Gauss abscissae (x values) and weights for n=24\n// Refeerence: https://pomax.github.io/bezierinfo/legendre-gauss.html\nexport const LegendreGaussN24TValues = [\n -0.0640568928626056260850430826247450385909,\n 0.0640568928626056260850430826247450385909,\n -0.1911188674736163091586398207570696318404,\n 0.1911188674736163091586398207570696318404,\n -0.3150426796961633743867932913198102407864,\n 0.3150426796961633743867932913198102407864,\n -0.4337935076260451384870842319133497124524,\n 0.4337935076260451384870842319133497124524,\n -0.5454214713888395356583756172183723700107,\n 0.5454214713888395356583756172183723700107,\n -0.6480936519369755692524957869107476266696,\n 0.6480936519369755692524957869107476266696,\n -0.7401241915785543642438281030999784255232,\n 0.7401241915785543642438281030999784255232,\n -0.8200019859739029219539498726697452080761,\n 0.8200019859739029219539498726697452080761,\n -0.8864155270044010342131543419821967550873,\n 0.8864155270044010342131543419821967550873,\n -0.9382745520027327585236490017087214496548,\n 0.9382745520027327585236490017087214496548,\n -0.9747285559713094981983919930081690617411,\n 0.9747285559713094981983919930081690617411,\n -0.9951872199970213601799974097007368118745,\n 0.9951872199970213601799974097007368118745,\n];\n\nexport const LegendreGaussN24CValues = [\n 0.1279381953467521569740561652246953718517,\n 0.1279381953467521569740561652246953718517,\n 0.1258374563468282961213753825111836887264,\n 0.1258374563468282961213753825111836887264,\n 0.121670472927803391204463153476262425607,\n 0.121670472927803391204463153476262425607,\n 0.1155056680537256013533444839067835598622,\n 0.1155056680537256013533444839067835598622,\n 0.1074442701159656347825773424466062227946,\n 0.1074442701159656347825773424466062227946,\n 0.0976186521041138882698806644642471544279,\n 0.0976186521041138882698806644642471544279,\n 0.086190161531953275917185202983742667185,\n 0.086190161531953275917185202983742667185,\n 0.0733464814110803057340336152531165181193,\n 0.0733464814110803057340336152531165181193,\n 0.0592985849154367807463677585001085845412,\n 0.0592985849154367807463677585001085845412,\n 0.0442774388174198061686027482113382288593,\n 0.0442774388174198061686027482113382288593,\n 0.0285313886289336631813078159518782864491,\n 0.0285313886289336631813078159518782864491,\n 0.0123412297999871995468056670700372915759,\n 0.0123412297999871995468056670700372915759,\n];\n", "import { isPoint, pointDistance, pointFrom, pointFromVector } from \"./point\";\nimport { vector, vectorNormal, vectorNormalize, vectorScale } from \"./vector\";\nimport { LegendreGaussN24CValues, LegendreGaussN24TValues } from \"./constants\";\n\nimport type { Curve, GlobalPoint, LineSegment, LocalPoint } from \"./types\";\n\n/**\n *\n * @param a\n * @param b\n * @param c\n * @param d\n * @returns\n */\nexport function curve<Point extends GlobalPoint | LocalPoint>(\n a: Point,\n b: Point,\n c: Point,\n d: Point,\n) {\n return [a, b, c, d] as Curve<Point>;\n}\n\nfunction gradient(\n f: (t: number, s: number) => number,\n t0: number,\n s0: number,\n delta: number = 1e-6,\n): number[] {\n return [\n (f(t0 + delta, s0) - f(t0 - delta, s0)) / (2 * delta),\n (f(t0, s0 + delta) - f(t0, s0 - delta)) / (2 * delta),\n ];\n}\n\nfunction solve(\n f: (t: number, s: number) => [number, number],\n t0: number,\n s0: number,\n tolerance: number = 1e-3,\n iterLimit: number = 10,\n): number[] | null {\n let error = Infinity;\n let iter = 0;\n\n while (error >= tolerance) {\n if (iter >= iterLimit) {\n return null;\n }\n\n const y0 = f(t0, s0);\n const jacobian = [\n gradient((t, s) => f(t, s)[0], t0, s0),\n gradient((t, s) => f(t, s)[1], t0, s0),\n ];\n const b = [[-y0[0]], [-y0[1]]];\n const det =\n jacobian[0][0] * jacobian[1][1] - jacobian[0][1] * jacobian[1][0];\n\n if (det === 0) {\n return null;\n }\n\n const iJ = [\n [jacobian[1][1] / det, -jacobian[0][1] / det],\n [-jacobian[1][0] / det, jacobian[0][0] / det],\n ];\n const h = [\n [iJ[0][0] * b[0][0] + iJ[0][1] * b[1][0]],\n [iJ[1][0] * b[0][0] + iJ[1][1] * b[1][0]],\n ];\n\n t0 = t0 + h[0][0];\n s0 = s0 + h[1][0];\n\n const [tErr, sErr] = f(t0, s0);\n error = Math.max(Math.abs(tErr), Math.abs(sErr));\n iter += 1;\n }\n\n return [t0, s0];\n}\n\nexport const bezierEquation = <Point extends GlobalPoint | LocalPoint>(\n c: Curve<Point>,\n t: number,\n) =>\n pointFrom<Point>(\n (1 - t) ** 3 * c[0][0] +\n 3 * (1 - t) ** 2 * t * c[1][0] +\n 3 * (1 - t) * t ** 2 * c[2][0] +\n t ** 3 * c[3][0],\n (1 - t) ** 3 * c[0][1] +\n 3 * (1 - t) ** 2 * t * c[1][1] +\n 3 * (1 - t) * t ** 2 * c[2][1] +\n t ** 3 * c[3][1],\n );\n\n/**\n * Computes the intersection between a cubic spline and a line segment.\n */\nexport function curveIntersectLineSegment<\n Point extends GlobalPoint | LocalPoint,\n>(c: Curve<Point>, l: LineSegment<Point>): Point[] {\n const line = (s: number) =>\n pointFrom<Point>(\n l[0][0] + s * (l[1][0] - l[0][0]),\n l[0][1] + s * (l[1][1] - l[0][1]),\n );\n\n const initial_guesses: [number, number][] = [\n [0.5, 0],\n [0.2, 0],\n [0.8, 0],\n ];\n\n const calculate = ([t0, s0]: [number, number]) => {\n const solution = solve(\n (t: number, s: number) => {\n const bezier_point = bezierEquation(c, t);\n const line_point = line(s);\n\n return [\n bezier_point[0] - line_point[0],\n bezier_point[1] - line_point[1],\n ];\n },\n t0,\n s0,\n );\n\n if (!solution) {\n return null;\n }\n\n const [t, s] = solution;\n\n if (t < 0 || t > 1 || s < 0 || s > 1) {\n return null;\n }\n\n return bezierEquation(c, t);\n };\n\n let solution = calculate(initial_guesses[0]);\n if (solution) {\n return [solution];\n }\n\n solution = calculate(initial_guesses[1]);\n if (solution) {\n return [solution];\n }\n\n solution = calculate(initial_guesses[2]);\n if (solution) {\n return [solution];\n }\n\n return [];\n}\n\n/**\n * Finds the closest point on the Bezier curve from another point\n *\n * @param x\n * @param y\n * @param P0\n * @param P1\n * @param P2\n * @param P3\n * @param tolerance\n * @param maxLevel\n * @returns\n */\nexport function curveClosestPoint<Point extends GlobalPoint | LocalPoint>(\n c: Curve<Point>,\n p: Point,\n tolerance: number = 1e-3,\n): Point | null {\n const localMinimum = (\n min: number,\n max: number,\n f: (t: number) => number,\n e: number = tolerance,\n ) => {\n let m = min;\n let n = max;\n let k;\n\n while (n - m > e) {\n k = (n + m) / 2;\n if (f(k - e) < f(k + e)) {\n n = k;\n } else {\n m = k;\n }\n }\n\n return k;\n };\n\n const maxSteps = 30;\n let closestStep = 0;\n for (let min = Infinity, step = 0; step < maxSteps; step++) {\n const d = pointDistance(p, bezierEquation(c, step / maxSteps));\n if (d < min) {\n min = d;\n closestStep = step;\n }\n }\n\n const t0 = Math.max((closestStep - 1) / maxSteps, 0);\n const t1 = Math.min((closestStep + 1) / maxSteps, 1);\n const solution = localMinimum(t0, t1, (t) =>\n pointDistance(p, bezierEquation(c, t)),\n );\n\n if (!solution) {\n return null;\n }\n\n return bezierEquation(c, solution);\n}\n\n/**\n * Determines the distance between a point and the closest point on the\n * Bezier curve.\n *\n * @param c The curve to test\n * @param p The point to measure from\n */\nexport function curvePointDistance<Point extends GlobalPoint | LocalPoint>(\n c: Curve<Point>,\n p: Point,\n) {\n const closest = curveClosestPoint(c, p);\n\n if (!closest) {\n return 0;\n }\n\n return pointDistance(p, closest);\n}\n\n/**\n * Determines if the parameter is a Curve\n */\nexport function isCurve<P extends GlobalPoint | LocalPoint>(\n v: unknown,\n): v is Curve<P> {\n return (\n Array.isArray(v) &&\n v.length === 4 &&\n isPoint(v[0]) &&\n isPoint(v[1]) &&\n isPoint(v[2]) &&\n isPoint(v[3])\n );\n}\n\nexport function curveTangent<Point extends GlobalPoint | LocalPoint>(\n [p0, p1, p2, p3]: Curve<Point>,\n t: number,\n) {\n return vector(\n -3 * (1 - t) * (1 - t) * p0[0] +\n 3 * (1 - t) * (1 - t) * p1[0] -\n 6 * t * (1 - t) * p1[0] -\n 3 * t * t * p2[0] +\n 6 * t * (1 - t) * p2[0] +\n 3 * t * t * p3[0],\n -3 * (1 - t) * (1 - t) * p0[1] +\n 3 * (1 - t) * (1 - t) * p1[1] -\n 6 * t * (1 - t) * p1[1] -\n 3 * t * t * p2[1] +\n 6 * t * (1 - t) * p2[1] +\n 3 * t * t * p3[1],\n );\n}\n\nexport function curveCatmullRomQuadraticApproxPoints(\n points: GlobalPoint[],\n tension = 0.5,\n) {\n if (points.length < 2) {\n return;\n }\n\n const pointSets: [GlobalPoint, GlobalPoint][] = [];\n for (let i = 0; i < points.length - 1; i++) {\n const p0 = points[i - 1 < 0 ? 0 : i - 1];\n const p1 = points[i];\n const p2 = points[i + 1 >= points.length ? points.length - 1 : i + 1];\n const cpX = p1[0] + ((p2[0] - p0[0]) * tension) / 2;\n const cpY = p1[1] + ((p2[1] - p0[1]) * tension) / 2;\n\n pointSets.push([\n pointFrom<GlobalPoint>(cpX, cpY),\n pointFrom<GlobalPoint>(p2[0], p2[1]),\n ]);\n }\n\n return pointSets;\n}\n\nexport function curveCatmullRomCubicApproxPoints<\n Point extends GlobalPoint | LocalPoint,\n>(points: Point[], tension = 0.5) {\n if (points.length < 2) {\n return;\n }\n\n const pointSets: Curve<Point>[] = [];\n for (let i = 0; i < points.length - 1; i++) {\n const p0 = points[i - 1 < 0 ? 0 : i - 1];\n const p1 = points[i];\n const p2 = points[i + 1 >= points.length ? points.length - 1 : i + 1];\n const p3 = points[i + 2 >= points.length ? points.length - 1 : i + 2];\n const tangent1 = [(p2[0] - p0[0]) * tension, (p2[1] - p0[1]) * tension];\n const tangent2 = [(p3[0] - p1[0]) * tension, (p3[1] - p1[1]) * tension];\n const cp1x = p1[0] + tangent1[0] / 3;\n const cp1y = p1[1] + tangent1[1] / 3;\n const cp2x = p2[0] - tangent2[0] / 3;\n const cp2y = p2[1] - tangent2[1] / 3;\n\n pointSets.push(\n curve(\n pointFrom(p1[0], p1[1]),\n pointFrom(cp1x, cp1y),\n pointFrom(cp2x, cp2y),\n pointFrom(p2[0], p2[1]),\n ),\n );\n }\n\n return pointSets;\n}\n\nexport function curveOffsetPoints(\n [p0, p1, p2, p3]: Curve<GlobalPoint>,\n offset: number,\n steps = 50,\n) {\n const offsetPoints = [];\n\n for (let i = 0; i <= steps; i++) {\n const t = i / steps;\n const c = curve(p0, p1, p2, p3);\n const point = bezierEquation(c, t);\n const tangent = vectorNormalize(curveTangent(c, t));\n const normal = vectorNormal(tangent);\n\n offsetPoints.push(pointFromVector(vectorScale(normal, offset), point));\n }\n\n return offsetPoints;\n}\n\nexport function offsetPointsForQuadraticBezier(\n p0: GlobalPoint,\n p1: GlobalPoint,\n p2: GlobalPoint,\n offsetDist: number,\n steps = 50,\n) {\n const offsetPoints = [];\n\n for (let i = 0; i <= steps; i++) {\n const t = i / steps;\n const t1 = 1 - t;\n const point = pointFrom<GlobalPoint>(\n t1 * t1 * p0[0] + 2 * t1 * t * p1[0] + t * t * p2[0],\n t1 * t1 * p0[1] + 2 * t1 * t * p1[1] + t * t * p2[1],\n );\n const tangentX = 2 * (1 - t) * (p1[0] - p0[0]) + 2 * t * (p2[0] - p1[0]);\n const tangentY = 2 * (1 - t) * (p1[1] - p0[1]) + 2 * t * (p2[1] - p1[1]);\n const tangent = vectorNormalize(vector(tangentX, tangentY));\n const normal = vectorNormal(tangent);\n\n offsetPoints.push(pointFromVector(vectorScale(normal, offsetDist), point));\n }\n\n return offsetPoints;\n}\n\n/**\n * Implementation based on Legendre-Gauss quadrature for more accurate arc\n * length calculation.\n *\n * Reference: https://pomax.github.io/bezierinfo/#arclength\n *\n * @param c The curve to calculate the length of\n * @returns The approximated length of the curve\n */\nexport function curveLength<P extends GlobalPoint | LocalPoint>(\n c: Curve<P>,\n): number {\n const z2 = 0.5;\n let sum = 0;\n\n for (let i = 0; i < 24; i++) {\n const t = z2 * LegendreGaussN24TValues[i] + z2;\n const derivativeVector = curveTangent(c, t);\n const magnitude = Math.sqrt(\n derivativeVector[0] * derivativeVector[0] +\n derivativeVector[1] * derivativeVector[1],\n );\n sum += LegendreGaussN24CValues[i] * magnitude;\n }\n\n return z2 * sum;\n}\n\n/**\n * Calculates the curve length from t=0 to t=parameter using the same\n * Legendre-Gauss quadrature method used in curveLength\n *\n * @param c The curve to calculate the partial length for\n * @param t The parameter value (0 to 1) to calculate length up to\n * @returns The length of the curve from beginning to parameter t\n */\nexport function curveLengthAtParameter<P extends GlobalPoint | LocalPoint>(\n c: Curve<P>,\n t: number,\n): number {\n if (t <= 0) {\n return 0;\n }\n if (t >= 1) {\n return curveLength(c);\n }\n\n // Scale and shift the integration interval from [0,t] to [-1,1]\n // which is what the Legendre-Gauss quadrature expects\n const z1 = t / 2;\n const z2 = t / 2;\n\n let sum = 0;\n\n for (let i = 0; i < 24; i++) {\n const parameter = z1 * LegendreGaussN24TValues[i] + z2;\n const derivativeVector = curveTangent(c, parameter);\n const magnitude = Math.sqrt(\n derivativeVector[0] * derivativeVector[0] +\n derivativeVector[1] * derivativeVector[1],\n );\n sum += LegendreGaussN24CValues[i] * magnitude;\n }\n\n return z1 * sum; // Scale the result back to the original interval\n}\n\n/**\n * Calculates the point at a specific percentage of a curve's total length\n * using binary search for improved efficiency and accuracy.\n *\n * @param c The curve to calculate point on\n * @param percent A value between 0 and 1 representing the percentage of the curve's length\n * @returns The point at the specified percentage of curve length\n */\nexport function curvePointAtLength<P extends GlobalPoint | LocalPoint>(\n c: Curve<P>,\n percent: number,\n): P {\n if (percent <= 0) {\n return bezierEquation(c, 0);\n }\n\n if (percent >= 1) {\n return bezierEquation(c, 1);\n }\n\n const totalLength = curveLength(c);\n const targetLength = totalLength * percent;\n\n // Binary search to find parameter t where length at t equals target length\n let tMin = 0;\n let tMax = 1;\n let t = percent; // Start with a reasonable guess (t = percent)\n let currentLength = 0;\n\n // Tolerance for length comparison and iteration limit to avoid infinite loops\n const tolerance = totalLength * 0.0001;\n const maxIterations = 20;\n\n for (let iteration = 0; iteration < maxIterations; iteration++) {\n currentLength = curveLengthAtParameter(c, t);\n const error = Math.abs(currentLength - targetLength);\n\n if (error < tolerance) {\n break;\n }\n\n if (currentLength < targetLength) {\n tMin = t;\n } else {\n tMax = t;\n }\n\n t = (tMin + tMax) / 2;\n }\n\n return bezierEquation(c, t);\n}\n", "import {\n pointFrom,\n pointDistance,\n pointFromVector,\n pointsEqual,\n} from \"./point\";\nimport { PRECISION } from \"./utils\";\nimport {\n vector,\n vectorAdd,\n vectorDot,\n vectorFromPoint,\n vectorScale,\n} from \"./vector\";\n\nimport type {\n Ellipse,\n GlobalPoint,\n Line,\n LineSegment,\n LocalPoint,\n} from \"./types\";\n\n/**\n * Construct an Ellipse object from the parameters\n *\n * @param center The center of the ellipse\n * @param angle The slanting of the ellipse in radians\n * @param halfWidth Half of the width of a non-slanted version of the ellipse\n * @param halfHeight Half of the height of a non-slanted version of the ellipse\n * @returns The constructed Ellipse object\n */\nexport function ellipse<Point extends GlobalPoint | LocalPoint>(\n center: Point,\n halfWidth: number,\n halfHeight: number,\n): Ellipse<Point> {\n return {\n center,\n halfWidth,\n halfHeight,\n } as Ellipse<Point>;\n}\n\n/**\n * Determines if a point is inside or on the ellipse outline\n *\n * @param p The point to test\n * @param ellipse The ellipse to compare against\n * @returns TRUE if the point is inside or on the outline of the ellipse\n */\nexport const ellipseIncludesPoint = <Point extends GlobalPoint | LocalPoint>(\n p: Point,\n ellipse: Ellipse<Point>,\n) => {\n const { center, halfWidth, halfHeight } = ellipse;\n const normalizedX = (p[0] - center[0]) / halfWidth;\n const normalizedY = (p[1] - center[1]) / halfHeight;\n\n return normalizedX * normalizedX + normalizedY * normalizedY <= 1;\n};\n\n/**\n * Tests whether a point lies on the outline of the ellipse within a given\n * tolerance\n *\n * @param point The point to test\n * @param ellipse The ellipse to compare against\n * @param threshold The distance to consider a point close enough to be \"on\" the outline\n * @returns TRUE if the point is on the ellise outline\n */\nexport const ellipseTouchesPoint = <Point extends GlobalPoint | LocalPoint>(\n point: Point,\n ellipse: Ellipse<Point>,\n threshold = PRECISION,\n) => {\n return ellipseDistanceFromPoint(point, ellipse) <= threshold;\n};\n\n/**\n * Determine the shortest euclidean distance from a point to the\n * outline of the ellipse\n *\n * @param p The point to consider\n * @param ellipse The ellipse to calculate the distance to\n * @returns The eucledian distance\n */\nexport const ellipseDistanceFromPoint = <\n Point extends GlobalPoint | LocalPoint,\n>(\n p: Point,\n ellipse: Ellipse<Point>,\n): number => {\n const { halfWidth, halfHeight, center } = ellipse;\n const a = halfWidth;\n const b = halfHeight;\n const translatedPoint = vectorAdd(\n vectorFromPoint(p),\n vectorScale(vectorFromPoint(center), -1),\n );\n\n const px = Math.abs(translatedPoint[0]);\n const py = Math.abs(translatedPoint[1]);\n\n let tx = 0.707;\n let ty = 0.707;\n\n for (let i = 0; i < 3; i++) {\n const x = a * tx;\n const y = b * ty;\n\n const ex = ((a * a - b * b) * tx ** 3) / a;\n const ey = ((b * b - a * a) * ty ** 3) / b;\n\n const rx = x - ex;\n const ry = y - ey;\n\n const qx = px - ex;\n const qy = py - ey;\n\n const r = Math.hypot(ry, rx);\n const q = Math.hypot(qy, qx);\n\n tx = Math.min(1, Math.max(0, ((qx * r) / q + ex) / a));\n ty = Math.min(1, Math.max(0, ((qy * r) / q + ey) / b));\n const t = Math.hypot(ty, tx);\n tx /= t;\n ty /= t;\n }\n\n const [minX, minY] = [\n a * tx * Math.sign(translatedPoint[0]),\n b * ty * Math.sign(translatedPoint[1]),\n ];\n\n return pointDistance(pointFromVector(translatedPoint), pointFrom(minX, minY));\n};\n\n/**\n * Calculate a maximum of two intercept points for a line going throug an\n * ellipse.\n */\nexport function ellipseSegmentInterceptPoints<\n Point extends GlobalPoint | LocalPoint,\n>(e: Readonly<Ellipse<Point>>, s: Readonly<LineSegment<Point>>): Point[] {\n const rx = e.halfWidth;\n const ry = e.halfHeight;\n\n const dir = vectorFromPoint(s[1], s[0]);\n const diff = vector(s[0][0] - e.center[0], s[0][1] - e.center[1]);\n const mDir = vector(dir[0] / (rx * rx), dir[1] / (ry * ry));\n const mDiff = vector(diff[0] / (rx * rx), diff[1] / (ry * ry));\n\n const a = vectorDot(dir, mDir);\n const b = vectorDot(dir, mDiff);\n const c = vectorDot(diff, mDiff) - 1.0;\n const d = b * b - a * c;\n\n const intersections: Point[] = [];\n\n if (d > 0) {\n const t_a = (-b - Math.sqrt(d)) / a;\n const t_b = (-b + Math.sqrt(d)) / a;\n\n if (0 <= t_a && t_a <= 1) {\n intersections.push(\n pointFrom(\n s[0][0] + (s[1][0] - s[0][0]) * t_a,\n s[0][1] + (s[1][1] - s[0][1]) * t_a,\n ),\n );\n }\n\n if (0 <= t_b && t_b <= 1) {\n intersections.push(\n pointFrom(\n s[0][0] + (s[1][0] - s[0][0]) * t_b,\n s[0][1] + (s[1][1] - s[0][1]) * t_b,\n ),\n );\n }\n } else if (d === 0) {\n const t = -b / a;\n if (0 <= t && t <= 1) {\n intersections.push(\n pointFrom(\n s[0][0] + (s[1][0] - s[0][0]) * t,\n s[0][1] + (s[1][1] - s[0][1]) * t,\n ),\n );\n }\n }\n\n return intersections;\n}\n\nexport function ellipseLineIntersectionPoints<\n Point extends GlobalPoint | LocalPoint,\n>(\n { center, halfWidth, halfHeight }: Ellipse<Point>,\n [g, h]: Line<Point>,\n): Point[] {\n const [cx, cy] = center;\n const x1 = g[0] - cx;\n const y1 = g[1] - cy;\n const x2 = h[0] - cx;\n const y2 = h[1] - cy;\n const a =\n Math.pow(x2 - x1, 2) / Math.pow(halfWidth, 2) +\n Math.pow(y2 - y1, 2) / Math.pow(halfHeight, 2);\n const b =\n 2 *\n ((x1 * (x2 - x1)) / Math.pow(halfWidth, 2) +\n (y1 * (y2 - y1)) / Math.pow(halfHeight, 2));\n const c =\n Math.pow(x1, 2) / Math.pow(halfWidth, 2) +\n Math.pow(y1, 2) / Math.pow(halfHeight, 2) -\n 1;\n const t1 = (-b + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);\n const t2 = (-b - Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);\n const candidates = [\n pointFrom<Point>(x1 + t1 * (x2 - x1) + cx, y1 + t1 * (y2 - y1) + cy),\n pointFrom<Point>(x1 + t2 * (x2 - x1) + cx, y1 + t2 * (y2 - y1) + cy),\n ].filter((p) => !isNaN(p[0]) && !isNaN(p[1]));\n\n if (candidates.length === 2 && pointsEqual(candidates[0], candidates[1])) {\n return [candidates[0]];\n }\n\n return candidates;\n}\n", "import { pointFrom } from \"./point\";\n\nimport type { GlobalPoint, Line, LocalPoint } from \"./types\";\n\n/**\n * Create a line from two points.\n *\n * @param points The two points lying on the line\n * @returns The line on which the points lie\n */\nexport function line<P extends GlobalPoint | LocalPoint>(a: P, b: P): Line<P> {\n return [a, b] as Line<P>;\n}\n\n/**\n * Determines the intersection point (unless the lines are parallel) of two\n * lines\n *\n * @param a\n * @param b\n * @returns\n */\nexport function linesIntersectAt<Point extends GlobalPoint | LocalPoint>(\n a: Line<Point>,\n b: Line<Point>,\n): Point | null {\n const A1 = a[1][1] - a[0][1];\n const B1 = a[0][0] - a[1][0];\n const A2 = b[1][1] - b[0][1];\n const B2 = b[0][0] - b[1][0];\n const D = A1 * B2 - A2 * B1;\n if (D !== 0) {\n const C1 = A1 * a[0][0] + B1 * a[0][1];\n const C2 = A2 * b[0][0] + B2 * b[0][1];\n return pointFrom<Point>((C1 * B2 - C2 * B1) / D, (A1 * C2 - A2 * C1) / D);\n }\n\n return null;\n}\n", "import { line, linesIntersectAt } from \"./line\";\nimport {\n isPoint,\n pointCenter,\n pointFromVector,\n pointRotateRads,\n} from \"./point\";\nimport { PRECISION } from \"./utils\";\nimport {\n vectorAdd,\n vectorCross,\n vectorFromPoint,\n vectorScale,\n vectorSubtract,\n} from \"./vector\";\n\nimport type { GlobalPoint, LineSegment, LocalPoint, Radians } from \"./types\";\n\n/**\n * Create a line segment from two points.\n *\n * @param points The two points delimiting the line segment on each end\n * @returns The line segment delineated by the points\n */\nexport function lineSegment<P extends GlobalPoint | LocalPoint>(\n a: P,\n b: P,\n): LineSegment<P> {\n return [a, b] as LineSegment<P>;\n}\n\n/**\n *\n * @param segment\n * @returns\n */\nexport const isLineSegment = <Point extends GlobalPoint | LocalPoint>(\n segment: unknown,\n): segment is LineSegment<Point> =>\n Array.isArray(segment) &&\n segment.length === 2 &&\n isPoint(segment[0]) &&\n isPoint(segment[0]);\n\n/**\n * Return the coordinates resulting from rotating the given line about an origin by an angle in radians\n * note that when the origin is not given, the midpoint of the given line is used as the origin.\n *\n * @param l\n * @param angle\n * @param origin\n * @returns\n */\nexport const lineSegmentRotate = <Point extends LocalPoint | GlobalPoint>(\n l: LineSegment<Point>,\n angle: Radians,\n origin?: Point,\n): LineSegment<Point> => {\n return lineSegment(\n pointRotateRads(l[0], origin || pointCenter(l[0], l[1]), angle),\n pointRotateRads(l[1], origin || pointCenter(l[0], l[1]), angle),\n );\n};\n\n/**\n * Calculates the point two line segments with a definite start and end point\n * intersect at.\n */\nexport const segmentsIntersectAt = <Point extends GlobalPoint | LocalPoint>(\n a: Readonly<LineSegment<Point>>,\n b: Readonly<LineSegment<Point>>,\n): Point | null => {\n const a0 = vectorFromPoint(a[0]);\n const a1 = vectorFromPoint(a[1]);\n const b0 = vectorFromPoint(b[0]);\n const b1 = vectorFromPoint(b[1]);\n const r = vectorSubtract(a1, a0);\n const s = vectorSubtract(b1, b0);\n const denominator = vectorCross(r, s);\n\n if (denominator === 0) {\n return null;\n }\n\n const i = vectorSubtract(vectorFromPoint(b[0]), vectorFromPoint(a[0]));\n const u = vectorCross(i, r) / denominator;\n const t = vectorCross(i, s) / denominator;\n\n if (u === 0) {\n return null;\n }\n\n const p = vectorAdd(a0, vectorScale(r, t));\n\n if (t >= 0 && t < 1 && u >= 0 && u < 1) {\n return pointFromVector<Point>(p);\n }\n\n return null;\n};\n\nexport const pointOnLineSegment = <Point extends LocalPoint | GlobalPoint>(\n point: Point,\n line: LineSegment<Point>,\n threshold = PRECISION,\n) => {\n const distance = distanceToLineSegment(point, line);\n\n if (distance === 0) {\n return true;\n }\n\n return distance < threshold;\n};\n\nexport const distanceToLineSegment = <Point extends LocalPoint | GlobalPoint>(\n point: Point,\n line: LineSegment<Point>,\n) => {\n const [x, y] = point;\n const [[x1, y1], [x2, y2]] = line;\n\n const A = x - x1;\n const B = y - y1;\n const C = x2 - x1;\n const D = y2 - y1;\n\n const dot = A * C + B * D;\n const len_sq = C * C + D * D;\n let param = -1;\n if (len_sq !== 0) {\n param = dot / len_sq;\n }\n\n let xx;\n let yy;\n\n if (param < 0) {\n xx = x1;\n yy = y1;\n } else if (param > 1) {\n xx = x2;\n yy = y2;\n } else {\n xx = x1 + param * C;\n yy = y1 + param * D;\n }\n\n const dx = x - xx;\n const dy = y - yy;\n return Math.sqrt(dx * dx + dy * dy);\n};\n\n/**\n * Returns the intersection point of a segment and a line\n *\n * @param l\n * @param s\n * @returns\n */\nexport function lineSegmentIntersectionPoints<\n Point extends GlobalPoint | LocalPoint,\n>(\n l: LineSegment<Point>,\n s: LineSegment<Point>,\n threshold?: number,\n): Point | null {\n const candidate = linesIntersectAt(line(l[0], l[1]), line(s[0], s[1]));\n\n if (\n !candidate ||\n !pointOnLineSegment(candidate, s, threshold) ||\n !pointOnLineSegment(candidate, l, threshold)\n ) {\n return null;\n }\n\n return candidate;\n}\n", "import { pointsEqual } from \"./point\";\nimport { lineSegment, pointOnLineSegment } from \"./segment\";\nimport { PRECISION } from \"./utils\";\n\nimport type { GlobalPoint, LocalPoint, Polygon } from \"./types\";\n\nexport function polygon<Point extends GlobalPoint | LocalPoint>(\n ...points: Point[]\n) {\n return polygonClose(points) as Polygon<Point>;\n}\n\nexport function polygonFromPoints<Point extends GlobalPoint | LocalPoint>(\n points: Point[],\n) {\n return polygonClose(points) as Polygon<Point>;\n}\n\nexport const polygonIncludesPoint = <Point extends LocalPoint | GlobalPoint>(\n point: Point,\n polygon: Polygon<Point>,\n) => {\n const x = point[0];\n const y = point[1];\n let inside = false;\n\n for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {\n const xi = polygon[i][0];\n const yi = polygon[i][1];\n const xj = polygon[j][0];\n const yj = polygon[j][1];\n\n if (\n ((yi > y && yj <= y) || (yi <= y && yj > y)) &&\n x < ((xj - xi) * (y - yi)) / (yj - yi) + xi\n ) {\n inside = !inside;\n }\n }\n\n return inside;\n};\n\nexport const polygonIncludesPointNonZero = <Point extends [number, number]>(\n point: Point,\n polygon: Point[],\n): boolean => {\n const [x, y] = point;\n let windingNumber = 0;\n\n for (let i = 0; i < polygon.length; i++) {\n const j = (i + 1) % polygon.length;\n const [xi, yi] = polygon[i];\n const [xj, yj] = polygon[j];\n\n if (yi <= y) {\n if (yj > y) {\n if ((xj - xi) * (y - yi) - (x - xi) * (yj - yi) > 0) {\n windingNumber++;\n }\n }\n } else if (yj <= y) {\n if ((xj - xi) * (y - yi) - (x - xi) * (yj - yi) < 0) {\n windingNumber--;\n }\n }\n }\n\n return windingNumber !== 0;\n};\n\nexport const pointOnPolygon = <Point extends LocalPoint | GlobalPoint>(\n p: Point,\n poly: Polygon<Point>,\n threshold = PRECISION,\n) => {\n let on = false;\n\n for (let i = 0, l = poly.length - 1; i < l; i++) {\n if (pointOnLineSegment(p, lineSegment(poly[i], poly[i + 1]), threshold)) {\n on = true;\n break;\n }\n }\n\n return on;\n};\n\nfunction polygonClose<Point extends LocalPoint | GlobalPoint>(\n polygon: Point[],\n) {\n return polygonIsClosed(polygon)\n ? polygon\n : ([...polygon, polygon[0]] as Polygon<Point>);\n}\n\nfunction polygonIsClosed<Point extends LocalPoint | GlobalPoint>(\n polygon: Point[],\n) {\n return pointsEqual(polygon[0], polygon[polygon.length - 1]);\n}\n", "import { toBrandedType } from \"@excalidraw/common\";\n\nimport type { InclusiveRange } from \"./types\";\n\n/**\n * Create an inclusive range from the two numbers provided.\n *\n * @param start Start of the range\n * @param end End of the range\n * @returns\n */\nexport function rangeInclusive(start: number, end: number): InclusiveRange {\n return toBrandedType<InclusiveRange>([start, end]);\n}\n\n/**\n * Turn a number pair into an inclusive range.\n *\n * @param pair The number pair to convert to an inclusive range\n * @returns The new inclusive range\n */\nexport function rangeInclusiveFromPair(pair: [start: number, end: number]) {\n return toBrandedType<InclusiveRange>(pair);\n}\n\n/**\n * Given two ranges, return if the two ranges overlap with each other e.g.\n * [1, 3] overlaps with [2, 4] while [1, 3] does not overlap with [4, 5].\n *\n * @param param0 One of the ranges to compare\n * @param param1 The other range to compare against\n * @returns TRUE if the ranges overlap\n */\nexport const rangesOverlap = (\n [a0, a1]: InclusiveRange,\n [b0, b1]: InclusiveRange,\n): boolean => {\n if (a0 <= b0) {\n return a1 >= b0;\n }\n\n if (a0 >= b0) {\n return b1 >= a0;\n }\n\n return false;\n};\n\n/**\n * Given two ranges,return ther intersection of the two ranges if any e.g. the\n * intersection of [1, 3] and [2, 4] is [2, 3].\n *\n * @param param0 The first range to compare\n * @param param1 The second range to compare\n * @returns The inclusive range intersection or NULL if no intersection\n */\nexport const rangeIntersection = (\n [a0, a1]: InclusiveRange,\n [b0, b1]: InclusiveRange,\n): InclusiveRange | null => {\n const rangeStart = Math.max(a0, b0);\n const rangeEnd = Math.min(a1, b1);\n\n if (rangeStart <= rangeEnd) {\n return toBrandedType<InclusiveRange>([rangeStart, rangeEnd]);\n }\n\n return null;\n};\n\n/**\n * Determine if a value is inside a range.\n *\n * @param value The value to check\n * @param range The range\n * @returns\n */\nexport const rangeIncludesValue = (\n value: number,\n [min, max]: InclusiveRange,\n): boolean => {\n return value >= min && value <= max;\n};\n", "import { pointFrom } from \"./point\";\nimport { lineSegment, lineSegmentIntersectionPoints } from \"./segment\";\n\nimport type { GlobalPoint, LineSegment, LocalPoint, Rectangle } from \"./types\";\n\nexport function rectangle<P extends GlobalPoint | LocalPoint>(\n topLeft: P,\n bottomRight: P,\n): Rectangle<P> {\n return [topLeft, bottomRight] as Rectangle<P>;\n}\n\nexport function rectangleFromNumberSequence<\n Point extends LocalPoint | GlobalPoint,\n>(minX: number, minY: number, maxX: number, maxY: number) {\n return rectangle(pointFrom<Point>(minX, minY), pointFrom<Point>(maxX, maxY));\n}\n\nexport function rectangleIntersectLineSegment<\n Point extends LocalPoint | GlobalPoint,\n>(r: Rectangle<Point>, l: LineSegment<Point>): Point[] {\n return [\n lineSegment(r[0], pointFrom(r[1][0], r[0][1])),\n lineSegment(pointFrom(r[1][0], r[0][1]), r[1]),\n lineSegment(r[1], pointFrom(r[0][0], r[1][1])),\n lineSegment(pointFrom(r[0][0], r[1][1]), r[0]),\n ]\n .map((s) => lineSegmentIntersectionPoints(l, s))\n .filter((i): i is Point => !!i);\n}\n\nexport function rectangleIntersectRectangle<\n Point extends LocalPoint | GlobalPoint,\n>(rectangle1: Rectangle<Point>, rectangle2: Rectangle<Point>): boolean {\n const [[minX1, minY1], [maxX1, maxY1]] = rectangle1;\n const [[minX2, minY2], [maxX2, maxY2]] = rectangle2;\n\n return minX1 < maxX2 && maxX1 > minX2 && minY1 < maxY2 && maxY1 > minY2;\n}\n", "import type { GlobalPoint, LocalPoint, Triangle } from \"./types\";\n\n// Types\n\n/**\n * Tests if a point lies inside a triangle. This function\n * will return FALSE if the point lies exactly on the sides\n * of the triangle.\n *\n * @param triangle The triangle to test the point for\n * @param p The point to test whether is in the triangle\n * @returns TRUE if the point is inside of the triangle\n */\nexport function triangleIncludesPoint<P extends GlobalPoint | LocalPoint>(\n [a, b, c]: Triangle<P>,\n p: P,\n): boolean {\n const triangleSign = (p1: P, p2: P, p3: P) =>\n (p1[0] - p3[0]) * (p2[1] - p3[1]) - (p2[0] - p3[0]) * (p1[1] - p3[1]);\n const d1 = triangleSign(p, a, b);\n const d2 = triangleSign(p, b, c);\n const d3 = triangleSign(p, c, a);\n\n const has_neg = d1 < 0 || d2 < 0 || d3 < 0;\n const has_pos = d1 > 0 || d2 > 0 || d3 > 0;\n\n return !(has_neg && has_pos);\n}\n"],
|
|
5
|
-
"mappings": ";AAAO,IAAM,YAAY;AAElB,IAAM,QAAQ,CAAC,OAAe,KAAa,QAAgB;AAChE,SAAO,KAAK,IAAI,KAAK,IAAI,OAAO,GAAG,GAAG,GAAG;AAC3C;AAEO,IAAM,QAAQ,CACnB,OACA,WACA,OAAmC,YAChC;AACH,QAAM,aAAa,KAAK,IA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AACrE,QAAM,KAAK,aAAa,GAAG,GAAG,CAAC;AAC/B,QAAM,KAAK,aAAa,GAAG,GAAG,CAAC;AAC/B,QAAM,KAAK,aAAa,GAAG,GAAG,CAAC;AAE/B,QAAM,UAAU,KAAK,KAAK,KAAK,KAAK,KAAK;AACzC,QAAM,UAAU,KAAK,KAAK,KAAK,KAAK,KAAK;AAEzC,SAAO,EAAE,WAAW;AACtB;",
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["export const PRECISION = 10e-5;\n\nexport const clamp = (value: number, min: number, max: number) => {\n return Math.min(Math.max(value, min), max);\n};\n\nexport const round = (\n value: number,\n precision: number,\n func: \"round\" | \"floor\" | \"ceil\" = \"round\",\n) => {\n const multiplier = Math.pow(10, precision);\n\n return Math[func]((value + Number.EPSILON) * multiplier) / multiplier;\n};\n\nexport const roundToStep = (\n value: number,\n step: number,\n func: \"round\" | \"floor\" | \"ceil\" = \"round\",\n): number => {\n const factor = 1 / step;\n return Math[func](value * factor) / factor;\n};\n\nexport const average = (a: number, b: number) => (a + b) / 2;\n\nexport const isFiniteNumber = (value: any): value is number => {\n return typeof value === \"number\" && Number.isFinite(value);\n};\n\nexport const isCloseTo = (a: number, b: number, precision = PRECISION) =>\n Math.abs(a - b) < precision;\n", "import { PRECISION } from \"./utils\";\n\nimport type {\n Degrees,\n GlobalPoint,\n LocalPoint,\n PolarCoords,\n Radians,\n} from \"./types\";\n\nexport const normalizeRadians = (angle: Radians): Radians =>\n angle < 0\n ? (((angle % (2 * Math.PI)) + 2 * Math.PI) as Radians)\n : ((angle % (2 * Math.PI)) as Radians);\n\n/**\n * Return the polar coordinates for the given cartesian point represented by\n * (x, y) for the center point 0,0 where the first number returned is the radius,\n * the second is the angle in radians.\n */\nexport const cartesian2Polar = <P extends GlobalPoint | LocalPoint>([\n x,\n y,\n]: P): PolarCoords => [\n Math.hypot(x, y),\n normalizeRadians(Math.atan2(y, x) as Radians),\n];\n\nexport function degreesToRadians(degrees: Degrees): Radians {\n return ((degrees * Math.PI) / 180) as Radians;\n}\n\nexport function radiansToDegrees(degrees: Radians): Degrees {\n return ((degrees * 180) / Math.PI) as Degrees;\n}\n\n/**\n * Determines if the provided angle is a right angle.\n *\n * @param rads The angle to measure\n * @returns TRUE if the provided angle is a right angle\n */\nexport function isRightAngleRads(rads: Radians): boolean {\n return Math.abs(Math.sin(2 * rads)) < PRECISION;\n}\n\nexport function radiansBetweenAngles(\n a: Radians,\n min: Radians,\n max: Radians,\n): boolean {\n a = normalizeRadians(a);\n min = normalizeRadians(min);\n max = normalizeRadians(max);\n\n if (min < max) {\n return a >= min && a <= max;\n }\n\n // The range wraps around the 0 angle\n return a >= min || a <= max;\n}\n\nexport function radiansDifference(a: Radians, b: Radians): Radians {\n a = normalizeRadians(a);\n b = normalizeRadians(b);\n\n let diff = a - b;\n\n if (diff < -Math.PI) {\n diff = (diff + 2 * Math.PI) as Radians;\n } else if (diff > Math.PI) {\n diff = (diff - 2 * Math.PI) as Radians;\n }\n\n return Math.abs(diff) as Radians;\n}\n", "import type { GlobalPoint, LocalPoint, Vector } from \"./types\";\n\n/**\n * Create a vector from the x and y coordiante elements.\n *\n * @param x The X aspect of the vector\n * @param y T Y aspect of the vector\n * @returns The constructed vector with X and Y as the coordinates\n */\nexport function vector(\n x: number,\n y: number,\n originX: number = 0,\n originY: number = 0,\n): Vector {\n return [x - originX, y - originY] as Vector;\n}\n\n/**\n * Turn a point into a vector with the origin point.\n *\n * @param p The point to turn into a vector\n * @param origin The origin point in a given coordiante system\n * @param threshold The threshold to consider the vector as 'undefined'\n * @param defaultValue The default value to return if the vector is 'undefined'\n * @returns The created vector from the point and the origin or default\n */\nexport function vectorFromPoint<Point extends GlobalPoint | LocalPoint>(\n p: Point,\n origin: Point = [0, 0] as Point,\n threshold?: number,\n defaultValue: Vector = [0, 1] as Vector,\n): Vector {\n const vec = vector(p[0] - origin[0], p[1] - origin[1]);\n\n if (threshold && vectorMagnitudeSq(vec) < threshold * threshold) {\n return defaultValue;\n }\n\n return vec;\n}\n\n/**\n * Cross product is a binary operation on two vectors in 2D space.\n * It results in a vector that is perpendicular to both vectors.\n *\n * @param a One of the vectors to use for the directed area calculation\n * @param b The other vector to use for the directed area calculation\n * @returns The directed area value for the two vectos\n */\nexport function vectorCross(a: Vector, b: Vector): number {\n return a[0] * b[1] - b[0] * a[1];\n}\n\n/**\n * Dot product is defined as the sum of the products of the\n * two vectors.\n *\n * @param a One of the vectors for which the sum of products is calculated\n * @param b The other vector for which the sum of products is calculated\n * @returns The sum of products of the two vectors\n */\nexport function vectorDot(a: Vector, b: Vector) {\n return a[0] * b[0] + a[1] * b[1];\n}\n\n/**\n * Determines if the value has the shape of a Vector.\n *\n * @param v The value to test\n * @returns TRUE if the value has the shape and components of a Vectors\n */\nexport function isVector(v: unknown): v is Vector {\n return (\n Array.isArray(v) &&\n v.length === 2 &&\n typeof v[0] === \"number\" &&\n !isNaN(v[0]) &&\n typeof v[1] === \"number\" &&\n !isNaN(v[1])\n );\n}\n\n/**\n * Add two vectors by adding their coordinates.\n *\n * @param a One of the vectors to add\n * @param b The other vector to add\n * @returns The sum vector of the two provided vectors\n */\nexport function vectorAdd(a: Readonly<Vector>, b: Readonly<Vector>): Vector {\n return [a[0] + b[0], a[1] + b[1]] as Vector;\n}\n\n/**\n * Add two vectors by adding their coordinates.\n *\n * @param start One of the vectors to add\n * @param end The other vector to add\n * @returns The sum vector of the two provided vectors\n */\nexport function vectorSubtract(\n start: Readonly<Vector>,\n end: Readonly<Vector>,\n): Vector {\n return [start[0] - end[0], start[1] - end[1]] as Vector;\n}\n\n/**\n * Scale vector by a scalar.\n *\n * @param v The vector to scale\n * @param scalar The scalar to multiply the vector components with\n * @returns The new scaled vector\n */\nexport function vectorScale(v: Vector, scalar: number): Vector {\n return vector(v[0] * scalar, v[1] * scalar);\n}\n\n/**\n * Calculates the sqare magnitude of a vector. Use this if you compare\n * magnitudes as it saves you an SQRT.\n *\n * @param v The vector to measure\n * @returns The scalar squared magnitude of the vector\n */\nexport function vectorMagnitudeSq(v: Vector) {\n return v[0] * v[0] + v[1] * v[1];\n}\n\n/**\n * Calculates the magnitude of a vector.\n *\n * @param v The vector to measure\n * @returns The scalar magnitude of the vector\n */\nexport function vectorMagnitude(v: Vector) {\n return Math.sqrt(vectorMagnitudeSq(v));\n}\n\n/**\n * Normalize the vector (i.e. make the vector magnitue equal 1).\n *\n * @param v The vector to normalize\n * @returns The new normalized vector\n */\nexport const vectorNormalize = (v: Vector): Vector => {\n const m = vectorMagnitude(v);\n\n if (m === 0) {\n return vector(0, 0);\n }\n\n return vector(v[0] / m, v[1] / m);\n};\n\n/**\n * Calculate the right-hand normal of the vector.\n */\nexport const vectorNormal = (v: Vector): Vector => vector(v[1], -v[0]);\n", "import { degreesToRadians } from \"./angle\";\nimport { PRECISION } from \"./utils\";\nimport { vectorFromPoint, vectorScale } from \"./vector\";\n\nimport type {\n LocalPoint,\n GlobalPoint,\n Radians,\n Degrees,\n Vector,\n} from \"./types\";\n\n/**\n * Create a properly typed Point instance from the X and Y coordinates.\n *\n * @param x The X coordinate\n * @param y The Y coordinate\n * @returns The branded and created point\n */\nexport function pointFrom<Point extends GlobalPoint | LocalPoint>(\n x: number,\n y: number,\n): Point {\n return [x, y] as Point;\n}\n\n/**\n * Converts and remaps an array containing a pair of numbers to Point.\n *\n * @param numberArray The number array to check and to convert to Point\n * @returns The point instance\n */\nexport function pointFromArray<Point extends GlobalPoint | LocalPoint>(\n numberArray: number[],\n): Point | undefined {\n return numberArray.length === 2\n ? pointFrom<Point>(numberArray[0], numberArray[1])\n : undefined;\n}\n\n/**\n * Converts and remaps a pair of numbers to Point.\n *\n * @param pair A number pair to convert to Point\n * @returns The point instance\n */\nexport function pointFromPair<Point extends GlobalPoint | LocalPoint>(\n pair: [number, number],\n): Point {\n return pair as Point;\n}\n\n/**\n * Convert a vector to a point.\n *\n * @param v The vector to convert\n * @returns The point the vector points at with origin 0,0\n */\nexport function pointFromVector<P extends GlobalPoint | LocalPoint>(\n v: Vector,\n offset: P = pointFrom(0, 0),\n): P {\n return pointFrom<P>(offset[0] + v[0], offset[1] + v[1]);\n}\n\n/**\n * Checks if the provided value has the shape of a Point.\n *\n * @param p The value to attempt verification on\n * @returns TRUE if the provided value has the shape of a local or global point\n */\nexport function isPoint(p: unknown): p is LocalPoint | GlobalPoint {\n return (\n Array.isArray(p) &&\n p.length === 2 &&\n typeof p[0] === \"number\" &&\n !isNaN(p[0]) &&\n typeof p[1] === \"number\" &&\n !isNaN(p[1])\n );\n}\n\n/**\n * Compare two points coordinate-by-coordinate and if\n * they are closer than INVERSE_PRECISION it returns TRUE.\n *\n * @param a Point The first point to compare\n * @param b Point The second point to compare\n * @returns TRUE if the points are sufficiently close to each other\n */\nexport function pointsEqual<Point extends GlobalPoint | LocalPoint>(\n a: Point,\n b: Point,\n tolerance: number = PRECISION,\n): boolean {\n const abs = Math.abs;\n return abs(a[0] - b[0]) < tolerance && abs(a[1] - b[1]) < tolerance;\n}\n\n/**\n * Rotate a point by [angle] radians.\n *\n * @param point The point to rotate\n * @param center The point to rotate around, the center point\n * @param angle The radians to rotate the point by\n * @returns The rotated point\n */\nexport function pointRotateRads<Point extends GlobalPoint | LocalPoint>(\n [x, y]: Point,\n [cx, cy]: Point,\n angle: Radians,\n): Point {\n return pointFrom(\n (x - cx) * Math.cos(angle) - (y - cy) * Math.sin(angle) + cx,\n (x - cx) * Math.sin(angle) + (y - cy) * Math.cos(angle) + cy,\n );\n}\n\n/**\n * Rotate a point by [angle] degree.\n *\n * @param point The point to rotate\n * @param center The point to rotate around, the center point\n * @param angle The degree to rotate the point by\n * @returns The rotated point\n */\nexport function pointRotateDegs<Point extends GlobalPoint | LocalPoint>(\n point: Point,\n center: Point,\n angle: Degrees,\n): Point {\n return pointRotateRads(point, center, degreesToRadians(angle));\n}\n\n/**\n * Translate a point by a vector.\n *\n * WARNING: This is not for translating Excalidraw element points!\n * You need to account for rotation on base coordinates\n * on your own.\n * CONSIDER USING AN APPROPRIATE ELEMENT-AWARE TRANSLATE!\n *\n * @param p The point to apply the translation on\n * @param v The vector to translate by\n * @returns\n */\n// TODO 99% of use is translating between global and local coords, which need to be formalized\nexport function pointTranslate<\n From extends GlobalPoint | LocalPoint,\n To extends GlobalPoint | LocalPoint,\n>(p: From, v: Vector = [0, 0] as Vector): To {\n return pointFrom(p[0] + v[0], p[1] + v[1]);\n}\n\n/**\n * Find the center point at equal distance from both points.\n *\n * @param a One of the points to create the middle point for\n * @param b The other point to create the middle point for\n * @returns The middle point\n */\nexport function pointCenter<P extends LocalPoint | GlobalPoint>(a: P, b: P): P {\n return pointFrom((a[0] + b[0]) / 2, (a[1] + b[1]) / 2);\n}\n\n/**\n * Calculate the distance between two points.\n *\n * @param a First point\n * @param b Second point\n * @returns The euclidean distance between the two points.\n */\nexport function pointDistance<P extends LocalPoint | GlobalPoint>(\n a: P,\n b: P,\n): number {\n return Math.hypot(b[0] - a[0], b[1] - a[1]);\n}\n\n/**\n * Calculate the squared distance between two points.\n *\n * Note: Use this if you only compare distances, it saves a square root.\n *\n * @param a First point\n * @param b Second point\n * @returns The euclidean distance between the two points.\n */\nexport function pointDistanceSq<P extends LocalPoint | GlobalPoint>(\n a: P,\n b: P,\n): number {\n const xDiff = b[0] - a[0];\n const yDiff = b[1] - a[1];\n\n return xDiff * xDiff + yDiff * yDiff;\n}\n\n/**\n * Scale a point from a given origin by the multiplier.\n *\n * @param p The point to scale\n * @param mid The origin to scale from\n * @param multiplier The scaling factor\n * @returns\n */\nexport const pointScaleFromOrigin = <P extends GlobalPoint | LocalPoint>(\n p: P,\n mid: P,\n multiplier: number,\n) => pointTranslate(mid, vectorScale(vectorFromPoint(p, mid), multiplier));\n\n/**\n * Returns whether `q` lies inside the segment/rectangle defined by `p` and `r`.\n * This is an approximation to \"does `q` lie on a segment `pr`\" check.\n *\n * @param p The first point to compare against\n * @param q The actual point this function checks whether is in between\n * @param r The other point to compare against\n * @returns TRUE if q is indeed between p and r\n */\nexport const isPointWithinBounds = <P extends GlobalPoint | LocalPoint>(\n p: P,\n q: P,\n r: P,\n) => {\n return (\n q[0] <= Math.max(p[0], r[0]) &&\n q[0] >= Math.min(p[0], r[0]) &&\n q[1] <= Math.max(p[1], r[1]) &&\n q[1] >= Math.min(p[1], r[1])\n );\n};\n", "export const PRECISION = 10e-5;\n\n// Legendre-Gauss abscissae (x values) and weights for n=24\n// Refeerence: https://pomax.github.io/bezierinfo/legendre-gauss.html\nexport const LegendreGaussN24TValues = [\n -0.0640568928626056260850430826247450385909,\n 0.0640568928626056260850430826247450385909,\n -0.1911188674736163091586398207570696318404,\n 0.1911188674736163091586398207570696318404,\n -0.3150426796961633743867932913198102407864,\n 0.3150426796961633743867932913198102407864,\n -0.4337935076260451384870842319133497124524,\n 0.4337935076260451384870842319133497124524,\n -0.5454214713888395356583756172183723700107,\n 0.5454214713888395356583756172183723700107,\n -0.6480936519369755692524957869107476266696,\n 0.6480936519369755692524957869107476266696,\n -0.7401241915785543642438281030999784255232,\n 0.7401241915785543642438281030999784255232,\n -0.8200019859739029219539498726697452080761,\n 0.8200019859739029219539498726697452080761,\n -0.8864155270044010342131543419821967550873,\n 0.8864155270044010342131543419821967550873,\n -0.9382745520027327585236490017087214496548,\n 0.9382745520027327585236490017087214496548,\n -0.9747285559713094981983919930081690617411,\n 0.9747285559713094981983919930081690617411,\n -0.9951872199970213601799974097007368118745,\n 0.9951872199970213601799974097007368118745,\n];\n\nexport const LegendreGaussN24CValues = [\n 0.1279381953467521569740561652246953718517,\n 0.1279381953467521569740561652246953718517,\n 0.1258374563468282961213753825111836887264,\n 0.1258374563468282961213753825111836887264,\n 0.121670472927803391204463153476262425607,\n 0.121670472927803391204463153476262425607,\n 0.1155056680537256013533444839067835598622,\n 0.1155056680537256013533444839067835598622,\n 0.1074442701159656347825773424466062227946,\n 0.1074442701159656347825773424466062227946,\n 0.0976186521041138882698806644642471544279,\n 0.0976186521041138882698806644642471544279,\n 0.086190161531953275917185202983742667185,\n 0.086190161531953275917185202983742667185,\n 0.0733464814110803057340336152531165181193,\n 0.0733464814110803057340336152531165181193,\n 0.0592985849154367807463677585001085845412,\n 0.0592985849154367807463677585001085845412,\n 0.0442774388174198061686027482113382288593,\n 0.0442774388174198061686027482113382288593,\n 0.0285313886289336631813078159518782864491,\n 0.0285313886289336631813078159518782864491,\n 0.0123412297999871995468056670700372915759,\n 0.0123412297999871995468056670700372915759,\n];\n", "import { isPoint, pointDistance, pointFrom, pointFromVector } from \"./point\";\nimport { vector, vectorNormal, vectorNormalize, vectorScale } from \"./vector\";\nimport { LegendreGaussN24CValues, LegendreGaussN24TValues } from \"./constants\";\n\nimport type { Curve, GlobalPoint, LineSegment, LocalPoint } from \"./types\";\n\n/**\n *\n * @param a\n * @param b\n * @param c\n * @param d\n * @returns\n */\nexport function curve<Point extends GlobalPoint | LocalPoint>(\n a: Point,\n b: Point,\n c: Point,\n d: Point,\n) {\n return [a, b, c, d] as Curve<Point>;\n}\n\nfunction solveWithAnalyticalJacobian<Point extends GlobalPoint | LocalPoint>(\n curve: Curve<Point>,\n lineSegment: LineSegment<Point>,\n t0: number,\n s0: number,\n tolerance: number = 1e-3,\n iterLimit: number = 10,\n): number[] | null {\n let error = Infinity;\n let iter = 0;\n\n while (error >= tolerance) {\n if (iter >= iterLimit) {\n return null;\n }\n\n // Compute bezier point at parameter t0\n const bt = 1 - t0;\n const bt2 = bt * bt;\n const bt3 = bt2 * bt;\n const t0_2 = t0 * t0;\n const t0_3 = t0_2 * t0;\n\n const bezierX =\n bt3 * curve[0][0] +\n 3 * bt2 * t0 * curve[1][0] +\n 3 * bt * t0_2 * curve[2][0] +\n t0_3 * curve[3][0];\n const bezierY =\n bt3 * curve[0][1] +\n 3 * bt2 * t0 * curve[1][1] +\n 3 * bt * t0_2 * curve[2][1] +\n t0_3 * curve[3][1];\n\n // Compute line point at parameter s0\n const lineX =\n lineSegment[0][0] + s0 * (lineSegment[1][0] - lineSegment[0][0]);\n const lineY =\n lineSegment[0][1] + s0 * (lineSegment[1][1] - lineSegment[0][1]);\n\n // Function values\n const fx = bezierX - lineX;\n const fy = bezierY - lineY;\n\n error = Math.abs(fx) + Math.abs(fy);\n\n if (error < tolerance) {\n break;\n }\n\n // Analytical derivatives\n const dfx_dt =\n -3 * bt2 * curve[0][0] +\n 3 * bt2 * curve[1][0] -\n 6 * bt * t0 * curve[1][0] -\n 3 * t0_2 * curve[2][0] +\n 6 * bt * t0 * curve[2][0] +\n 3 * t0_2 * curve[3][0];\n\n const dfy_dt =\n -3 * bt2 * curve[0][1] +\n 3 * bt2 * curve[1][1] -\n 6 * bt * t0 * curve[1][1] -\n 3 * t0_2 * curve[2][1] +\n 6 * bt * t0 * curve[2][1] +\n 3 * t0_2 * curve[3][1];\n\n // Line derivatives\n const dfx_ds = -(lineSegment[1][0] - lineSegment[0][0]);\n const dfy_ds = -(lineSegment[1][1] - lineSegment[0][1]);\n\n // Jacobian determinant\n const det = dfx_dt * dfy_ds - dfx_ds * dfy_dt;\n\n if (Math.abs(det) < 1e-12) {\n return null;\n }\n\n // Newton step\n const invDet = 1 / det;\n const dt = invDet * (dfy_ds * -fx - dfx_ds * -fy);\n const ds = invDet * (-dfy_dt * -fx + dfx_dt * -fy);\n\n t0 += dt;\n s0 += ds;\n iter += 1;\n }\n\n return [t0, s0];\n}\n\nexport const bezierEquation = <Point extends GlobalPoint | LocalPoint>(\n c: Curve<Point>,\n t: number,\n) =>\n pointFrom<Point>(\n (1 - t) ** 3 * c[0][0] +\n 3 * (1 - t) ** 2 * t * c[1][0] +\n 3 * (1 - t) * t ** 2 * c[2][0] +\n t ** 3 * c[3][0],\n (1 - t) ** 3 * c[0][1] +\n 3 * (1 - t) ** 2 * t * c[1][1] +\n 3 * (1 - t) * t ** 2 * c[2][1] +\n t ** 3 * c[3][1],\n );\n\nconst initial_guesses: [number, number][] = [\n [0.5, 0],\n [0.2, 0],\n [0.8, 0],\n];\n\nconst calculate = <Point extends GlobalPoint | LocalPoint>(\n [t0, s0]: [number, number],\n l: LineSegment<Point>,\n c: Curve<Point>,\n) => {\n const solution = solveWithAnalyticalJacobian(c, l, t0, s0, 1e-2, 3);\n\n if (!solution) {\n return null;\n }\n\n const [t, s] = solution;\n\n if (t < 0 || t > 1 || s < 0 || s > 1) {\n return null;\n }\n\n return bezierEquation(c, t);\n};\n\n/**\n * Computes the intersection between a cubic spline and a line segment.\n */\nexport function curveIntersectLineSegment<\n Point extends GlobalPoint | LocalPoint,\n>(c: Curve<Point>, l: LineSegment<Point>): Point[] {\n let solution = calculate(initial_guesses[0], l, c);\n if (solution) {\n return [solution];\n }\n\n solution = calculate(initial_guesses[1], l, c);\n if (solution) {\n return [solution];\n }\n\n solution = calculate(initial_guesses[2], l, c);\n if (solution) {\n return [solution];\n }\n\n return [];\n}\n\n/**\n * Finds the closest point on the Bezier curve from another point\n *\n * @param x\n * @param y\n * @param P0\n * @param P1\n * @param P2\n * @param P3\n * @param tolerance\n * @param maxLevel\n * @returns\n */\nexport function curveClosestPoint<Point extends GlobalPoint | LocalPoint>(\n c: Curve<Point>,\n p: Point,\n tolerance: number = 1e-3,\n): Point | null {\n const localMinimum = (\n min: number,\n max: number,\n f: (t: number) => number,\n e: number = tolerance,\n ) => {\n let m = min;\n let n = max;\n let k;\n\n while (n - m > e) {\n k = (n + m) / 2;\n if (f(k - e) < f(k + e)) {\n n = k;\n } else {\n m = k;\n }\n }\n\n return k;\n };\n\n const maxSteps = 30;\n let closestStep = 0;\n for (let min = Infinity, step = 0; step < maxSteps; step++) {\n const d = pointDistance(p, bezierEquation(c, step / maxSteps));\n if (d < min) {\n min = d;\n closestStep = step;\n }\n }\n\n const t0 = Math.max((closestStep - 1) / maxSteps, 0);\n const t1 = Math.min((closestStep + 1) / maxSteps, 1);\n const solution = localMinimum(t0, t1, (t) =>\n pointDistance(p, bezierEquation(c, t)),\n );\n\n if (!solution) {\n return null;\n }\n\n return bezierEquation(c, solution);\n}\n\n/**\n * Determines the distance between a point and the closest point on the\n * Bezier curve.\n *\n * @param c The curve to test\n * @param p The point to measure from\n */\nexport function curvePointDistance<Point extends GlobalPoint | LocalPoint>(\n c: Curve<Point>,\n p: Point,\n) {\n const closest = curveClosestPoint(c, p);\n\n if (!closest) {\n return 0;\n }\n\n return pointDistance(p, closest);\n}\n\n/**\n * Determines if the parameter is a Curve\n */\nexport function isCurve<P extends GlobalPoint | LocalPoint>(\n v: unknown,\n): v is Curve<P> {\n return (\n Array.isArray(v) &&\n v.length === 4 &&\n isPoint(v[0]) &&\n isPoint(v[1]) &&\n isPoint(v[2]) &&\n isPoint(v[3])\n );\n}\n\nexport function curveTangent<Point extends GlobalPoint | LocalPoint>(\n [p0, p1, p2, p3]: Curve<Point>,\n t: number,\n) {\n return vector(\n -3 * (1 - t) * (1 - t) * p0[0] +\n 3 * (1 - t) * (1 - t) * p1[0] -\n 6 * t * (1 - t) * p1[0] -\n 3 * t * t * p2[0] +\n 6 * t * (1 - t) * p2[0] +\n 3 * t * t * p3[0],\n -3 * (1 - t) * (1 - t) * p0[1] +\n 3 * (1 - t) * (1 - t) * p1[1] -\n 6 * t * (1 - t) * p1[1] -\n 3 * t * t * p2[1] +\n 6 * t * (1 - t) * p2[1] +\n 3 * t * t * p3[1],\n );\n}\n\nexport function curveCatmullRomQuadraticApproxPoints(\n points: GlobalPoint[],\n tension = 0.5,\n) {\n if (points.length < 2) {\n return;\n }\n\n const pointSets: [GlobalPoint, GlobalPoint][] = [];\n for (let i = 0; i < points.length - 1; i++) {\n const p0 = points[i - 1 < 0 ? 0 : i - 1];\n const p1 = points[i];\n const p2 = points[i + 1 >= points.length ? points.length - 1 : i + 1];\n const cpX = p1[0] + ((p2[0] - p0[0]) * tension) / 2;\n const cpY = p1[1] + ((p2[1] - p0[1]) * tension) / 2;\n\n pointSets.push([\n pointFrom<GlobalPoint>(cpX, cpY),\n pointFrom<GlobalPoint>(p2[0], p2[1]),\n ]);\n }\n\n return pointSets;\n}\n\nexport function curveCatmullRomCubicApproxPoints<\n Point extends GlobalPoint | LocalPoint,\n>(points: Point[], tension = 0.5) {\n if (points.length < 2) {\n return;\n }\n\n const pointSets: Curve<Point>[] = [];\n for (let i = 0; i < points.length - 1; i++) {\n const p0 = points[i - 1 < 0 ? 0 : i - 1];\n const p1 = points[i];\n const p2 = points[i + 1 >= points.length ? points.length - 1 : i + 1];\n const p3 = points[i + 2 >= points.length ? points.length - 1 : i + 2];\n const tangent1 = [(p2[0] - p0[0]) * tension, (p2[1] - p0[1]) * tension];\n const tangent2 = [(p3[0] - p1[0]) * tension, (p3[1] - p1[1]) * tension];\n const cp1x = p1[0] + tangent1[0] / 3;\n const cp1y = p1[1] + tangent1[1] / 3;\n const cp2x = p2[0] - tangent2[0] / 3;\n const cp2y = p2[1] - tangent2[1] / 3;\n\n pointSets.push(\n curve(\n pointFrom(p1[0], p1[1]),\n pointFrom(cp1x, cp1y),\n pointFrom(cp2x, cp2y),\n pointFrom(p2[0], p2[1]),\n ),\n );\n }\n\n return pointSets;\n}\n\nexport function curveOffsetPoints(\n [p0, p1, p2, p3]: Curve<GlobalPoint>,\n offset: number,\n steps = 50,\n) {\n const offsetPoints = [];\n\n for (let i = 0; i <= steps; i++) {\n const t = i / steps;\n const c = curve(p0, p1, p2, p3);\n const point = bezierEquation(c, t);\n const tangent = vectorNormalize(curveTangent(c, t));\n const normal = vectorNormal(tangent);\n\n offsetPoints.push(pointFromVector(vectorScale(normal, offset), point));\n }\n\n return offsetPoints;\n}\n\nexport function offsetPointsForQuadraticBezier(\n p0: GlobalPoint,\n p1: GlobalPoint,\n p2: GlobalPoint,\n offsetDist: number,\n steps = 50,\n) {\n const offsetPoints = [];\n\n for (let i = 0; i <= steps; i++) {\n const t = i / steps;\n const t1 = 1 - t;\n const point = pointFrom<GlobalPoint>(\n t1 * t1 * p0[0] + 2 * t1 * t * p1[0] + t * t * p2[0],\n t1 * t1 * p0[1] + 2 * t1 * t * p1[1] + t * t * p2[1],\n );\n const tangentX = 2 * (1 - t) * (p1[0] - p0[0]) + 2 * t * (p2[0] - p1[0]);\n const tangentY = 2 * (1 - t) * (p1[1] - p0[1]) + 2 * t * (p2[1] - p1[1]);\n const tangent = vectorNormalize(vector(tangentX, tangentY));\n const normal = vectorNormal(tangent);\n\n offsetPoints.push(pointFromVector(vectorScale(normal, offsetDist), point));\n }\n\n return offsetPoints;\n}\n\n/**\n * Implementation based on Legendre-Gauss quadrature for more accurate arc\n * length calculation.\n *\n * Reference: https://pomax.github.io/bezierinfo/#arclength\n *\n * @param c The curve to calculate the length of\n * @returns The approximated length of the curve\n */\nexport function curveLength<P extends GlobalPoint | LocalPoint>(\n c: Curve<P>,\n): number {\n const z2 = 0.5;\n let sum = 0;\n\n for (let i = 0; i < 24; i++) {\n const t = z2 * LegendreGaussN24TValues[i] + z2;\n const derivativeVector = curveTangent(c, t);\n const magnitude = Math.sqrt(\n derivativeVector[0] * derivativeVector[0] +\n derivativeVector[1] * derivativeVector[1],\n );\n sum += LegendreGaussN24CValues[i] * magnitude;\n }\n\n return z2 * sum;\n}\n\n/**\n * Calculates the curve length from t=0 to t=parameter using the same\n * Legendre-Gauss quadrature method used in curveLength\n *\n * @param c The curve to calculate the partial length for\n * @param t The parameter value (0 to 1) to calculate length up to\n * @returns The length of the curve from beginning to parameter t\n */\nexport function curveLengthAtParameter<P extends GlobalPoint | LocalPoint>(\n c: Curve<P>,\n t: number,\n): number {\n if (t <= 0) {\n return 0;\n }\n if (t >= 1) {\n return curveLength(c);\n }\n\n // Scale and shift the integration interval from [0,t] to [-1,1]\n // which is what the Legendre-Gauss quadrature expects\n const z1 = t / 2;\n const z2 = t / 2;\n\n let sum = 0;\n\n for (let i = 0; i < 24; i++) {\n const parameter = z1 * LegendreGaussN24TValues[i] + z2;\n const derivativeVector = curveTangent(c, parameter);\n const magnitude = Math.sqrt(\n derivativeVector[0] * derivativeVector[0] +\n derivativeVector[1] * derivativeVector[1],\n );\n sum += LegendreGaussN24CValues[i] * magnitude;\n }\n\n return z1 * sum; // Scale the result back to the original interval\n}\n\n/**\n * Calculates the point at a specific percentage of a curve's total length\n * using binary search for improved efficiency and accuracy.\n *\n * @param c The curve to calculate point on\n * @param percent A value between 0 and 1 representing the percentage of the curve's length\n * @returns The point at the specified percentage of curve length\n */\nexport function curvePointAtLength<P extends GlobalPoint | LocalPoint>(\n c: Curve<P>,\n percent: number,\n): P {\n if (percent <= 0) {\n return bezierEquation(c, 0);\n }\n\n if (percent >= 1) {\n return bezierEquation(c, 1);\n }\n\n const totalLength = curveLength(c);\n const targetLength = totalLength * percent;\n\n // Binary search to find parameter t where length at t equals target length\n let tMin = 0;\n let tMax = 1;\n let t = percent; // Start with a reasonable guess (t = percent)\n let currentLength = 0;\n\n // Tolerance for length comparison and iteration limit to avoid infinite loops\n const tolerance = totalLength * 0.0001;\n const maxIterations = 20;\n\n for (let iteration = 0; iteration < maxIterations; iteration++) {\n currentLength = curveLengthAtParameter(c, t);\n const error = Math.abs(currentLength - targetLength);\n\n if (error < tolerance) {\n break;\n }\n\n if (currentLength < targetLength) {\n tMin = t;\n } else {\n tMax = t;\n }\n\n t = (tMin + tMax) / 2;\n }\n\n return bezierEquation(c, t);\n}\n", "import {\n pointFrom,\n pointDistance,\n pointFromVector,\n pointsEqual,\n} from \"./point\";\nimport { PRECISION } from \"./utils\";\nimport {\n vector,\n vectorAdd,\n vectorDot,\n vectorFromPoint,\n vectorScale,\n} from \"./vector\";\n\nimport type {\n Ellipse,\n GlobalPoint,\n Line,\n LineSegment,\n LocalPoint,\n} from \"./types\";\n\n/**\n * Construct an Ellipse object from the parameters\n *\n * @param center The center of the ellipse\n * @param angle The slanting of the ellipse in radians\n * @param halfWidth Half of the width of a non-slanted version of the ellipse\n * @param halfHeight Half of the height of a non-slanted version of the ellipse\n * @returns The constructed Ellipse object\n */\nexport function ellipse<Point extends GlobalPoint | LocalPoint>(\n center: Point,\n halfWidth: number,\n halfHeight: number,\n): Ellipse<Point> {\n return {\n center,\n halfWidth,\n halfHeight,\n } as Ellipse<Point>;\n}\n\n/**\n * Determines if a point is inside or on the ellipse outline\n *\n * @param p The point to test\n * @param ellipse The ellipse to compare against\n * @returns TRUE if the point is inside or on the outline of the ellipse\n */\nexport const ellipseIncludesPoint = <Point extends GlobalPoint | LocalPoint>(\n p: Point,\n ellipse: Ellipse<Point>,\n) => {\n const { center, halfWidth, halfHeight } = ellipse;\n const normalizedX = (p[0] - center[0]) / halfWidth;\n const normalizedY = (p[1] - center[1]) / halfHeight;\n\n return normalizedX * normalizedX + normalizedY * normalizedY <= 1;\n};\n\n/**\n * Tests whether a point lies on the outline of the ellipse within a given\n * tolerance\n *\n * @param point The point to test\n * @param ellipse The ellipse to compare against\n * @param threshold The distance to consider a point close enough to be \"on\" the outline\n * @returns TRUE if the point is on the ellise outline\n */\nexport const ellipseTouchesPoint = <Point extends GlobalPoint | LocalPoint>(\n point: Point,\n ellipse: Ellipse<Point>,\n threshold = PRECISION,\n) => {\n return ellipseDistanceFromPoint(point, ellipse) <= threshold;\n};\n\n/**\n * Determine the shortest euclidean distance from a point to the\n * outline of the ellipse\n *\n * @param p The point to consider\n * @param ellipse The ellipse to calculate the distance to\n * @returns The eucledian distance\n */\nexport const ellipseDistanceFromPoint = <\n Point extends GlobalPoint | LocalPoint,\n>(\n p: Point,\n ellipse: Ellipse<Point>,\n): number => {\n const { halfWidth, halfHeight, center } = ellipse;\n const a = halfWidth;\n const b = halfHeight;\n const translatedPoint = vectorAdd(\n vectorFromPoint(p),\n vectorScale(vectorFromPoint(center), -1),\n );\n\n const px = Math.abs(translatedPoint[0]);\n const py = Math.abs(translatedPoint[1]);\n\n let tx = 0.707;\n let ty = 0.707;\n\n for (let i = 0; i < 3; i++) {\n const x = a * tx;\n const y = b * ty;\n\n const ex = ((a * a - b * b) * tx ** 3) / a;\n const ey = ((b * b - a * a) * ty ** 3) / b;\n\n const rx = x - ex;\n const ry = y - ey;\n\n const qx = px - ex;\n const qy = py - ey;\n\n const r = Math.hypot(ry, rx);\n const q = Math.hypot(qy, qx);\n\n tx = Math.min(1, Math.max(0, ((qx * r) / q + ex) / a));\n ty = Math.min(1, Math.max(0, ((qy * r) / q + ey) / b));\n const t = Math.hypot(ty, tx);\n tx /= t;\n ty /= t;\n }\n\n const [minX, minY] = [\n a * tx * Math.sign(translatedPoint[0]),\n b * ty * Math.sign(translatedPoint[1]),\n ];\n\n return pointDistance(pointFromVector(translatedPoint), pointFrom(minX, minY));\n};\n\n/**\n * Calculate a maximum of two intercept points for a line going throug an\n * ellipse.\n */\nexport function ellipseSegmentInterceptPoints<\n Point extends GlobalPoint | LocalPoint,\n>(e: Readonly<Ellipse<Point>>, s: Readonly<LineSegment<Point>>): Point[] {\n const rx = e.halfWidth;\n const ry = e.halfHeight;\n\n const dir = vectorFromPoint(s[1], s[0]);\n const diff = vector(s[0][0] - e.center[0], s[0][1] - e.center[1]);\n const mDir = vector(dir[0] / (rx * rx), dir[1] / (ry * ry));\n const mDiff = vector(diff[0] / (rx * rx), diff[1] / (ry * ry));\n\n const a = vectorDot(dir, mDir);\n const b = vectorDot(dir, mDiff);\n const c = vectorDot(diff, mDiff) - 1.0;\n const d = b * b - a * c;\n\n const intersections: Point[] = [];\n\n if (d > 0) {\n const t_a = (-b - Math.sqrt(d)) / a;\n const t_b = (-b + Math.sqrt(d)) / a;\n\n if (0 <= t_a && t_a <= 1) {\n intersections.push(\n pointFrom(\n s[0][0] + (s[1][0] - s[0][0]) * t_a,\n s[0][1] + (s[1][1] - s[0][1]) * t_a,\n ),\n );\n }\n\n if (0 <= t_b && t_b <= 1) {\n intersections.push(\n pointFrom(\n s[0][0] + (s[1][0] - s[0][0]) * t_b,\n s[0][1] + (s[1][1] - s[0][1]) * t_b,\n ),\n );\n }\n } else if (d === 0) {\n const t = -b / a;\n if (0 <= t && t <= 1) {\n intersections.push(\n pointFrom(\n s[0][0] + (s[1][0] - s[0][0]) * t,\n s[0][1] + (s[1][1] - s[0][1]) * t,\n ),\n );\n }\n }\n\n return intersections;\n}\n\nexport function ellipseLineIntersectionPoints<\n Point extends GlobalPoint | LocalPoint,\n>(\n { center, halfWidth, halfHeight }: Ellipse<Point>,\n [g, h]: Line<Point>,\n): Point[] {\n const [cx, cy] = center;\n const x1 = g[0] - cx;\n const y1 = g[1] - cy;\n const x2 = h[0] - cx;\n const y2 = h[1] - cy;\n const a =\n Math.pow(x2 - x1, 2) / Math.pow(halfWidth, 2) +\n Math.pow(y2 - y1, 2) / Math.pow(halfHeight, 2);\n const b =\n 2 *\n ((x1 * (x2 - x1)) / Math.pow(halfWidth, 2) +\n (y1 * (y2 - y1)) / Math.pow(halfHeight, 2));\n const c =\n Math.pow(x1, 2) / Math.pow(halfWidth, 2) +\n Math.pow(y1, 2) / Math.pow(halfHeight, 2) -\n 1;\n const t1 = (-b + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);\n const t2 = (-b - Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);\n const candidates = [\n pointFrom<Point>(x1 + t1 * (x2 - x1) + cx, y1 + t1 * (y2 - y1) + cy),\n pointFrom<Point>(x1 + t2 * (x2 - x1) + cx, y1 + t2 * (y2 - y1) + cy),\n ].filter((p) => !isNaN(p[0]) && !isNaN(p[1]));\n\n if (candidates.length === 2 && pointsEqual(candidates[0], candidates[1])) {\n return [candidates[0]];\n }\n\n return candidates;\n}\n", "import { pointFrom } from \"./point\";\n\nimport type { GlobalPoint, Line, LocalPoint } from \"./types\";\n\n/**\n * Create a line from two points.\n *\n * @param points The two points lying on the line\n * @returns The line on which the points lie\n */\nexport function line<P extends GlobalPoint | LocalPoint>(a: P, b: P): Line<P> {\n return [a, b] as Line<P>;\n}\n\n/**\n * Determines the intersection point (unless the lines are parallel) of two\n * lines\n *\n * @param a\n * @param b\n * @returns\n */\nexport function linesIntersectAt<Point extends GlobalPoint | LocalPoint>(\n a: Line<Point>,\n b: Line<Point>,\n): Point | null {\n const A1 = a[1][1] - a[0][1];\n const B1 = a[0][0] - a[1][0];\n const A2 = b[1][1] - b[0][1];\n const B2 = b[0][0] - b[1][0];\n const D = A1 * B2 - A2 * B1;\n if (D !== 0) {\n const C1 = A1 * a[0][0] + B1 * a[0][1];\n const C2 = A2 * b[0][0] + B2 * b[0][1];\n return pointFrom<Point>((C1 * B2 - C2 * B1) / D, (A1 * C2 - A2 * C1) / D);\n }\n\n return null;\n}\n", "import { line, linesIntersectAt } from \"./line\";\nimport {\n isPoint,\n pointCenter,\n pointFromVector,\n pointRotateRads,\n} from \"./point\";\nimport { PRECISION } from \"./utils\";\nimport {\n vectorAdd,\n vectorCross,\n vectorFromPoint,\n vectorScale,\n vectorSubtract,\n} from \"./vector\";\n\nimport type { GlobalPoint, LineSegment, LocalPoint, Radians } from \"./types\";\n\n/**\n * Create a line segment from two points.\n *\n * @param points The two points delimiting the line segment on each end\n * @returns The line segment delineated by the points\n */\nexport function lineSegment<P extends GlobalPoint | LocalPoint>(\n a: P,\n b: P,\n): LineSegment<P> {\n return [a, b] as LineSegment<P>;\n}\n\n/**\n *\n * @param segment\n * @returns\n */\nexport const isLineSegment = <Point extends GlobalPoint | LocalPoint>(\n segment: unknown,\n): segment is LineSegment<Point> =>\n Array.isArray(segment) &&\n segment.length === 2 &&\n isPoint(segment[0]) &&\n isPoint(segment[0]);\n\n/**\n * Return the coordinates resulting from rotating the given line about an origin by an angle in radians\n * note that when the origin is not given, the midpoint of the given line is used as the origin.\n *\n * @param l\n * @param angle\n * @param origin\n * @returns\n */\nexport const lineSegmentRotate = <Point extends LocalPoint | GlobalPoint>(\n l: LineSegment<Point>,\n angle: Radians,\n origin?: Point,\n): LineSegment<Point> => {\n return lineSegment(\n pointRotateRads(l[0], origin || pointCenter(l[0], l[1]), angle),\n pointRotateRads(l[1], origin || pointCenter(l[0], l[1]), angle),\n );\n};\n\n/**\n * Calculates the point two line segments with a definite start and end point\n * intersect at.\n */\nexport const segmentsIntersectAt = <Point extends GlobalPoint | LocalPoint>(\n a: Readonly<LineSegment<Point>>,\n b: Readonly<LineSegment<Point>>,\n): Point | null => {\n const a0 = vectorFromPoint(a[0]);\n const a1 = vectorFromPoint(a[1]);\n const b0 = vectorFromPoint(b[0]);\n const b1 = vectorFromPoint(b[1]);\n const r = vectorSubtract(a1, a0);\n const s = vectorSubtract(b1, b0);\n const denominator = vectorCross(r, s);\n\n if (denominator === 0) {\n return null;\n }\n\n const i = vectorSubtract(vectorFromPoint(b[0]), vectorFromPoint(a[0]));\n const u = vectorCross(i, r) / denominator;\n const t = vectorCross(i, s) / denominator;\n\n if (u === 0) {\n return null;\n }\n\n const p = vectorAdd(a0, vectorScale(r, t));\n\n if (t >= 0 && t < 1 && u >= 0 && u < 1) {\n return pointFromVector<Point>(p);\n }\n\n return null;\n};\n\nexport const pointOnLineSegment = <Point extends LocalPoint | GlobalPoint>(\n point: Point,\n line: LineSegment<Point>,\n threshold = PRECISION,\n) => {\n const distance = distanceToLineSegment(point, line);\n\n if (distance === 0) {\n return true;\n }\n\n return distance < threshold;\n};\n\nexport const distanceToLineSegment = <Point extends LocalPoint | GlobalPoint>(\n point: Point,\n line: LineSegment<Point>,\n) => {\n const [x, y] = point;\n const [[x1, y1], [x2, y2]] = line;\n\n const A = x - x1;\n const B = y - y1;\n const C = x2 - x1;\n const D = y2 - y1;\n\n const dot = A * C + B * D;\n const len_sq = C * C + D * D;\n let param = -1;\n if (len_sq !== 0) {\n param = dot / len_sq;\n }\n\n let xx;\n let yy;\n\n if (param < 0) {\n xx = x1;\n yy = y1;\n } else if (param > 1) {\n xx = x2;\n yy = y2;\n } else {\n xx = x1 + param * C;\n yy = y1 + param * D;\n }\n\n const dx = x - xx;\n const dy = y - yy;\n return Math.sqrt(dx * dx + dy * dy);\n};\n\n/**\n * Returns the intersection point of a segment and a line\n *\n * @param l\n * @param s\n * @returns\n */\nexport function lineSegmentIntersectionPoints<\n Point extends GlobalPoint | LocalPoint,\n>(\n l: LineSegment<Point>,\n s: LineSegment<Point>,\n threshold?: number,\n): Point | null {\n const candidate = linesIntersectAt(line(l[0], l[1]), line(s[0], s[1]));\n\n if (\n !candidate ||\n !pointOnLineSegment(candidate, s, threshold) ||\n !pointOnLineSegment(candidate, l, threshold)\n ) {\n return null;\n }\n\n return candidate;\n}\n\nexport function lineSegmentsDistance<Point extends GlobalPoint | LocalPoint>(\n s1: LineSegment<Point>,\n s2: LineSegment<Point>,\n): number {\n if (lineSegmentIntersectionPoints(s1, s2)) {\n return 0;\n }\n\n return Math.min(\n distanceToLineSegment(s1[0], s2),\n distanceToLineSegment(s1[1], s2),\n distanceToLineSegment(s2[0], s1),\n distanceToLineSegment(s2[1], s1),\n );\n}\n", "import { pointsEqual } from \"./point\";\nimport { lineSegment, pointOnLineSegment } from \"./segment\";\nimport { PRECISION } from \"./utils\";\n\nimport type { GlobalPoint, LocalPoint, Polygon } from \"./types\";\n\nexport function polygon<Point extends GlobalPoint | LocalPoint>(\n ...points: Point[]\n) {\n return polygonClose(points) as Polygon<Point>;\n}\n\nexport function polygonFromPoints<Point extends GlobalPoint | LocalPoint>(\n points: Point[],\n) {\n return polygonClose(points) as Polygon<Point>;\n}\n\nexport const polygonIncludesPoint = <Point extends LocalPoint | GlobalPoint>(\n point: Point,\n polygon: Polygon<Point>,\n) => {\n const x = point[0];\n const y = point[1];\n let inside = false;\n\n for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {\n const xi = polygon[i][0];\n const yi = polygon[i][1];\n const xj = polygon[j][0];\n const yj = polygon[j][1];\n\n if (\n ((yi > y && yj <= y) || (yi <= y && yj > y)) &&\n x < ((xj - xi) * (y - yi)) / (yj - yi) + xi\n ) {\n inside = !inside;\n }\n }\n\n return inside;\n};\n\nexport const polygonIncludesPointNonZero = <Point extends [number, number]>(\n point: Point,\n polygon: Point[],\n): boolean => {\n const [x, y] = point;\n let windingNumber = 0;\n\n for (let i = 0; i < polygon.length; i++) {\n const j = (i + 1) % polygon.length;\n const [xi, yi] = polygon[i];\n const [xj, yj] = polygon[j];\n\n if (yi <= y) {\n if (yj > y) {\n if ((xj - xi) * (y - yi) - (x - xi) * (yj - yi) > 0) {\n windingNumber++;\n }\n }\n } else if (yj <= y) {\n if ((xj - xi) * (y - yi) - (x - xi) * (yj - yi) < 0) {\n windingNumber--;\n }\n }\n }\n\n return windingNumber !== 0;\n};\n\nexport const pointOnPolygon = <Point extends LocalPoint | GlobalPoint>(\n p: Point,\n poly: Polygon<Point>,\n threshold = PRECISION,\n) => {\n let on = false;\n\n for (let i = 0, l = poly.length - 1; i < l; i++) {\n if (pointOnLineSegment(p, lineSegment(poly[i], poly[i + 1]), threshold)) {\n on = true;\n break;\n }\n }\n\n return on;\n};\n\nfunction polygonClose<Point extends LocalPoint | GlobalPoint>(\n polygon: Point[],\n) {\n return polygonIsClosed(polygon)\n ? polygon\n : ([...polygon, polygon[0]] as Polygon<Point>);\n}\n\nfunction polygonIsClosed<Point extends LocalPoint | GlobalPoint>(\n polygon: Point[],\n) {\n return pointsEqual(polygon[0], polygon[polygon.length - 1]);\n}\n", "import { toBrandedType } from \"@excalidraw/common\";\n\nimport type { InclusiveRange } from \"./types\";\n\n/**\n * Create an inclusive range from the two numbers provided.\n *\n * @param start Start of the range\n * @param end End of the range\n * @returns\n */\nexport function rangeInclusive(start: number, end: number): InclusiveRange {\n return toBrandedType<InclusiveRange>([start, end]);\n}\n\n/**\n * Turn a number pair into an inclusive range.\n *\n * @param pair The number pair to convert to an inclusive range\n * @returns The new inclusive range\n */\nexport function rangeInclusiveFromPair(pair: [start: number, end: number]) {\n return toBrandedType<InclusiveRange>(pair);\n}\n\n/**\n * Given two ranges, return if the two ranges overlap with each other e.g.\n * [1, 3] overlaps with [2, 4] while [1, 3] does not overlap with [4, 5].\n *\n * @param param0 One of the ranges to compare\n * @param param1 The other range to compare against\n * @returns TRUE if the ranges overlap\n */\nexport const rangesOverlap = (\n [a0, a1]: InclusiveRange,\n [b0, b1]: InclusiveRange,\n): boolean => {\n if (a0 <= b0) {\n return a1 >= b0;\n }\n\n if (a0 >= b0) {\n return b1 >= a0;\n }\n\n return false;\n};\n\n/**\n * Given two ranges,return ther intersection of the two ranges if any e.g. the\n * intersection of [1, 3] and [2, 4] is [2, 3].\n *\n * @param param0 The first range to compare\n * @param param1 The second range to compare\n * @returns The inclusive range intersection or NULL if no intersection\n */\nexport const rangeIntersection = (\n [a0, a1]: InclusiveRange,\n [b0, b1]: InclusiveRange,\n): InclusiveRange | null => {\n const rangeStart = Math.max(a0, b0);\n const rangeEnd = Math.min(a1, b1);\n\n if (rangeStart <= rangeEnd) {\n return toBrandedType<InclusiveRange>([rangeStart, rangeEnd]);\n }\n\n return null;\n};\n\n/**\n * Determine if a value is inside a range.\n *\n * @param value The value to check\n * @param range The range\n * @returns\n */\nexport const rangeIncludesValue = (\n value: number,\n [min, max]: InclusiveRange,\n): boolean => {\n return value >= min && value <= max;\n};\n", "import { pointFrom } from \"./point\";\nimport { lineSegment, lineSegmentIntersectionPoints } from \"./segment\";\n\nimport type { GlobalPoint, LineSegment, LocalPoint, Rectangle } from \"./types\";\n\nexport function rectangle<P extends GlobalPoint | LocalPoint>(\n topLeft: P,\n bottomRight: P,\n): Rectangle<P> {\n return [topLeft, bottomRight] as Rectangle<P>;\n}\n\nexport function rectangleFromNumberSequence<\n Point extends LocalPoint | GlobalPoint,\n>(minX: number, minY: number, maxX: number, maxY: number) {\n return rectangle(pointFrom<Point>(minX, minY), pointFrom<Point>(maxX, maxY));\n}\n\nexport function rectangleIntersectLineSegment<\n Point extends LocalPoint | GlobalPoint,\n>(r: Rectangle<Point>, l: LineSegment<Point>): Point[] {\n return [\n lineSegment(r[0], pointFrom(r[1][0], r[0][1])),\n lineSegment(pointFrom(r[1][0], r[0][1]), r[1]),\n lineSegment(r[1], pointFrom(r[0][0], r[1][1])),\n lineSegment(pointFrom(r[0][0], r[1][1]), r[0]),\n ]\n .map((s) => lineSegmentIntersectionPoints(l, s))\n .filter((i): i is Point => !!i);\n}\n\nexport function rectangleIntersectRectangle<\n Point extends LocalPoint | GlobalPoint,\n>(rectangle1: Rectangle<Point>, rectangle2: Rectangle<Point>): boolean {\n const [[minX1, minY1], [maxX1, maxY1]] = rectangle1;\n const [[minX2, minY2], [maxX2, maxY2]] = rectangle2;\n\n return minX1 < maxX2 && maxX1 > minX2 && minY1 < maxY2 && maxY1 > minY2;\n}\n", "import type { GlobalPoint, LocalPoint, Triangle } from \"./types\";\n\n// Types\n\n/**\n * Tests if a point lies inside a triangle. This function\n * will return FALSE if the point lies exactly on the sides\n * of the triangle.\n *\n * @param triangle The triangle to test the point for\n * @param p The point to test whether is in the triangle\n * @returns TRUE if the point is inside of the triangle\n */\nexport function triangleIncludesPoint<P extends GlobalPoint | LocalPoint>(\n [a, b, c]: Triangle<P>,\n p: P,\n): boolean {\n const triangleSign = (p1: P, p2: P, p3: P) =>\n (p1[0] - p3[0]) * (p2[1] - p3[1]) - (p2[0] - p3[0]) * (p1[1] - p3[1]);\n const d1 = triangleSign(p, a, b);\n const d2 = triangleSign(p, b, c);\n const d3 = triangleSign(p, c, a);\n\n const has_neg = d1 < 0 || d2 < 0 || d3 < 0;\n const has_pos = d1 > 0 || d2 > 0 || d3 > 0;\n\n return !(has_neg && has_pos);\n}\n"],
|
|
5
|
+
"mappings": ";AAAO,IAAM,YAAY;AAElB,IAAM,QAAQ,CAAC,OAAe,KAAa,QAAgB;AAChE,SAAO,KAAK,IAAI,KAAK,IAAI,OAAO,GAAG,GAAG,GAAG;AAC3C;AAEO,IAAM,QAAQ,CACnB,OACA,WACA,OAAmC,YAChC;AACH,QAAM,aAAa,KAAK,IAAI,IAAI,SAAS;AAEzC,SAAO,KAAK,IAAI,GAAG,QAAQ,OAAO,WAAW,UAAU,IAAI;AAC7D;AAEO,IAAM,cAAc,CACzB,OACA,MACA,OAAmC,YACxB;AACX,QAAM,SAAS,IAAI;AACnB,SAAO,KAAK,IAAI,EAAE,QAAQ,MAAM,IAAI;AACtC;AAEO,IAAM,UAAU,CAAC,GAAW,OAAe,IAAI,KAAK;AAEpD,IAAM,iBAAiB,CAAC,UAAgC;AAC7D,SAAO,OAAO,UAAU,YAAY,OAAO,SAAS,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GAAG,CAAC;AAC/B,QAAM,KAAK,aAAa,GAAG,GAAG,CAAC;AAE/B,QAAM,UAAU,KAAK,KAAK,KAAK,KAAK,KAAK;AACzC,QAAM,UAAU,KAAK,KAAK,KAAK,KAAK,KAAK;AAEzC,SAAO,EAAE,WAAW;AACtB;",
|
|
6
|
+
"names": ["curve", "lineSegment", "ellipse", "line", "polygon"]
|
|
7
7
|
}
|
package/dist/prod/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var y=1e-4,ft=(t,n,o)=>Math.min(Math.max(t,n),o),dt=(t,n,o="round")=>{let e=Math.pow(10,n);return Math[o]((t+Number.EPSILON)*e)/e},gt=(t,n,o="round")=>{let e=1/n;return Math[o](t*e)/e},ht=(t,n)=>(t+n)/2,Lt=t=>typeof t=="number"&&Number.isFinite(t),yt=(t,n,o=1e-4)=>Math.abs(t-n)<o;var C=t=>t<0?t%(2*Math.PI)+2*Math.PI:t%(2*Math.PI),St=([t,n])=>[Math.hypot(t,n),C(Math.atan2(n,t))];function K(t){return t*Math.PI/180}function vt(t){return t*180/Math.PI}function It(t){return Math.abs(Math.sin(2*t))<1e-4}function Vt(t,n,o){return t=C(t),n=C(n),o=C(o),n<o?t>=n&&t<=o:t>=n||t<=o}function Ct(t,n){t=C(t),n=C(n);let o=t-n;return o<-Math.PI?o=o+2*Math.PI:o>Math.PI&&(o=o-2*Math.PI),Math.abs(o)}function L(t,n,o=0,e=0){return[t-o,n-e]}function h(t,n=[0,0],o,e=[0,1]){let r=L(t[0]-n[0],t[1]-n[1]);return o&&U(r)<o*o?e:r}function N(t,n){return t[0]*n[1]-n[0]*t[1]}function E(t,n){return t[0]*n[0]+t[1]*n[1]}function Et(t){return Array.isArray(t)&&t.length===2&&typeof t[0]=="number"&&!isNaN(t[0])&&typeof t[1]=="number"&&!isNaN(t[1])}function F(t,n){return[t[0]+n[0],t[1]+n[1]]}function D(t,n){return[t[0]-n[0],t[1]-n[1]]}function M(t,n){return L(t[0]*n,t[1]*n)}function U(t){return t[0]*t[0]+t[1]*t[1]}function ct(t){return Math.sqrt(U(t))}var T=t=>{let n=ct(t);return n===0?L(0,0):L(t[0]/n,t[1]/n)},O=t=>L(t[1],-t[0]);function p(t,n){return[t,n]}function Tt(t){return t.length===2?p(t[0],t[1]):void 0}function Ot(t){return t}function I(t,n=p(0,0)){return p(n[0]+t[0],n[1]+t[1])}function S(t){return Array.isArray(t)&&t.length===2&&typeof t[0]=="number"&&!isNaN(t[0])&&typeof t[1]=="number"&&!isNaN(t[1])}function A(t,n,o=1e-4){let e=Math.abs;return e(t[0]-n[0])<o&&e(t[1]-n[1])<o}function w([t,n],[o,e],r){return p((t-o)*Math.cos(r)-(n-e)*Math.sin(r)+o,(t-o)*Math.sin(r)+(n-e)*Math.cos(r)+e)}function zt(t,n,o){return w(t,n,K(o))}function lt(t,n=[0,0]){return p(t[0]+n[0],t[1]+n[1])}function z(t,n){return p((t[0]+n[0])/2,(t[1]+n[1])/2)}function _(t,n){return Math.hypot(n[0]-t[0],n[1]-t[1])}function Xt(t,n){let o=n[0]-t[0],e=n[1]-t[1];return o*o+e*e}var Yt=(t,n,o)=>lt(n,M(h(t,n),o)),jt=(t,n,o)=>n[0]<=Math.max(t[0],o[0])&&n[0]>=Math.min(t[0],o[0])&&n[1]<=Math.max(t[1],o[1])&&n[1]>=Math.min(t[1],o[1]);var X=[-.06405689286260563,.06405689286260563,-.1911188674736163,.1911188674736163,-.3150426796961634,.3150426796961634,-.4337935076260451,.4337935076260451,-.5454214713888396,.5454214713888396,-.6480936519369755,.6480936519369755,-.7401241915785544,.7401241915785544,-.820001985973903,.820001985973903,-.8864155270044011,.8864155270044011,-.9382745520027328,.9382745520027328,-.9747285559713095,.9747285559713095,-.9951872199970213,.9951872199970213],Y=[.12793819534675216,.12793819534675216,.1258374563468283,.1258374563468283,.12167047292780339,.12167047292780339,.1155056680537256,.1155056680537256,.10744427011596563,.10744427011596563,.09761865210411388,.09761865210411388,.08619016153195327,.08619016153195327,.0733464814110803,.0733464814110803,.05929858491543678,.05929858491543678,.04427743881741981,.04427743881741981,.028531388628933663,.028531388628933663,.0123412297999872,.0123412297999872];function tt(t,n,o,e){return[t,n,o,e]}function $(t,n,o,e=1e-6){return[(t(n+e,o)-t(n-e,o))/(2*e),(t(n,o+e)-t(n,o-e))/(2*e)]}function st(t,n,o,e=.001,r=10){let i=1/0,a=0;for(;i>=e;){if(a>=r)return null;let c=t(n,o),l=[$((f,d)=>t(f,d)[0],n,o),$((f,d)=>t(f,d)[1],n,o)],P=[[-c[0]],[-c[1]]],s=l[0][0]*l[1][1]-l[0][1]*l[1][0];if(s===0)return null;let u=[[l[1][1]/s,-l[0][1]/s],[-l[1][0]/s,l[0][0]/s]],m=[[u[0][0]*P[0][0]+u[0][1]*P[1][0]],[u[1][0]*P[0][0]+u[1][1]*P[1][0]]];n=n+m[0][0],o=o+m[1][0];let[x,b]=t(n,o);i=Math.max(Math.abs(x),Math.abs(b)),a+=1}return[n,o]}var R=(t,n)=>p((1-n)**3*t[0][0]+3*(1-n)**2*n*t[1][0]+3*(1-n)*n**2*t[2][0]+n**3*t[3][0],(1-n)**3*t[0][1]+3*(1-n)**2*n*t[1][1]+3*(1-n)*n**2*t[2][1]+n**3*t[3][1]);function Kt(t,n){let o=a=>p(n[0][0]+a*(n[1][0]-n[0][0]),n[0][1]+a*(n[1][1]-n[0][1])),e=[[.5,0],[.2,0],[.8,0]],r=([a,c])=>{let l=st((u,m)=>{let x=R(t,u),b=o(m);return[x[0]-b[0],x[1]-b[1]]},a,c);if(!l)return null;let[P,s]=l;return P<0||P>1||s<0||s>1?null:R(t,P)},i=r(e[0]);return i?[i]:(i=r(e[1]),i?[i]:(i=r(e[2]),i?[i]:[]))}function Pt(t,n,o=.001){let e=(P,s,u,m=o)=>{let x=P,b=s,f;for(;b-x>m;)f=(b+x)/2,u(f-m)<u(f+m)?b=f:x=f;return f},i=0;for(let P=1/0,s=0;s<30;s++){let u=_(n,R(t,s/30));u<P&&(P=u,i=s)}let a=Math.max((i-1)/30,0),c=Math.min((i+1)/30,1),l=e(a,c,P=>_(n,R(t,P)));return l?R(t,l):null}function Ut(t,n){let o=Pt(t,n);return o?_(n,o):0}function $t(t){return Array.isArray(t)&&t.length===4&&S(t[0])&&S(t[1])&&S(t[2])&&S(t[3])}function j([t,n,o,e],r){return L(-3*(1-r)*(1-r)*t[0]+3*(1-r)*(1-r)*n[0]-6*r*(1-r)*n[0]-3*r*r*o[0]+6*r*(1-r)*o[0]+3*r*r*e[0],-3*(1-r)*(1-r)*t[1]+3*(1-r)*(1-r)*n[1]-6*r*(1-r)*n[1]-3*r*r*o[1]+6*r*(1-r)*o[1]+3*r*r*e[1])}function tn(t,n=.5){if(t.length<2)return;let o=[];for(let e=0;e<t.length-1;e++){let r=t[e-1<0?0:e-1],i=t[e],a=t[e+1>=t.length?t.length-1:e+1],c=i[0]+(a[0]-r[0])*n/2,l=i[1]+(a[1]-r[1])*n/2;o.push([p(c,l),p(a[0],a[1])])}return o}function nn(t,n=.5){if(t.length<2)return;let o=[];for(let e=0;e<t.length-1;e++){let r=t[e-1<0?0:e-1],i=t[e],a=t[e+1>=t.length?t.length-1:e+1],c=t[e+2>=t.length?t.length-1:e+2],l=[(a[0]-r[0])*n,(a[1]-r[1])*n],P=[(c[0]-i[0])*n,(c[1]-i[1])*n],s=i[0]+l[0]/3,u=i[1]+l[1]/3,m=a[0]-P[0]/3,x=a[1]-P[1]/3;o.push(tt(p(i[0],i[1]),p(s,u),p(m,x),p(a[0],a[1])))}return o}function on([t,n,o,e],r,i=50){let a=[];for(let c=0;c<=i;c++){let l=c/i,P=tt(t,n,o,e),s=R(P,l),u=T(j(P,l)),m=O(u);a.push(I(M(m,r),s))}return a}function en(t,n,o,e,r=50){let i=[];for(let a=0;a<=r;a++){let c=a/r,l=1-c,P=p(l*l*t[0]+2*l*c*n[0]+c*c*o[0],l*l*t[1]+2*l*c*n[1]+c*c*o[1]),s=2*(1-c)*(n[0]-t[0])+2*c*(o[0]-n[0]),u=2*(1-c)*(n[1]-t[1])+2*c*(o[1]-n[1]),m=T(L(s,u)),x=O(m);i.push(I(M(x,e),P))}return i}function nt(t){let o=0;for(let e=0;e<24;e++){let r=.5*X[e]+.5,i=j(t,r),a=Math.sqrt(i[0]*i[0]+i[1]*i[1]);o+=Y[e]*a}return .5*o}function ut(t,n){if(n<=0)return 0;if(n>=1)return nt(t);let o=n/2,e=n/2,r=0;for(let i=0;i<24;i++){let a=o*X[i]+e,c=j(t,a),l=Math.sqrt(c[0]*c[0]+c[1]*c[1]);r+=Y[i]*l}return o*r}function rn(t,n){if(n<=0)return R(t,0);if(n>=1)return R(t,1);let o=nt(t),e=o*n,r=0,i=1,a=n,c=0,l=o*1e-4,P=20;for(let s=0;s<P&&(c=ut(t,a),!(Math.abs(c-e)<l));s++)c<e?r=a:i=a,a=(r+i)/2;return R(t,a)}function un(t,n,o){return{center:t,halfWidth:n,halfHeight:o}}var mn=(t,n)=>{let{center:o,halfWidth:e,halfHeight:r}=n,i=(t[0]-o[0])/e,a=(t[1]-o[1])/r;return i*i+a*a<=1},pn=(t,n,o=1e-4)=>mt(t,n)<=o,mt=(t,n)=>{let{halfWidth:o,halfHeight:e,center:r}=n,i=o,a=e,c=F(h(t),M(h(r),-1)),l=Math.abs(c[0]),P=Math.abs(c[1]),s=.707,u=.707;for(let b=0;b<3;b++){let f=i*s,d=a*u,G=(i*i-a*a)*s**3/i,V=(a*a-i*i)*u**3/a,it=f-G,at=d-V,W=l-G,H=P-V,Q=Math.hypot(at,it),J=Math.hypot(H,W);s=Math.min(1,Math.max(0,(W*Q/J+G)/i)),u=Math.min(1,Math.max(0,(H*Q/J+V)/a));let Z=Math.hypot(u,s);s/=Z,u/=Z}let[m,x]=[i*s*Math.sign(c[0]),a*u*Math.sign(c[1])];return _(I(c),p(m,x))};function xn(t,n){let o=t.halfWidth,e=t.halfHeight,r=h(n[1],n[0]),i=L(n[0][0]-t.center[0],n[0][1]-t.center[1]),a=L(r[0]/(o*o),r[1]/(e*e)),c=L(i[0]/(o*o),i[1]/(e*e)),l=E(r,a),P=E(r,c),s=E(i,c)-1,u=P*P-l*s,m=[];if(u>0){let x=(-P-Math.sqrt(u))/l,b=(-P+Math.sqrt(u))/l;0<=x&&x<=1&&m.push(p(n[0][0]+(n[1][0]-n[0][0])*x,n[0][1]+(n[1][1]-n[0][1])*x)),0<=b&&b<=1&&m.push(p(n[0][0]+(n[1][0]-n[0][0])*b,n[0][1]+(n[1][1]-n[0][1])*b))}else if(u===0){let x=-P/l;0<=x&&x<=1&&m.push(p(n[0][0]+(n[1][0]-n[0][0])*x,n[0][1]+(n[1][1]-n[0][1])*x))}return m}function bn({center:t,halfWidth:n,halfHeight:o},[e,r]){let[i,a]=t,c=e[0]-i,l=e[1]-a,P=r[0]-i,s=r[1]-a,u=Math.pow(P-c,2)/Math.pow(n,2)+Math.pow(s-l,2)/Math.pow(o,2),m=2*(c*(P-c)/Math.pow(n,2)+l*(s-l)/Math.pow(o,2)),x=Math.pow(c,2)/Math.pow(n,2)+Math.pow(l,2)/Math.pow(o,2)-1,b=(-m+Math.sqrt(Math.pow(m,2)-4*u*x))/(2*u),f=(-m-Math.sqrt(Math.pow(m,2)-4*u*x))/(2*u),d=[p(c+b*(P-c)+i,l+b*(s-l)+a),p(c+f*(P-c)+i,l+f*(s-l)+a)].filter(G=>!isNaN(G[0])&&!isNaN(G[1]));return d.length===2&&A(d[0],d[1])?[d[0]]:d}function k(t,n){return[t,n]}function ot(t,n){let o=t[1][1]-t[0][1],e=t[0][0]-t[1][0],r=n[1][1]-n[0][1],i=n[0][0]-n[1][0],a=o*i-r*e;if(a!==0){let c=o*t[0][0]+e*t[0][1],l=r*n[0][0]+i*n[0][1];return p((c*i-l*e)/a,(o*l-r*c)/a)}return null}function v(t,n){return[t,n]}var Sn=t=>Array.isArray(t)&&t.length===2&&S(t[0])&&S(t[0]),vn=(t,n,o)=>v(w(t[0],o||z(t[0],t[1]),n),w(t[1],o||z(t[0],t[1]),n)),In=(t,n)=>{let o=h(t[0]),e=h(t[1]),r=h(n[0]),i=h(n[1]),a=D(e,o),c=D(i,r),l=N(a,c);if(l===0)return null;let P=D(h(n[0]),h(t[0])),s=N(P,a)/l,u=N(P,c)/l;if(s===0)return null;let m=F(o,M(a,u));return u>=0&&u<1&&s>=0&&s<1?I(m):null},q=(t,n,o=1e-4)=>{let e=pt(t,n);return e===0?!0:e<o},pt=(t,n)=>{let[o,e]=t,[[r,i],[a,c]]=n,l=o-r,P=e-i,s=a-r,u=c-i,m=l*s+P*u,x=s*s+u*u,b=-1;x!==0&&(b=m/x);let f,d;b<0?(f=r,d=i):b>1?(f=a,d=c):(f=r+b*s,d=i+b*u);let G=o-f,V=e-d;return Math.sqrt(G*G+V*V)};function et(t,n,o){let e=ot(k(t[0],t[1]),k(n[0],n[1]));return!e||!q(e,n,o)||!q(e,t,o)?null:e}function Fn(...t){return rt(t)}function Dn(t){return rt(t)}var An=(t,n)=>{let o=t[0],e=t[1],r=!1;for(let i=0,a=n.length-1;i<n.length;a=i++){let c=n[i][0],l=n[i][1],P=n[a][0],s=n[a][1];(l>e&&s<=e||l<=e&&s>e)&&o<(P-c)*(e-l)/(s-l)+c&&(r=!r)}return r},wn=(t,n)=>{let[o,e]=t,r=0;for(let i=0;i<n.length;i++){let a=(i+1)%n.length,[c,l]=n[i],[P,s]=n[a];l<=e?s>e&&(P-c)*(e-l)-(o-c)*(s-l)>0&&r++:s<=e&&(P-c)*(e-l)-(o-c)*(s-l)<0&&r--}return r!==0},qn=(t,n,o=1e-4)=>{let e=!1;for(let r=0,i=n.length-1;r<i;r++)if(q(t,v(n[r],n[r+1]),o)){e=!0;break}return e};function rt(t){return xt(t)?t:[...t,t[0]]}function xt(t){return A(t[0],t[t.length-1])}import{toBrandedType as B}from"@excalidraw/common";function Xn(t,n){return B([t,n])}function Yn(t){return B(t)}var jn=([t,n],[o,e])=>t<=o?n>=o:t>=o?e>=t:!1,kn=([t,n],[o,e])=>{let r=Math.max(t,o),i=Math.min(n,e);return r<=i?B([r,i]):null},Bn=(t,[n,o])=>t>=n&&t<=o;function bt(t,n){return[t,n]}function Zn(t,n,o,e){return bt(p(t,n),p(o,e))}function Kn(t,n){return[v(t[0],p(t[1][0],t[0][1])),v(p(t[1][0],t[0][1]),t[1]),v(t[1],p(t[0][0],t[1][1])),v(p(t[0][0],t[1][1]),t[0])].map(o=>et(n,o)).filter(o=>!!o)}function Un(t,n){let[[o,e],[r,i]]=t,[[a,c],[l,P]]=n;return o<l&&r>a&&e<P&&i>c}function no([t,n,o],e){let r=(s,u,m)=>(s[0]-m[0])*(u[1]-m[1])-(u[0]-m[0])*(s[1]-m[1]),i=r(e,t,n),a=r(e,n,o),c=r(e,o,t),l=i<0||a<0||c<0,P=i>0||a>0||c>0;return!(l&&P)}export{y as PRECISION,ht as average,R as bezierEquation,St as cartesian2Polar,ft as clamp,tt as curve,nn as curveCatmullRomCubicApproxPoints,tn as curveCatmullRomQuadraticApproxPoints,Pt as curveClosestPoint,Kt as curveIntersectLineSegment,nt as curveLength,ut as curveLengthAtParameter,on as curveOffsetPoints,rn as curvePointAtLength,Ut as curvePointDistance,j as curveTangent,K as degreesToRadians,pt as distanceToLineSegment,un as ellipse,mt as ellipseDistanceFromPoint,mn as ellipseIncludesPoint,bn as ellipseLineIntersectionPoints,xn as ellipseSegmentInterceptPoints,pn as ellipseTouchesPoint,yt as isCloseTo,$t as isCurve,Lt as isFiniteNumber,Sn as isLineSegment,S as isPoint,jt as isPointWithinBounds,It as isRightAngleRads,Et as isVector,k as line,v as lineSegment,et as lineSegmentIntersectionPoints,vn as lineSegmentRotate,ot as linesIntersectAt,C as normalizeRadians,en as offsetPointsForQuadraticBezier,z as pointCenter,_ as pointDistance,Xt as pointDistanceSq,p as pointFrom,Tt as pointFromArray,Ot as pointFromPair,I as pointFromVector,q as pointOnLineSegment,qn as pointOnPolygon,zt as pointRotateDegs,w as pointRotateRads,Yt as pointScaleFromOrigin,lt as pointTranslate,A as pointsEqual,Fn as polygon,Dn as polygonFromPoints,An as polygonIncludesPoint,wn as polygonIncludesPointNonZero,Vt as radiansBetweenAngles,Ct as radiansDifference,vt as radiansToDegrees,Bn as rangeIncludesValue,Xn as rangeInclusive,Yn as rangeInclusiveFromPair,kn as rangeIntersection,jn as rangesOverlap,bt as rectangle,Zn as rectangleFromNumberSequence,Kn as rectangleIntersectLineSegment,Un as rectangleIntersectRectangle,dt as round,gt as roundToStep,In as segmentsIntersectAt,no as triangleIncludesPoint,L as vector,F as vectorAdd,N as vectorCross,E as vectorDot,h as vectorFromPoint,ct as vectorMagnitude,U as vectorMagnitudeSq,O as vectorNormal,T as vectorNormalize,M as vectorScale,D as vectorSubtract};
|
|
1
|
+
var M=1e-4,gt=(t,n,o)=>Math.min(Math.max(t,n),o),ht=(t,n,o="round")=>{let e=Math.pow(10,n);return Math[o]((t+Number.EPSILON)*e)/e},Lt=(t,n,o="round")=>{let e=1/n;return Math[o](t*e)/e},yt=(t,n)=>(t+n)/2,Gt=t=>typeof t=="number"&&Number.isFinite(t),Mt=(t,n,o=1e-4)=>Math.abs(t-n)<o;var V=t=>t<0?t%(2*Math.PI)+2*Math.PI:t%(2*Math.PI),vt=([t,n])=>[Math.hypot(t,n),V(Math.atan2(n,t))];function et(t){return t*Math.PI/180}function Ct(t){return t*180/Math.PI}function Vt(t){return Math.abs(Math.sin(2*t))<1e-4}function _t(t,n,o){return t=V(t),n=V(n),o=V(o),n<o?t>=n&&t<=o:t>=n||t<=o}function Nt(t,n){t=V(t),n=V(n);let o=t-n;return o<-Math.PI?o=o+2*Math.PI:o>Math.PI&&(o=o-2*Math.PI),Math.abs(o)}function y(t,n,o=0,e=0){return[t-o,n-e]}function L(t,n=[0,0],o,e=[0,1]){let i=y(t[0]-n[0],t[1]-n[1]);return o&&it(i)<o*o?e:i}function z(t,n){return t[0]*n[1]-n[0]*t[1]}function O(t,n){return t[0]*n[0]+t[1]*n[1]}function Et(t){return Array.isArray(t)&&t.length===2&&typeof t[0]=="number"&&!isNaN(t[0])&&typeof t[1]=="number"&&!isNaN(t[1])}function X(t,n){return[t[0]+n[0],t[1]+n[1]]}function Y(t,n){return[t[0]-n[0],t[1]-n[1]]}function R(t,n){return y(t[0]*n,t[1]*n)}function it(t){return t[0]*t[0]+t[1]*t[1]}function Pt(t){return Math.sqrt(it(t))}var W=t=>{let n=Pt(t);return n===0?y(0,0):y(t[0]/n,t[1]/n)},H=t=>y(t[1],-t[0]);function p(t,n){return[t,n]}function Ot(t){return t.length===2?p(t[0],t[1]):void 0}function Xt(t){return t}function C(t,n=p(0,0)){return p(n[0]+t[0],n[1]+t[1])}function S(t){return Array.isArray(t)&&t.length===2&&typeof t[0]=="number"&&!isNaN(t[0])&&typeof t[1]=="number"&&!isNaN(t[1])}function k(t,n,o=1e-4){let e=Math.abs;return e(t[0]-n[0])<o&&e(t[1]-n[1])<o}function B([t,n],[o,e],i){return p((t-o)*Math.cos(i)-(n-e)*Math.sin(i)+o,(t-o)*Math.sin(i)+(n-e)*Math.cos(i)+e)}function Yt(t,n,o){return B(t,n,et(o))}function ut(t,n=[0,0]){return p(t[0]+n[0],t[1]+n[1])}function Q(t,n){return p((t[0]+n[0])/2,(t[1]+n[1])/2)}function _(t,n){return Math.hypot(n[0]-t[0],n[1]-t[1])}function kt(t,n){let o=n[0]-t[0],e=n[1]-t[1];return o*o+e*e}var Bt=(t,n,o)=>ut(n,R(L(t,n),o)),jt=(t,n,o)=>n[0]<=Math.max(t[0],o[0])&&n[0]>=Math.min(t[0],o[0])&&n[1]<=Math.max(t[1],o[1])&&n[1]>=Math.min(t[1],o[1]);var J=[-.06405689286260563,.06405689286260563,-.1911188674736163,.1911188674736163,-.3150426796961634,.3150426796961634,-.4337935076260451,.4337935076260451,-.5454214713888396,.5454214713888396,-.6480936519369755,.6480936519369755,-.7401241915785544,.7401241915785544,-.820001985973903,.820001985973903,-.8864155270044011,.8864155270044011,-.9382745520027328,.9382745520027328,-.9747285559713095,.9747285559713095,-.9951872199970213,.9951872199970213],Z=[.12793819534675216,.12793819534675216,.1258374563468283,.1258374563468283,.12167047292780339,.12167047292780339,.1155056680537256,.1155056680537256,.10744427011596563,.10744427011596563,.09761865210411388,.09761865210411388,.08619016153195327,.08619016153195327,.0733464814110803,.0733464814110803,.05929858491543678,.05929858491543678,.04427743881741981,.04427743881741981,.028531388628933663,.028531388628933663,.0123412297999872,.0123412297999872];function rt(t,n,o,e){return[t,n,o,e]}function mt(t,n,o,e,i=.001,r=10){let a=1/0,l=0;for(;a>=i;){if(l>=r)return null;let s=1-o,P=s*s,c=P*s,u=o*o,m=u*o,x=c*t[0][0]+3*P*o*t[1][0]+3*s*u*t[2][0]+m*t[3][0],b=c*t[0][1]+3*P*o*t[1][1]+3*s*u*t[2][1]+m*t[3][1],f=n[0][0]+e*(n[1][0]-n[0][0]),d=n[0][1]+e*(n[1][1]-n[0][1]),h=x-f,G=b-d;if(a=Math.abs(h)+Math.abs(G),a<i)break;let w=-3*P*t[0][0]+3*P*t[1][0]-6*s*o*t[1][0]-3*u*t[2][0]+6*s*o*t[2][0]+3*u*t[3][0],q=-3*P*t[0][1]+3*P*t[1][1]-6*s*o*t[1][1]-3*u*t[2][1]+6*s*o*t[2][1]+3*u*t[3][1],N=-(n[1][0]-n[0][0]),D=-(n[1][1]-n[0][1]),F=w*D-N*q;if(Math.abs(F)<1e-12)return null;let E=1/F,T=E*(D*-h-N*-G),ct=E*(-q*-h+w*-G);o+=T,e+=ct,l+=1}return[o,e]}var I=(t,n)=>p((1-n)**3*t[0][0]+3*(1-n)**2*n*t[1][0]+3*(1-n)*n**2*t[2][0]+n**3*t[3][0],(1-n)**3*t[0][1]+3*(1-n)**2*n*t[1][1]+3*(1-n)*n**2*t[2][1]+n**3*t[3][1]),K=[[.5,0],[.2,0],[.8,0]],U=([t,n],o,e)=>{let i=mt(e,o,t,n,.01,3);if(!i)return null;let[r,a]=i;return r<0||r>1||a<0||a>1?null:I(e,r)};function $t(t,n){let o=U(K[0],n,t);return o?[o]:(o=U(K[1],n,t),o?[o]:(o=U(K[2],n,t),o?[o]:[]))}function pt(t,n,o=.001){let e=(P,c,u,m=o)=>{let x=P,b=c,f;for(;b-x>m;)f=(b+x)/2,u(f-m)<u(f+m)?b=f:x=f;return f},r=0;for(let P=1/0,c=0;c<30;c++){let u=_(n,I(t,c/30));u<P&&(P=u,r=c)}let a=Math.max((r-1)/30,0),l=Math.min((r+1)/30,1),s=e(a,l,P=>_(n,I(t,P)));return s?I(t,s):null}function tn(t,n){let o=pt(t,n);return o?_(n,o):0}function nn(t){return Array.isArray(t)&&t.length===4&&S(t[0])&&S(t[1])&&S(t[2])&&S(t[3])}function $([t,n,o,e],i){return y(-3*(1-i)*(1-i)*t[0]+3*(1-i)*(1-i)*n[0]-6*i*(1-i)*n[0]-3*i*i*o[0]+6*i*(1-i)*o[0]+3*i*i*e[0],-3*(1-i)*(1-i)*t[1]+3*(1-i)*(1-i)*n[1]-6*i*(1-i)*n[1]-3*i*i*o[1]+6*i*(1-i)*o[1]+3*i*i*e[1])}function on(t,n=.5){if(t.length<2)return;let o=[];for(let e=0;e<t.length-1;e++){let i=t[e-1<0?0:e-1],r=t[e],a=t[e+1>=t.length?t.length-1:e+1],l=r[0]+(a[0]-i[0])*n/2,s=r[1]+(a[1]-i[1])*n/2;o.push([p(l,s),p(a[0],a[1])])}return o}function en(t,n=.5){if(t.length<2)return;let o=[];for(let e=0;e<t.length-1;e++){let i=t[e-1<0?0:e-1],r=t[e],a=t[e+1>=t.length?t.length-1:e+1],l=t[e+2>=t.length?t.length-1:e+2],s=[(a[0]-i[0])*n,(a[1]-i[1])*n],P=[(l[0]-r[0])*n,(l[1]-r[1])*n],c=r[0]+s[0]/3,u=r[1]+s[1]/3,m=a[0]-P[0]/3,x=a[1]-P[1]/3;o.push(rt(p(r[0],r[1]),p(c,u),p(m,x),p(a[0],a[1])))}return o}function rn([t,n,o,e],i,r=50){let a=[];for(let l=0;l<=r;l++){let s=l/r,P=rt(t,n,o,e),c=I(P,s),u=W($(P,s)),m=H(u);a.push(C(R(m,i),c))}return a}function an(t,n,o,e,i=50){let r=[];for(let a=0;a<=i;a++){let l=a/i,s=1-l,P=p(s*s*t[0]+2*s*l*n[0]+l*l*o[0],s*s*t[1]+2*s*l*n[1]+l*l*o[1]),c=2*(1-l)*(n[0]-t[0])+2*l*(o[0]-n[0]),u=2*(1-l)*(n[1]-t[1])+2*l*(o[1]-n[1]),m=W(y(c,u)),x=H(m);r.push(C(R(x,e),P))}return r}function at(t){let o=0;for(let e=0;e<24;e++){let i=.5*J[e]+.5,r=$(t,i),a=Math.sqrt(r[0]*r[0]+r[1]*r[1]);o+=Z[e]*a}return .5*o}function xt(t,n){if(n<=0)return 0;if(n>=1)return at(t);let o=n/2,e=n/2,i=0;for(let r=0;r<24;r++){let a=o*J[r]+e,l=$(t,a),s=Math.sqrt(l[0]*l[0]+l[1]*l[1]);i+=Z[r]*s}return o*i}function ln(t,n){if(n<=0)return I(t,0);if(n>=1)return I(t,1);let o=at(t),e=o*n,i=0,r=1,a=n,l=0,s=o*1e-4,P=20;for(let c=0;c<P&&(l=xt(t,a),!(Math.abs(l-e)<s));c++)l<e?i=a:r=a,a=(i+r)/2;return I(t,a)}function pn(t,n,o){return{center:t,halfWidth:n,halfHeight:o}}var xn=(t,n)=>{let{center:o,halfWidth:e,halfHeight:i}=n,r=(t[0]-o[0])/e,a=(t[1]-o[1])/i;return r*r+a*a<=1},bn=(t,n,o=1e-4)=>bt(t,n)<=o,bt=(t,n)=>{let{halfWidth:o,halfHeight:e,center:i}=n,r=o,a=e,l=X(L(t),R(L(i),-1)),s=Math.abs(l[0]),P=Math.abs(l[1]),c=.707,u=.707;for(let b=0;b<3;b++){let f=r*c,d=a*u,h=(r*r-a*a)*c**3/r,G=(a*a-r*r)*u**3/a,w=f-h,q=d-G,N=s-h,D=P-G,F=Math.hypot(q,w),E=Math.hypot(D,N);c=Math.min(1,Math.max(0,(N*F/E+h)/r)),u=Math.min(1,Math.max(0,(D*F/E+G)/a));let T=Math.hypot(u,c);c/=T,u/=T}let[m,x]=[r*c*Math.sign(l[0]),a*u*Math.sign(l[1])];return _(C(l),p(m,x))};function fn(t,n){let o=t.halfWidth,e=t.halfHeight,i=L(n[1],n[0]),r=y(n[0][0]-t.center[0],n[0][1]-t.center[1]),a=y(i[0]/(o*o),i[1]/(e*e)),l=y(r[0]/(o*o),r[1]/(e*e)),s=O(i,a),P=O(i,l),c=O(r,l)-1,u=P*P-s*c,m=[];if(u>0){let x=(-P-Math.sqrt(u))/s,b=(-P+Math.sqrt(u))/s;0<=x&&x<=1&&m.push(p(n[0][0]+(n[1][0]-n[0][0])*x,n[0][1]+(n[1][1]-n[0][1])*x)),0<=b&&b<=1&&m.push(p(n[0][0]+(n[1][0]-n[0][0])*b,n[0][1]+(n[1][1]-n[0][1])*b))}else if(u===0){let x=-P/s;0<=x&&x<=1&&m.push(p(n[0][0]+(n[1][0]-n[0][0])*x,n[0][1]+(n[1][1]-n[0][1])*x))}return m}function dn({center:t,halfWidth:n,halfHeight:o},[e,i]){let[r,a]=t,l=e[0]-r,s=e[1]-a,P=i[0]-r,c=i[1]-a,u=Math.pow(P-l,2)/Math.pow(n,2)+Math.pow(c-s,2)/Math.pow(o,2),m=2*(l*(P-l)/Math.pow(n,2)+s*(c-s)/Math.pow(o,2)),x=Math.pow(l,2)/Math.pow(n,2)+Math.pow(s,2)/Math.pow(o,2)-1,b=(-m+Math.sqrt(Math.pow(m,2)-4*u*x))/(2*u),f=(-m-Math.sqrt(Math.pow(m,2)-4*u*x))/(2*u),d=[p(l+b*(P-l)+r,s+b*(c-s)+a),p(l+f*(P-l)+r,s+f*(c-s)+a)].filter(h=>!isNaN(h[0])&&!isNaN(h[1]));return d.length===2&&k(d[0],d[1])?[d[0]]:d}function tt(t,n){return[t,n]}function lt(t,n){let o=t[1][1]-t[0][1],e=t[0][0]-t[1][0],i=n[1][1]-n[0][1],r=n[0][0]-n[1][0],a=o*r-i*e;if(a!==0){let l=o*t[0][0]+e*t[0][1],s=i*n[0][0]+r*n[0][1];return p((l*r-s*e)/a,(o*s-i*l)/a)}return null}function v(t,n){return[t,n]}var vn=t=>Array.isArray(t)&&t.length===2&&S(t[0])&&S(t[0]),Cn=(t,n,o)=>v(B(t[0],o||Q(t[0],t[1]),n),B(t[1],o||Q(t[0],t[1]),n)),Vn=(t,n)=>{let o=L(t[0]),e=L(t[1]),i=L(n[0]),r=L(n[1]),a=Y(e,o),l=Y(r,i),s=z(a,l);if(s===0)return null;let P=Y(L(n[0]),L(t[0])),c=z(P,a)/s,u=z(P,l)/s;if(c===0)return null;let m=X(o,R(a,u));return u>=0&&u<1&&c>=0&&c<1?C(m):null},j=(t,n,o=1e-4)=>{let e=A(t,n);return e===0?!0:e<o},A=(t,n)=>{let[o,e]=t,[[i,r],[a,l]]=n,s=o-i,P=e-r,c=a-i,u=l-r,m=s*c+P*u,x=c*c+u*u,b=-1;x!==0&&(b=m/x);let f,d;b<0?(f=i,d=r):b>1?(f=a,d=l):(f=i+b*c,d=r+b*u);let h=o-f,G=e-d;return Math.sqrt(h*h+G*G)};function nt(t,n,o){let e=lt(tt(t[0],t[1]),tt(n[0],n[1]));return!e||!j(e,n,o)||!j(e,t,o)?null:e}function _n(t,n){return nt(t,n)?0:Math.min(A(t[0],n),A(t[1],n),A(n[0],t),A(n[1],t))}function wn(...t){return st(t)}function qn(t){return st(t)}var Tn=(t,n)=>{let o=t[0],e=t[1],i=!1;for(let r=0,a=n.length-1;r<n.length;a=r++){let l=n[r][0],s=n[r][1],P=n[a][0],c=n[a][1];(s>e&&c<=e||s<=e&&c>e)&&o<(P-l)*(e-s)/(c-s)+l&&(i=!i)}return i},zn=(t,n)=>{let[o,e]=t,i=0;for(let r=0;r<n.length;r++){let a=(r+1)%n.length,[l,s]=n[r],[P,c]=n[a];s<=e?c>e&&(P-l)*(e-s)-(o-l)*(c-s)>0&&i++:c<=e&&(P-l)*(e-s)-(o-l)*(c-s)<0&&i--}return i!==0},On=(t,n,o=1e-4)=>{let e=!1;for(let i=0,r=n.length-1;i<r;i++)if(j(t,v(n[i],n[i+1]),o)){e=!0;break}return e};function st(t){return ft(t)?t:[...t,t[0]]}function ft(t){return k(t[0],t[t.length-1])}import{toBrandedType as ot}from"@excalidraw/common";function Bn(t,n){return ot([t,n])}function jn(t){return ot(t)}var Wn=([t,n],[o,e])=>t<=o?n>=o:t>=o?e>=t:!1,Hn=([t,n],[o,e])=>{let i=Math.max(t,o),r=Math.min(n,e);return i<=r?ot([i,r]):null},Qn=(t,[n,o])=>t>=n&&t<=o;function dt(t,n){return[t,n]}function $n(t,n,o,e){return dt(p(t,n),p(o,e))}function to(t,n){return[v(t[0],p(t[1][0],t[0][1])),v(p(t[1][0],t[0][1]),t[1]),v(t[1],p(t[0][0],t[1][1])),v(p(t[0][0],t[1][1]),t[0])].map(o=>nt(n,o)).filter(o=>!!o)}function no(t,n){let[[o,e],[i,r]]=t,[[a,l],[s,P]]=n;return o<s&&i>a&&e<P&&r>l}function io([t,n,o],e){let i=(c,u,m)=>(c[0]-m[0])*(u[1]-m[1])-(u[0]-m[0])*(c[1]-m[1]),r=i(e,t,n),a=i(e,n,o),l=i(e,o,t),s=r<0||a<0||l<0,P=r>0||a>0||l>0;return!(s&&P)}export{M as PRECISION,yt as average,I as bezierEquation,vt as cartesian2Polar,gt as clamp,rt as curve,en as curveCatmullRomCubicApproxPoints,on as curveCatmullRomQuadraticApproxPoints,pt as curveClosestPoint,$t as curveIntersectLineSegment,at as curveLength,xt as curveLengthAtParameter,rn as curveOffsetPoints,ln as curvePointAtLength,tn as curvePointDistance,$ as curveTangent,et as degreesToRadians,A as distanceToLineSegment,pn as ellipse,bt as ellipseDistanceFromPoint,xn as ellipseIncludesPoint,dn as ellipseLineIntersectionPoints,fn as ellipseSegmentInterceptPoints,bn as ellipseTouchesPoint,Mt as isCloseTo,nn as isCurve,Gt as isFiniteNumber,vn as isLineSegment,S as isPoint,jt as isPointWithinBounds,Vt as isRightAngleRads,Et as isVector,tt as line,v as lineSegment,nt as lineSegmentIntersectionPoints,Cn as lineSegmentRotate,_n as lineSegmentsDistance,lt as linesIntersectAt,V as normalizeRadians,an as offsetPointsForQuadraticBezier,Q as pointCenter,_ as pointDistance,kt as pointDistanceSq,p as pointFrom,Ot as pointFromArray,Xt as pointFromPair,C as pointFromVector,j as pointOnLineSegment,On as pointOnPolygon,Yt as pointRotateDegs,B as pointRotateRads,Bt as pointScaleFromOrigin,ut as pointTranslate,k as pointsEqual,wn as polygon,qn as polygonFromPoints,Tn as polygonIncludesPoint,zn as polygonIncludesPointNonZero,_t as radiansBetweenAngles,Nt as radiansDifference,Ct as radiansToDegrees,Qn as rangeIncludesValue,Bn as rangeInclusive,jn as rangeInclusiveFromPair,Hn as rangeIntersection,Wn as rangesOverlap,dt as rectangle,$n as rectangleFromNumberSequence,to as rectangleIntersectLineSegment,no as rectangleIntersectRectangle,ht as round,Lt as roundToStep,Vn as segmentsIntersectAt,io as triangleIncludesPoint,y as vector,X as vectorAdd,z as vectorCross,O as vectorDot,L as vectorFromPoint,Pt as vectorMagnitude,it as vectorMagnitudeSq,H as vectorNormal,W as vectorNormalize,R as vectorScale,Y as vectorSubtract};
|