@excalidraw/math 0.18.0-2b0e4c9 → 0.18.0-39103bd
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 +303 -100
- package/dist/dev/index.js.map +4 -4
- package/dist/prod/index.js +1 -1
- package/dist/types/common/src/colors.d.ts +1 -1
- package/dist/types/common/src/constants.d.ts +11 -7
- package/dist/types/common/src/points.d.ts +1 -1
- package/dist/types/common/src/utils.d.ts +1 -43
- package/dist/types/element/src/Scene.d.ts +6 -4
- package/dist/types/element/src/align.d.ts +2 -2
- package/dist/types/element/src/arrowEndpointText.d.ts +49 -0
- package/dist/types/element/src/arrows/focus.d.ts +5 -2
- package/dist/types/element/src/binding.d.ts +17 -8
- package/dist/types/element/src/bounds.d.ts +22 -7
- package/dist/types/element/src/collision.d.ts +1 -1
- package/dist/types/element/src/comparisons.d.ts +5 -4
- package/dist/types/element/src/convertToShape.d.ts +23 -0
- package/dist/types/element/src/distribute.d.ts +2 -2
- package/dist/types/element/src/dragElements.d.ts +27 -0
- package/dist/types/element/src/duplicate.d.ts +4 -3
- package/dist/types/element/src/embeddable.d.ts +2 -2
- package/dist/types/element/src/flowchart.d.ts +7 -7
- package/dist/types/element/src/fractionalIndex.d.ts +2 -2
- package/dist/types/element/src/frame.d.ts +9 -8
- package/dist/types/element/src/groups.d.ts +9 -9
- package/dist/types/element/src/index.d.ts +3 -1
- package/dist/types/element/src/linearElementEditor.d.ts +17 -10
- package/dist/types/element/src/newElement.d.ts +14 -0
- package/dist/types/element/src/renderElement.d.ts +0 -3
- package/dist/types/element/src/resizeElements.d.ts +2 -2
- package/dist/types/element/src/selection.d.ts +11 -7
- package/dist/types/element/src/shape.d.ts +1 -1
- package/dist/types/element/src/textElement.d.ts +13 -10
- package/dist/types/element/src/textWrapping.d.ts +26 -0
- package/dist/types/element/src/transform.d.ts +2 -2
- package/dist/types/element/src/typeChecks.d.ts +26 -25
- package/dist/types/element/src/types.d.ts +8 -1
- package/dist/types/element/src/utils.d.ts +1 -1
- package/dist/types/element/src/zindex.d.ts +2 -2
- package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +33 -15
- package/dist/types/excalidraw/actions/actionAlign.d.ts +6 -6
- package/dist/types/excalidraw/actions/actionBoundText.d.ts +23 -11
- package/dist/types/excalidraw/actions/actionCanvas.d.ts +139 -933
- package/dist/types/excalidraw/actions/actionClipboard.d.ts +22 -10
- package/dist/types/excalidraw/actions/actionCropEditor.d.ts +11 -5
- package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +35 -16
- package/dist/types/excalidraw/actions/{actionEmbeddable.d.ts → actionDeselect.d.ts} +25 -34
- package/dist/types/excalidraw/actions/actionDistribute.d.ts +2 -3
- package/dist/types/excalidraw/actions/actionElementLink.d.ts +11 -5
- package/dist/types/excalidraw/actions/actionElementLock.d.ts +23 -11
- package/dist/types/excalidraw/actions/actionExport.d.ts +24 -12
- package/dist/types/excalidraw/actions/actionFrame.d.ts +45 -199
- package/dist/types/excalidraw/actions/actionGroup.d.ts +38 -26
- package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +15 -7
- package/dist/types/excalidraw/actions/actionLink.d.ts +12 -6
- package/dist/types/excalidraw/actions/actionMenu.d.ts +11 -5
- package/dist/types/excalidraw/actions/actionProperties.d.ts +49 -28
- package/dist/types/excalidraw/actions/actionSelectAll.d.ts +16 -10
- package/dist/types/excalidraw/actions/actionStyles.d.ts +12 -5
- package/dist/types/excalidraw/actions/actionTextAutoResize.d.ts +3 -3
- package/dist/types/excalidraw/actions/actionToggleArrowBinding.d.ts +12 -6
- package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +15 -10
- package/dist/types/excalidraw/actions/actionToggleMidpointSnapping.d.ts +12 -6
- package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +12 -6
- package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +15 -10
- package/dist/types/excalidraw/actions/actionToggleShapeSwitch.d.ts +1 -1
- package/dist/types/excalidraw/actions/actionToggleStats.d.ts +12 -6
- package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +13 -7
- package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +12 -6
- package/dist/types/excalidraw/actions/index.d.ts +2 -2
- package/dist/types/excalidraw/actions/manager.d.ts +1 -0
- package/dist/types/excalidraw/actions/shortcuts.d.ts +1 -1
- package/dist/types/excalidraw/actions/types.d.ts +8 -4
- package/dist/types/excalidraw/{animated-trail.d.ts → animatedTrail.d.ts} +4 -3
- package/dist/types/excalidraw/appState.d.ts +7 -5
- package/dist/types/excalidraw/components/Actions.d.ts +17 -12
- package/dist/types/excalidraw/components/ActiveConfirmDialog.d.ts +1 -1
- package/dist/types/excalidraw/components/App.arrowText.d.ts +72 -0
- package/dist/types/excalidraw/components/App.cursor.d.ts +31 -0
- package/dist/types/excalidraw/components/App.d.ts +358 -64
- package/dist/types/excalidraw/components/App.drawshape.d.ts +55 -0
- package/dist/types/excalidraw/components/App.flowchart.d.ts +21 -0
- package/dist/types/excalidraw/components/App.viewport.d.ts +73 -0
- package/dist/types/excalidraw/components/ColorPicker/ColorPicker.d.ts +2 -2
- package/dist/types/excalidraw/components/ColorPicker/colorPickerUtils.d.ts +1 -1
- package/dist/types/excalidraw/components/CommandPalette/defaultCommandPaletteItems.d.ts +1 -2
- package/dist/types/excalidraw/components/ConvertElementTypePopup.d.ts +2 -2
- package/dist/types/excalidraw/components/CursorHint.d.ts +46 -0
- package/dist/types/excalidraw/components/EyeDropper.d.ts +1 -1
- package/dist/types/excalidraw/components/{ToolButton.d.ts → IconButton.d.ts} +16 -19
- package/dist/types/excalidraw/components/Island.d.ts +7 -0
- package/dist/types/excalidraw/components/LaserPointerButton.d.ts +2 -4
- package/dist/types/excalidraw/components/LayerUI.d.ts +4 -2
- package/dist/types/excalidraw/components/LibraryMenu.d.ts +1 -1
- package/dist/types/excalidraw/components/LockButton.d.ts +3 -4
- package/dist/types/excalidraw/components/MagicButton.d.ts +0 -2
- package/dist/types/excalidraw/components/MobileMenu.d.ts +4 -4
- package/dist/types/excalidraw/components/MobileToolbar.d.ts +9 -0
- package/dist/types/excalidraw/components/OverwriteConfirm/OverwriteConfirmState.d.ts +1 -1
- package/dist/types/excalidraw/components/PenModeButton.d.ts +2 -5
- package/dist/types/excalidraw/components/Popover.d.ts +1 -3
- package/dist/types/excalidraw/components/{ButtonIcon.d.ts → RadioButton.d.ts} +2 -5
- package/dist/types/excalidraw/components/Range.d.ts +10 -4
- package/dist/types/excalidraw/components/SVGLayer.d.ts +1 -1
- package/dist/types/excalidraw/components/SearchMenu.d.ts +1 -1
- package/dist/types/excalidraw/components/Sidebar/Sidebar.d.ts +1 -1
- package/dist/types/excalidraw/components/Stats/Angle.d.ts +2 -2
- package/dist/types/excalidraw/components/Stats/Dimension.d.ts +2 -2
- package/dist/types/excalidraw/components/Stats/DragInput.d.ts +2 -2
- package/dist/types/excalidraw/components/Stats/MultiAngle.d.ts +2 -2
- package/dist/types/excalidraw/components/Stats/MultiDimension.d.ts +2 -2
- package/dist/types/excalidraw/components/Stats/MultiPosition.d.ts +2 -2
- package/dist/types/excalidraw/components/Stats/Position.d.ts +3 -3
- package/dist/types/excalidraw/components/Stats/utils.d.ts +1 -1
- package/dist/types/excalidraw/components/TTDDialog/TTDContext.d.ts +4 -4
- package/dist/types/excalidraw/components/TTDDialog/useTTDChatStorage.d.ts +3 -3
- package/dist/types/excalidraw/components/ToolPopover.d.ts +3 -6
- package/dist/types/excalidraw/components/Toolbar.d.ts +11 -0
- package/dist/types/excalidraw/components/Tools.d.ts +145 -0
- package/dist/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +4 -1
- package/dist/types/excalidraw/components/canvases/NewElementCanvas.d.ts +1 -0
- package/dist/types/excalidraw/components/canvases/StaticCanvas.d.ts +1 -1
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemContentRadio.d.ts +2 -1
- package/dist/types/excalidraw/components/footer/Footer.d.ts +3 -1
- package/dist/types/excalidraw/components/hyperlink/helpers.d.ts +2 -2
- package/dist/types/excalidraw/components/icons.d.ts +3 -1
- package/dist/types/excalidraw/components/main-menu/DefaultItems.d.ts +8 -4
- package/dist/types/excalidraw/components/positionElementBesideCursor.d.ts +26 -0
- package/dist/types/excalidraw/components/shapeActionPredicates.d.ts +39 -0
- package/dist/types/excalidraw/data/blob.d.ts +26 -14
- package/dist/types/excalidraw/data/index.d.ts +4 -4
- package/dist/types/excalidraw/data/json.d.ts +19 -13
- package/dist/types/excalidraw/data/library.d.ts +1 -1
- package/dist/types/excalidraw/drawShapeTrail.d.ts +16 -0
- package/dist/types/excalidraw/eraser/index.d.ts +2 -3
- package/dist/types/excalidraw/hooks/useAppStateValue.d.ts +29 -0
- package/dist/types/excalidraw/hooks/useLibraryItemSvg.d.ts +1 -1
- package/dist/types/excalidraw/{laser-trails.d.ts → laserTrails.d.ts} +5 -7
- package/dist/types/excalidraw/lasso/index.d.ts +2 -3
- package/dist/types/excalidraw/renderer/animation.d.ts +5 -1
- package/dist/types/excalidraw/renderer/interactiveScene.d.ts +1 -3
- package/dist/types/excalidraw/scene/Renderer.d.ts +426 -19
- package/dist/types/excalidraw/scene/export.d.ts +3 -3
- package/dist/types/excalidraw/scene/index.d.ts +2 -2
- package/dist/types/excalidraw/scene/types.d.ts +4 -3
- package/dist/types/excalidraw/snapping.d.ts +7 -7
- package/dist/types/excalidraw/textAutoResizeHandle.d.ts +15 -0
- package/dist/types/excalidraw/types.d.ts +369 -20
- package/dist/types/excalidraw/viewport.d.ts +272 -0
- package/dist/types/excalidraw/wysiwyg/textWysiwyg.d.ts +6 -3
- package/dist/types/fractional-indexing/src/index.d.ts +29 -0
- package/dist/types/laser-pointer/src/index.d.ts +2 -0
- package/dist/types/laser-pointer/src/math.d.ts +16 -0
- package/dist/types/laser-pointer/src/simplify.d.ts +2 -0
- package/dist/types/laser-pointer/src/state.d.ts +36 -0
- package/dist/types/math/src/constants.d.ts +0 -1
- package/dist/types/math/src/curve.d.ts +4 -1
- package/dist/types/math/src/index.d.ts +1 -0
- package/dist/types/math/src/pca.d.ts +79 -0
- package/dist/types/math/src/point.d.ts +2 -1
- package/dist/types/math/src/polygon.d.ts +25 -1
- package/dist/types/utils/src/export.d.ts +3 -3
- package/dist/types/utils/src/index.d.ts +1 -2
- package/package.json +2 -2
- package/dist/types/excalidraw/animation-frame-handler.d.ts +0 -16
- package/dist/types/excalidraw/components/HandButton.d.ts +0 -10
- package/dist/types/excalidraw/components/MobileToolBar.d.ts +0 -10
- package/dist/types/excalidraw/components/shapes.d.ts +0 -263
- package/dist/types/excalidraw/cursor.d.ts +0 -5
- package/dist/types/excalidraw/scene/scroll.d.ts +0 -18
- package/dist/types/excalidraw/scene/zoom.d.ts +0 -12
- package/dist/types/utils/src/bbox.d.ts +0 -9
- package/dist/types/utils/src/withinBounds.d.ts +0 -19
package/dist/dev/index.js
CHANGED
|
@@ -120,7 +120,12 @@ function pointsEqual(a, b, tolerance = PRECISION) {
|
|
|
120
120
|
const abs = Math.abs;
|
|
121
121
|
return abs(a[0] - b[0]) < tolerance && abs(a[1] - b[1]) < tolerance;
|
|
122
122
|
}
|
|
123
|
-
function pointRotateRads(
|
|
123
|
+
function pointRotateRads(point, center, angle) {
|
|
124
|
+
if (!angle) {
|
|
125
|
+
return point;
|
|
126
|
+
}
|
|
127
|
+
const [x, y] = point;
|
|
128
|
+
const [cx, cy] = center;
|
|
124
129
|
return pointFrom(
|
|
125
130
|
(x - cx) * Math.cos(angle) - (y - cy) * Math.sin(angle) + cx,
|
|
126
131
|
(x - cx) * Math.sin(angle) + (y - cy) * Math.cos(angle) + cy
|
|
@@ -147,6 +152,9 @@ var pointScaleFromOrigin = (p, mid, multiplier) => pointTranslate(mid, vectorSca
|
|
|
147
152
|
var isPointWithinBounds = (p, q, r) => {
|
|
148
153
|
return q[0] <= Math.max(p[0], r[0]) && q[0] >= Math.min(p[0], r[0]) && q[1] <= Math.max(p[1], r[1]) && q[1] >= Math.min(p[1], r[1]);
|
|
149
154
|
};
|
|
155
|
+
var isValidPoint = (point) => {
|
|
156
|
+
return Array.isArray(point) && point.length === 2 && isFiniteNumber(point[0]) && isFiniteNumber(point[1]);
|
|
157
|
+
};
|
|
150
158
|
|
|
151
159
|
// src/constants.ts
|
|
152
160
|
var LegendreGaussN24TValues = [
|
|
@@ -254,8 +262,15 @@ var initial_guesses = [
|
|
|
254
262
|
[0.2, 0],
|
|
255
263
|
[0.8, 0]
|
|
256
264
|
];
|
|
257
|
-
var calculate = ([t0, s0], l, c) => {
|
|
258
|
-
const solution = solveWithAnalyticalJacobian(
|
|
265
|
+
var calculate = ([t0, s0], l, c, tolerance = 0.01, iterLimit = 4) => {
|
|
266
|
+
const solution = solveWithAnalyticalJacobian(
|
|
267
|
+
c,
|
|
268
|
+
l,
|
|
269
|
+
t0,
|
|
270
|
+
s0,
|
|
271
|
+
tolerance,
|
|
272
|
+
iterLimit
|
|
273
|
+
);
|
|
259
274
|
if (!solution) {
|
|
260
275
|
return null;
|
|
261
276
|
}
|
|
@@ -265,16 +280,34 @@ var calculate = ([t0, s0], l, c) => {
|
|
|
265
280
|
}
|
|
266
281
|
return bezierEquation(c, t);
|
|
267
282
|
};
|
|
268
|
-
function curveIntersectLineSegment(c, l) {
|
|
269
|
-
let solution = calculate(
|
|
283
|
+
function curveIntersectLineSegment(c, l, opts) {
|
|
284
|
+
let solution = calculate(
|
|
285
|
+
initial_guesses[0],
|
|
286
|
+
l,
|
|
287
|
+
c,
|
|
288
|
+
opts?.tolerance,
|
|
289
|
+
opts?.iterLimit
|
|
290
|
+
);
|
|
270
291
|
if (solution) {
|
|
271
292
|
return [solution];
|
|
272
293
|
}
|
|
273
|
-
solution = calculate(
|
|
294
|
+
solution = calculate(
|
|
295
|
+
initial_guesses[1],
|
|
296
|
+
l,
|
|
297
|
+
c,
|
|
298
|
+
opts?.tolerance,
|
|
299
|
+
opts?.iterLimit
|
|
300
|
+
);
|
|
274
301
|
if (solution) {
|
|
275
302
|
return [solution];
|
|
276
303
|
}
|
|
277
|
-
solution = calculate(
|
|
304
|
+
solution = calculate(
|
|
305
|
+
initial_guesses[2],
|
|
306
|
+
l,
|
|
307
|
+
c,
|
|
308
|
+
opts?.tolerance,
|
|
309
|
+
opts?.iterLimit
|
|
310
|
+
);
|
|
278
311
|
if (solution) {
|
|
279
312
|
return [solution];
|
|
280
313
|
}
|
|
@@ -311,7 +344,7 @@ function curveClosestPoint(c, p, tolerance = 1e-3) {
|
|
|
311
344
|
t1,
|
|
312
345
|
(t) => pointDistance(p, bezierEquation(c, t))
|
|
313
346
|
);
|
|
314
|
-
if (
|
|
347
|
+
if (solution == null) {
|
|
315
348
|
return null;
|
|
316
349
|
}
|
|
317
350
|
return bezierEquation(c, solution);
|
|
@@ -319,7 +352,7 @@ function curveClosestPoint(c, p, tolerance = 1e-3) {
|
|
|
319
352
|
function curvePointDistance(c, p) {
|
|
320
353
|
const closest = curveClosestPoint(c, p);
|
|
321
354
|
if (!closest) {
|
|
322
|
-
return
|
|
355
|
+
return Infinity;
|
|
323
356
|
}
|
|
324
357
|
return pointDistance(p, closest);
|
|
325
358
|
}
|
|
@@ -605,11 +638,257 @@ function linesIntersectAt(a, b) {
|
|
|
605
638
|
return null;
|
|
606
639
|
}
|
|
607
640
|
|
|
641
|
+
// src/pca.ts
|
|
642
|
+
function centroid(points) {
|
|
643
|
+
let cx = 0;
|
|
644
|
+
let cy = 0;
|
|
645
|
+
for (const [x, y] of points) {
|
|
646
|
+
cx += x;
|
|
647
|
+
cy += y;
|
|
648
|
+
}
|
|
649
|
+
return pointFrom(cx / points.length, cy / points.length);
|
|
650
|
+
}
|
|
651
|
+
function principalAxes(points) {
|
|
652
|
+
if (points.length < 2) {
|
|
653
|
+
console.error("Degenerate point set: at least two points are required");
|
|
654
|
+
}
|
|
655
|
+
const c = centroid(points);
|
|
656
|
+
let m20 = 0;
|
|
657
|
+
let m02 = 0;
|
|
658
|
+
let m11 = 0;
|
|
659
|
+
for (const [x, y] of points) {
|
|
660
|
+
const dx = x - c[0];
|
|
661
|
+
const dy = y - c[1];
|
|
662
|
+
m20 += dx * dx;
|
|
663
|
+
m02 += dy * dy;
|
|
664
|
+
m11 += dx * dy;
|
|
665
|
+
}
|
|
666
|
+
m20 /= points.length;
|
|
667
|
+
m02 /= points.length;
|
|
668
|
+
m11 /= points.length;
|
|
669
|
+
const trace = m20 + m02;
|
|
670
|
+
const diff = Math.hypot(m20 - m02, 2 * m11);
|
|
671
|
+
const majorVariance = (trace + diff) / 2;
|
|
672
|
+
const minorVariance = (trace - diff) / 2;
|
|
673
|
+
let major;
|
|
674
|
+
if (Math.abs(m11) > Number.EPSILON) {
|
|
675
|
+
major = vectorNormalize(vector(majorVariance - m02, m11));
|
|
676
|
+
} else {
|
|
677
|
+
major = m20 >= m02 ? vector(1, 0) : vector(0, 1);
|
|
678
|
+
}
|
|
679
|
+
return {
|
|
680
|
+
centroid: c,
|
|
681
|
+
major,
|
|
682
|
+
minor: vectorNormal(major),
|
|
683
|
+
majorVariance,
|
|
684
|
+
minorVariance
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
function principalCoords(points, axes, scale = 1) {
|
|
688
|
+
const { centroid: c, major, minor } = axes;
|
|
689
|
+
return points.map(([x, y]) => {
|
|
690
|
+
const dx = x - c[0];
|
|
691
|
+
const dy = y - c[1];
|
|
692
|
+
return [
|
|
693
|
+
(dx * major[0] + dy * major[1]) * scale,
|
|
694
|
+
(dx * minor[0] + dy * minor[1]) * scale
|
|
695
|
+
];
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
function orientPrincipalAxes(points, axes) {
|
|
699
|
+
const u = principalCoords(points, axes).map(([uu]) => uu);
|
|
700
|
+
if (skewness(u) <= 0) {
|
|
701
|
+
return axes;
|
|
702
|
+
}
|
|
703
|
+
const major = vectorScale(axes.major, -1);
|
|
704
|
+
return { ...axes, major, minor: vectorNormal(major) };
|
|
705
|
+
}
|
|
706
|
+
function elongation(axes) {
|
|
707
|
+
return axes.majorVariance > 0 ? axes.minorVariance / axes.majorVariance : 1;
|
|
708
|
+
}
|
|
709
|
+
function standardizedMoment(values, order) {
|
|
710
|
+
const n = values.length;
|
|
711
|
+
let mean = 0;
|
|
712
|
+
for (const v of values) {
|
|
713
|
+
mean += v;
|
|
714
|
+
}
|
|
715
|
+
mean /= n;
|
|
716
|
+
let variance = 0;
|
|
717
|
+
let moment = 0;
|
|
718
|
+
for (const v of values) {
|
|
719
|
+
const d = v - mean;
|
|
720
|
+
variance += d * d;
|
|
721
|
+
moment += d ** order;
|
|
722
|
+
}
|
|
723
|
+
variance /= n;
|
|
724
|
+
moment /= n;
|
|
725
|
+
const sigma = Math.sqrt(variance);
|
|
726
|
+
return sigma > Number.EPSILON ? moment / sigma ** order : 0;
|
|
727
|
+
}
|
|
728
|
+
function skewness(values) {
|
|
729
|
+
return standardizedMoment(values, 3);
|
|
730
|
+
}
|
|
731
|
+
function kurtosis(values) {
|
|
732
|
+
return standardizedMoment(values, 4);
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
// src/polygon.ts
|
|
736
|
+
function polygon(...points) {
|
|
737
|
+
return polygonClose(points);
|
|
738
|
+
}
|
|
739
|
+
function polygonFromPoints(points) {
|
|
740
|
+
return polygonClose(points);
|
|
741
|
+
}
|
|
742
|
+
var polygonIncludesPoint = (point, polygon2) => {
|
|
743
|
+
const x = point[0];
|
|
744
|
+
const y = point[1];
|
|
745
|
+
let inside = false;
|
|
746
|
+
for (let i = 0, j = polygon2.length - 1; i < polygon2.length; j = i++) {
|
|
747
|
+
const xi = polygon2[i][0];
|
|
748
|
+
const yi = polygon2[i][1];
|
|
749
|
+
const xj = polygon2[j][0];
|
|
750
|
+
const yj = polygon2[j][1];
|
|
751
|
+
if ((yi > y && yj <= y || yi <= y && yj > y) && x < (xj - xi) * (y - yi) / (yj - yi) + xi) {
|
|
752
|
+
inside = !inside;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
return inside;
|
|
756
|
+
};
|
|
757
|
+
var polygonIncludesPointNonZero = (point, polygon2) => {
|
|
758
|
+
const [x, y] = point;
|
|
759
|
+
let windingNumber = 0;
|
|
760
|
+
for (let i = 0; i < polygon2.length; i++) {
|
|
761
|
+
const j = (i + 1) % polygon2.length;
|
|
762
|
+
const [xi, yi] = polygon2[i];
|
|
763
|
+
const [xj, yj] = polygon2[j];
|
|
764
|
+
if (yi <= y) {
|
|
765
|
+
if (yj > y) {
|
|
766
|
+
if ((xj - xi) * (y - yi) - (x - xi) * (yj - yi) > 0) {
|
|
767
|
+
windingNumber++;
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
} else if (yj <= y) {
|
|
771
|
+
if ((xj - xi) * (y - yi) - (x - xi) * (yj - yi) < 0) {
|
|
772
|
+
windingNumber--;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
return windingNumber !== 0;
|
|
777
|
+
};
|
|
778
|
+
function polygonClose(polygon2) {
|
|
779
|
+
return polygonIsClosed(polygon2) ? polygon2 : [...polygon2, polygon2[0]];
|
|
780
|
+
}
|
|
781
|
+
function polygonIsClosed(polygon2, tolerance = PRECISION) {
|
|
782
|
+
return pointsEqual(polygon2[0], polygon2[polygon2.length - 1], tolerance);
|
|
783
|
+
}
|
|
784
|
+
function polygonSignedArea(polygon2) {
|
|
785
|
+
const pts = polygonIsClosed(polygon2) ? polygon2.slice(0, -1) : polygon2;
|
|
786
|
+
let sum = 0;
|
|
787
|
+
for (let i = 0, j = pts.length - 1; i < pts.length; j = i++) {
|
|
788
|
+
sum += pts[j][0] * pts[i][1] - pts[i][0] * pts[j][1];
|
|
789
|
+
}
|
|
790
|
+
return sum / 2;
|
|
791
|
+
}
|
|
792
|
+
function polygonArea(polygon2) {
|
|
793
|
+
return Math.abs(polygonSignedArea(polygon2));
|
|
794
|
+
}
|
|
795
|
+
function convexHull(points) {
|
|
796
|
+
if (points.length < 3) {
|
|
797
|
+
return [...points];
|
|
798
|
+
}
|
|
799
|
+
const sorted = [...points].sort(
|
|
800
|
+
(a, b) => a[0] === b[0] ? a[1] - b[1] : a[0] - b[0]
|
|
801
|
+
);
|
|
802
|
+
const cross = (o, a, b) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);
|
|
803
|
+
const half = (pts) => {
|
|
804
|
+
const chain = [];
|
|
805
|
+
for (const p of pts) {
|
|
806
|
+
while (chain.length >= 2 && cross(chain[chain.length - 2], chain[chain.length - 1], p) <= 0) {
|
|
807
|
+
chain.pop();
|
|
808
|
+
}
|
|
809
|
+
chain.push(p);
|
|
810
|
+
}
|
|
811
|
+
chain.pop();
|
|
812
|
+
return chain;
|
|
813
|
+
};
|
|
814
|
+
const hull = [...half(sorted), ...half([...sorted].reverse())];
|
|
815
|
+
return hull.length >= 3 ? hull : [...points];
|
|
816
|
+
}
|
|
817
|
+
function simplifyConvexPolygon(polygon2, angleThreshold) {
|
|
818
|
+
if (polygon2.length < 3) {
|
|
819
|
+
return [...polygon2];
|
|
820
|
+
}
|
|
821
|
+
const turnAt = (i) => {
|
|
822
|
+
const prev = polygon2[(i - 1 + polygon2.length) % polygon2.length];
|
|
823
|
+
const curr = polygon2[i];
|
|
824
|
+
const next = polygon2[(i + 1) % polygon2.length];
|
|
825
|
+
const inAngle = Math.atan2(curr[1] - prev[1], curr[0] - prev[0]);
|
|
826
|
+
const outAngle = Math.atan2(next[1] - curr[1], next[0] - curr[0]);
|
|
827
|
+
return Math.abs(normalizeTurn(outAngle - inAngle));
|
|
828
|
+
};
|
|
829
|
+
let start = 0;
|
|
830
|
+
for (let i = 1; i < polygon2.length; i++) {
|
|
831
|
+
if (turnAt(i) > turnAt(start)) {
|
|
832
|
+
start = i;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
const simplified = [];
|
|
836
|
+
let accumulated = 0;
|
|
837
|
+
for (let k = 0; k < polygon2.length; k++) {
|
|
838
|
+
const i = (start + k) % polygon2.length;
|
|
839
|
+
accumulated += turnAt(i);
|
|
840
|
+
if (accumulated >= angleThreshold) {
|
|
841
|
+
simplified.push(polygon2[i]);
|
|
842
|
+
accumulated = 0;
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
return simplified.length >= 3 ? simplified : [...polygon2];
|
|
846
|
+
}
|
|
847
|
+
function normalizeTurn(angle) {
|
|
848
|
+
let a = angle;
|
|
849
|
+
while (a > Math.PI) {
|
|
850
|
+
a -= 2 * Math.PI;
|
|
851
|
+
}
|
|
852
|
+
while (a < -Math.PI) {
|
|
853
|
+
a += 2 * Math.PI;
|
|
854
|
+
}
|
|
855
|
+
return a;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
// src/range.ts
|
|
859
|
+
import { toBrandedType } from "@excalidraw/common";
|
|
860
|
+
function rangeInclusive(start, end) {
|
|
861
|
+
return toBrandedType([start, end]);
|
|
862
|
+
}
|
|
863
|
+
function rangeInclusiveFromPair(pair) {
|
|
864
|
+
return toBrandedType(pair);
|
|
865
|
+
}
|
|
866
|
+
var rangesOverlap = ([a0, a1], [b0, b1]) => {
|
|
867
|
+
if (a0 <= b0) {
|
|
868
|
+
return a1 >= b0;
|
|
869
|
+
}
|
|
870
|
+
if (a0 >= b0) {
|
|
871
|
+
return b1 >= a0;
|
|
872
|
+
}
|
|
873
|
+
return false;
|
|
874
|
+
};
|
|
875
|
+
var rangeIntersection = ([a0, a1], [b0, b1]) => {
|
|
876
|
+
const rangeStart = Math.max(a0, b0);
|
|
877
|
+
const rangeEnd = Math.min(a1, b1);
|
|
878
|
+
if (rangeStart <= rangeEnd) {
|
|
879
|
+
return toBrandedType([rangeStart, rangeEnd]);
|
|
880
|
+
}
|
|
881
|
+
return null;
|
|
882
|
+
};
|
|
883
|
+
var rangeIncludesValue = (value, [min, max]) => {
|
|
884
|
+
return value >= min && value <= max;
|
|
885
|
+
};
|
|
886
|
+
|
|
608
887
|
// src/segment.ts
|
|
609
888
|
function lineSegment(a, b) {
|
|
610
889
|
return [a, b];
|
|
611
890
|
}
|
|
612
|
-
var isLineSegment = (segment) => Array.isArray(segment) && segment.length === 2 && isPoint(segment[0]) && isPoint(segment[
|
|
891
|
+
var isLineSegment = (segment) => Array.isArray(segment) && segment.length === 2 && isPoint(segment[0]) && isPoint(segment[1]);
|
|
613
892
|
var lineSegmentRotate = (l, angle, origin) => {
|
|
614
893
|
return lineSegment(
|
|
615
894
|
pointRotateRads(l[0], origin || pointCenter(l[0], l[1]), angle),
|
|
@@ -694,95 +973,6 @@ function lineSegmentsDistance(s1, s2) {
|
|
|
694
973
|
);
|
|
695
974
|
}
|
|
696
975
|
|
|
697
|
-
// src/polygon.ts
|
|
698
|
-
function polygon(...points) {
|
|
699
|
-
return polygonClose(points);
|
|
700
|
-
}
|
|
701
|
-
function polygonFromPoints(points) {
|
|
702
|
-
return polygonClose(points);
|
|
703
|
-
}
|
|
704
|
-
var polygonIncludesPoint = (point, polygon2) => {
|
|
705
|
-
const x = point[0];
|
|
706
|
-
const y = point[1];
|
|
707
|
-
let inside = false;
|
|
708
|
-
for (let i = 0, j = polygon2.length - 1; i < polygon2.length; j = i++) {
|
|
709
|
-
const xi = polygon2[i][0];
|
|
710
|
-
const yi = polygon2[i][1];
|
|
711
|
-
const xj = polygon2[j][0];
|
|
712
|
-
const yj = polygon2[j][1];
|
|
713
|
-
if ((yi > y && yj <= y || yi <= y && yj > y) && x < (xj - xi) * (y - yi) / (yj - yi) + xi) {
|
|
714
|
-
inside = !inside;
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
return inside;
|
|
718
|
-
};
|
|
719
|
-
var polygonIncludesPointNonZero = (point, polygon2) => {
|
|
720
|
-
const [x, y] = point;
|
|
721
|
-
let windingNumber = 0;
|
|
722
|
-
for (let i = 0; i < polygon2.length; i++) {
|
|
723
|
-
const j = (i + 1) % polygon2.length;
|
|
724
|
-
const [xi, yi] = polygon2[i];
|
|
725
|
-
const [xj, yj] = polygon2[j];
|
|
726
|
-
if (yi <= y) {
|
|
727
|
-
if (yj > y) {
|
|
728
|
-
if ((xj - xi) * (y - yi) - (x - xi) * (yj - yi) > 0) {
|
|
729
|
-
windingNumber++;
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
} else if (yj <= y) {
|
|
733
|
-
if ((xj - xi) * (y - yi) - (x - xi) * (yj - yi) < 0) {
|
|
734
|
-
windingNumber--;
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
return windingNumber !== 0;
|
|
739
|
-
};
|
|
740
|
-
var pointOnPolygon = (p, poly, threshold = PRECISION) => {
|
|
741
|
-
let on = false;
|
|
742
|
-
for (let i = 0, l = poly.length - 1; i < l; i++) {
|
|
743
|
-
if (pointOnLineSegment(p, lineSegment(poly[i], poly[i + 1]), threshold)) {
|
|
744
|
-
on = true;
|
|
745
|
-
break;
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
return on;
|
|
749
|
-
};
|
|
750
|
-
function polygonClose(polygon2) {
|
|
751
|
-
return polygonIsClosed(polygon2) ? polygon2 : [...polygon2, polygon2[0]];
|
|
752
|
-
}
|
|
753
|
-
function polygonIsClosed(polygon2) {
|
|
754
|
-
return pointsEqual(polygon2[0], polygon2[polygon2.length - 1]);
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
// src/range.ts
|
|
758
|
-
import { toBrandedType } from "@excalidraw/common";
|
|
759
|
-
function rangeInclusive(start, end) {
|
|
760
|
-
return toBrandedType([start, end]);
|
|
761
|
-
}
|
|
762
|
-
function rangeInclusiveFromPair(pair) {
|
|
763
|
-
return toBrandedType(pair);
|
|
764
|
-
}
|
|
765
|
-
var rangesOverlap = ([a0, a1], [b0, b1]) => {
|
|
766
|
-
if (a0 <= b0) {
|
|
767
|
-
return a1 >= b0;
|
|
768
|
-
}
|
|
769
|
-
if (a0 >= b0) {
|
|
770
|
-
return b1 >= a0;
|
|
771
|
-
}
|
|
772
|
-
return false;
|
|
773
|
-
};
|
|
774
|
-
var rangeIntersection = ([a0, a1], [b0, b1]) => {
|
|
775
|
-
const rangeStart = Math.max(a0, b0);
|
|
776
|
-
const rangeEnd = Math.min(a1, b1);
|
|
777
|
-
if (rangeStart <= rangeEnd) {
|
|
778
|
-
return toBrandedType([rangeStart, rangeEnd]);
|
|
779
|
-
}
|
|
780
|
-
return null;
|
|
781
|
-
};
|
|
782
|
-
var rangeIncludesValue = (value, [min, max]) => {
|
|
783
|
-
return value >= min && value <= max;
|
|
784
|
-
};
|
|
785
|
-
|
|
786
976
|
// src/rectangle.ts
|
|
787
977
|
function rectangle(topLeft, bottomRight) {
|
|
788
978
|
return [topLeft, bottomRight];
|
|
@@ -819,7 +1009,9 @@ export {
|
|
|
819
1009
|
average,
|
|
820
1010
|
bezierEquation,
|
|
821
1011
|
cartesian2Polar,
|
|
1012
|
+
centroid,
|
|
822
1013
|
clamp,
|
|
1014
|
+
convexHull,
|
|
823
1015
|
curve,
|
|
824
1016
|
curveCatmullRomCubicApproxPoints,
|
|
825
1017
|
curveCatmullRomQuadraticApproxPoints,
|
|
@@ -839,6 +1031,7 @@ export {
|
|
|
839
1031
|
ellipseLineIntersectionPoints,
|
|
840
1032
|
ellipseSegmentInterceptPoints,
|
|
841
1033
|
ellipseTouchesPoint,
|
|
1034
|
+
elongation,
|
|
842
1035
|
isCloseTo,
|
|
843
1036
|
isCurve,
|
|
844
1037
|
isFiniteNumber,
|
|
@@ -846,7 +1039,9 @@ export {
|
|
|
846
1039
|
isPoint,
|
|
847
1040
|
isPointWithinBounds,
|
|
848
1041
|
isRightAngleRads,
|
|
1042
|
+
isValidPoint,
|
|
849
1043
|
isVector,
|
|
1044
|
+
kurtosis,
|
|
850
1045
|
line,
|
|
851
1046
|
lineSegment,
|
|
852
1047
|
lineSegmentIntersectionPoints,
|
|
@@ -855,6 +1050,7 @@ export {
|
|
|
855
1050
|
linesIntersectAt,
|
|
856
1051
|
normalizeRadians,
|
|
857
1052
|
offsetPointsForQuadraticBezier,
|
|
1053
|
+
orientPrincipalAxes,
|
|
858
1054
|
pointCenter,
|
|
859
1055
|
pointDistance,
|
|
860
1056
|
pointDistanceSq,
|
|
@@ -863,16 +1059,20 @@ export {
|
|
|
863
1059
|
pointFromPair,
|
|
864
1060
|
pointFromVector,
|
|
865
1061
|
pointOnLineSegment,
|
|
866
|
-
pointOnPolygon,
|
|
867
1062
|
pointRotateDegs,
|
|
868
1063
|
pointRotateRads,
|
|
869
1064
|
pointScaleFromOrigin,
|
|
870
1065
|
pointTranslate,
|
|
871
1066
|
pointsEqual,
|
|
872
1067
|
polygon,
|
|
1068
|
+
polygonArea,
|
|
873
1069
|
polygonFromPoints,
|
|
874
1070
|
polygonIncludesPoint,
|
|
875
1071
|
polygonIncludesPointNonZero,
|
|
1072
|
+
polygonIsClosed,
|
|
1073
|
+
polygonSignedArea,
|
|
1074
|
+
principalAxes,
|
|
1075
|
+
principalCoords,
|
|
876
1076
|
radiansBetweenAngles,
|
|
877
1077
|
radiansDifference,
|
|
878
1078
|
radiansToDegrees,
|
|
@@ -888,6 +1088,9 @@ export {
|
|
|
888
1088
|
round,
|
|
889
1089
|
roundToStep,
|
|
890
1090
|
segmentsIntersectAt,
|
|
1091
|
+
simplifyConvexPolygon,
|
|
1092
|
+
skewness,
|
|
1093
|
+
standardizedMoment,
|
|
891
1094
|
triangleIncludesPoint,
|
|
892
1095
|
vector,
|
|
893
1096
|
vectorAdd,
|