@excalidraw/math 0.18.0-6135548 → 0.18.0-699826
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 +150 -130
- package/dist/dev/index.js.map +4 -4
- package/dist/prod/index.js +1 -1
- package/dist/types/common/debug.d.ts +21 -0
- package/dist/types/common/src/appEventBus.d.ts +27 -0
- package/dist/types/common/src/colors.d.ts +2 -2
- package/dist/types/common/src/constants.d.ts +5 -2
- package/dist/types/common/src/index.d.ts +3 -0
- package/dist/types/common/src/utils.d.ts +4 -7
- package/dist/types/common/src/versionedSnapshotStore.d.ts +17 -0
- package/dist/types/element/src/Scene.d.ts +7 -3
- package/dist/types/element/src/arrowheads.d.ts +3 -0
- package/dist/types/element/src/arrows/focus.d.ts +27 -0
- package/dist/types/element/src/arrows/helpers.d.ts +5 -0
- package/dist/types/element/src/binding.d.ts +13 -8
- package/dist/types/element/src/bounds.d.ts +22 -3
- package/dist/types/element/src/collision.d.ts +4 -3
- package/dist/types/element/src/distribute.d.ts +2 -1
- package/dist/types/element/src/duplicate.d.ts +1 -0
- package/dist/types/element/src/elbowArrow.d.ts +2 -0
- package/dist/types/element/src/frame.d.ts +7 -6
- package/dist/types/element/src/index.d.ts +3 -0
- package/dist/types/element/src/linearElementEditor.d.ts +7 -2
- package/dist/types/element/src/mutateElement.d.ts +2 -0
- package/dist/types/element/src/selection.d.ts +7 -3
- package/dist/types/element/src/shape.d.ts +1 -1
- package/dist/types/element/src/textElement.d.ts +1 -1
- package/dist/types/element/src/textWrapping.d.ts +26 -0
- package/dist/types/element/src/typeChecks.d.ts +1 -0
- package/dist/types/element/src/types.d.ts +5 -2
- package/dist/types/element/src/utils.d.ts +6 -4
- package/dist/types/element/src/zindex.d.ts +1 -1
- package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +41 -38
- package/dist/types/excalidraw/actions/actionBoundText.d.ts +29 -27
- package/dist/types/excalidraw/actions/actionCanvas.d.ts +169 -157
- package/dist/types/excalidraw/actions/actionClipboard.d.ts +28 -26
- package/dist/types/excalidraw/actions/actionCropEditor.d.ts +14 -13
- package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +44 -39
- package/dist/types/excalidraw/actions/actionDeselect.d.ts +159 -0
- package/dist/types/excalidraw/actions/actionElementLink.d.ts +10 -13
- package/dist/types/excalidraw/actions/actionElementLock.d.ts +28 -26
- package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +14 -13
- package/dist/types/excalidraw/actions/actionExport.d.ts +77 -349
- package/dist/types/excalidraw/actions/actionFrame.d.ts +56 -52
- package/dist/types/excalidraw/actions/actionGroup.d.ts +29 -27
- package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +16 -13
- package/dist/types/excalidraw/actions/actionLink.d.ts +14 -13
- package/dist/types/excalidraw/actions/actionMenu.d.ts +10 -13
- package/dist/types/excalidraw/actions/actionProperties.d.ts +30 -28
- package/dist/types/excalidraw/actions/actionSelectAll.d.ts +14 -13
- package/dist/types/excalidraw/actions/actionStyles.d.ts +14 -12
- package/dist/types/excalidraw/actions/actionTextAutoResize.d.ts +3 -3
- package/dist/types/excalidraw/actions/actionToggleArrowBinding.d.ts +172 -0
- package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +14 -13
- package/dist/types/excalidraw/actions/actionToggleMidpointSnapping.d.ts +172 -0
- package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +14 -13
- package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +10 -13
- package/dist/types/excalidraw/actions/actionToggleStats.d.ts +14 -13
- package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +14 -13
- package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +14 -13
- package/dist/types/excalidraw/actions/index.d.ts +3 -0
- package/dist/types/excalidraw/actions/shortcuts.d.ts +1 -1
- package/dist/types/excalidraw/actions/types.d.ts +1 -1
- package/dist/types/excalidraw/{animated-trail.d.ts → animatedTrail.d.ts} +4 -3
- package/dist/types/excalidraw/appState.d.ts +10 -7
- package/dist/types/excalidraw/charts/charts.bar.d.ts +2 -0
- package/dist/types/excalidraw/charts/charts.constants.d.ts +48 -0
- package/dist/types/excalidraw/charts/charts.helpers.d.ts +32 -0
- package/dist/types/excalidraw/charts/charts.line.d.ts +2 -0
- package/dist/types/excalidraw/charts/charts.parse.d.ts +10 -0
- package/dist/types/excalidraw/charts/charts.radar.d.ts +2 -0
- package/dist/types/excalidraw/charts/charts.types.d.ts +18 -0
- package/dist/types/excalidraw/charts/index.d.ts +7 -0
- package/dist/types/excalidraw/clipboard.d.ts +6 -7
- package/dist/types/excalidraw/components/App.d.ts +63 -16
- package/dist/types/excalidraw/components/AppStateObserver.d.ts +37 -0
- package/dist/types/excalidraw/components/CommandPalette/defaultCommandPaletteItems.d.ts +1 -2
- package/dist/types/excalidraw/components/CommandPalette/types.d.ts +1 -1
- package/dist/types/excalidraw/components/IconPicker.d.ts +14 -9
- package/dist/types/excalidraw/components/PasteChartDialog.d.ts +4 -5
- package/dist/types/excalidraw/components/PropertiesPopover.d.ts +1 -1
- 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/TTDDialog/Chat/ChatInterface.d.ts +2 -6
- package/dist/types/excalidraw/components/TTDDialog/Chat/TTDChatPanel.d.ts +2 -1
- package/dist/types/excalidraw/components/TTDDialog/CodeMirrorEditor.d.ts +11 -0
- package/dist/types/excalidraw/components/TTDDialog/TTDDialog.d.ts +11 -7
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogInput.d.ts +3 -3
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogOutput.d.ts +4 -1
- package/dist/types/excalidraw/components/TTDDialog/TTDWelcomeMessage.d.ts +1 -0
- package/dist/types/excalidraw/components/TTDDialog/TextToDiagram.d.ts +2 -1
- package/dist/types/excalidraw/components/TTDDialog/mermaid-lang-lite.d.ts +2 -0
- package/dist/types/excalidraw/components/TTDDialog/types.d.ts +4 -0
- package/dist/types/excalidraw/components/TTDDialog/utils/mermaidAutoFix.d.ts +1 -0
- package/dist/types/excalidraw/components/TTDDialog/utils/mermaidError.d.ts +10 -0
- package/dist/types/excalidraw/components/Toast.d.ts +8 -4
- package/dist/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +2 -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/DropdownMenu.d.ts +30 -17
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuContent.d.ts +3 -2
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItem.d.ts +11 -13
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemCheckbox.d.ts +5 -0
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemContentRadio.d.ts +2 -1
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuSub.d.ts +23 -0
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuSubContent.d.ts +8 -0
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuSubTrigger.d.ts +12 -0
- package/dist/types/excalidraw/components/dropdownMenu/common.d.ts +1 -1
- package/dist/types/excalidraw/components/dropdownMenu/dropdownMenuUtils.d.ts +2 -0
- package/dist/types/excalidraw/components/icons.d.ts +23 -9
- package/dist/types/excalidraw/components/main-menu/DefaultItems.d.ts +24 -3
- package/dist/types/excalidraw/components/main-menu/MainMenu.d.ts +23 -13
- package/dist/types/excalidraw/components/shapes.d.ts +81 -1
- package/dist/types/excalidraw/data/blob.d.ts +47 -46
- package/dist/types/excalidraw/data/filesystem.d.ts +3 -5
- package/dist/types/excalidraw/data/index.d.ts +2 -3
- package/dist/types/excalidraw/data/json.d.ts +37 -28
- package/dist/types/excalidraw/data/resave.d.ts +7 -2
- package/dist/types/excalidraw/eraser/index.d.ts +2 -3
- 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 +4 -1
- package/dist/types/excalidraw/scene/Renderer.d.ts +425 -19
- package/dist/types/excalidraw/textAutoResizeHandle.d.ts +15 -0
- package/dist/types/excalidraw/types.d.ts +116 -18
- package/dist/types/excalidraw/wysiwyg/textWysiwyg.d.ts +5 -1
- package/dist/types/fractional-indexing/src/index.d.ts +29 -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/point.d.ts +8 -2
- package/dist/types/math/src/types.d.ts +25 -1
- 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/charts.d.ts +0 -27
- package/dist/types/excalidraw/components/DiagramToCodePlugin/DiagramToCodePlugin.d.ts +0 -4
- package/dist/types/excalidraw/components/ExcalidrawLogo.d.ts +0 -15
- package/dist/types/excalidraw/components/InitializeApp.d.ts +0 -10
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogTrigger.d.ts +0 -8
- package/dist/types/excalidraw/components/TTDDialog/utils/TTDStreamFetch.d.ts +0 -24
- package/dist/types/excalidraw/components/footer/FooterCenter.d.ts +0 -8
- package/dist/types/excalidraw/components/live-collaboration/LiveCollaborationTrigger.d.ts +0 -11
- package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.Center.d.ts +0 -58
- package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.Hints.d.ts +0 -19
- package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.d.ts +0 -84
- package/dist/types/excalidraw/data/reconcile.d.ts +0 -7
- package/dist/types/excalidraw/index.d.ts +0 -46
- package/dist/types/excalidraw/polyfill.d.ts +0 -2
- 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
|
@@ -101,8 +101,8 @@ var vectorNormalize = (v) => {
|
|
|
101
101
|
var vectorNormal = (v) => vector(v[1], -v[0]);
|
|
102
102
|
|
|
103
103
|
// src/point.ts
|
|
104
|
-
function pointFrom(
|
|
105
|
-
return [x, y];
|
|
104
|
+
function pointFrom(xOrCoords, y) {
|
|
105
|
+
return typeof xOrCoords === "object" ? [xOrCoords.x, xOrCoords.y] : [xOrCoords, y];
|
|
106
106
|
}
|
|
107
107
|
function pointFromArray(numberArray) {
|
|
108
108
|
return numberArray.length === 2 ? pointFrom(numberArray[0], numberArray[1]) : void 0;
|
|
@@ -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 = [
|
|
@@ -202,113 +210,6 @@ var LegendreGaussN24CValues = [
|
|
|
202
210
|
0.0123412297999872
|
|
203
211
|
];
|
|
204
212
|
|
|
205
|
-
// src/line.ts
|
|
206
|
-
function line(a, b) {
|
|
207
|
-
return [a, b];
|
|
208
|
-
}
|
|
209
|
-
function linesIntersectAt(a, b) {
|
|
210
|
-
const A1 = a[1][1] - a[0][1];
|
|
211
|
-
const B1 = a[0][0] - a[1][0];
|
|
212
|
-
const A2 = b[1][1] - b[0][1];
|
|
213
|
-
const B2 = b[0][0] - b[1][0];
|
|
214
|
-
const D = A1 * B2 - A2 * B1;
|
|
215
|
-
if (D !== 0) {
|
|
216
|
-
const C1 = A1 * a[0][0] + B1 * a[0][1];
|
|
217
|
-
const C2 = A2 * b[0][0] + B2 * b[0][1];
|
|
218
|
-
return pointFrom((C1 * B2 - C2 * B1) / D, (A1 * C2 - A2 * C1) / D);
|
|
219
|
-
}
|
|
220
|
-
return null;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// src/segment.ts
|
|
224
|
-
function lineSegment(a, b) {
|
|
225
|
-
return [a, b];
|
|
226
|
-
}
|
|
227
|
-
var isLineSegment = (segment) => Array.isArray(segment) && segment.length === 2 && isPoint(segment[0]) && isPoint(segment[0]);
|
|
228
|
-
var lineSegmentRotate = (l, angle, origin) => {
|
|
229
|
-
return lineSegment(
|
|
230
|
-
pointRotateRads(l[0], origin || pointCenter(l[0], l[1]), angle),
|
|
231
|
-
pointRotateRads(l[1], origin || pointCenter(l[0], l[1]), angle)
|
|
232
|
-
);
|
|
233
|
-
};
|
|
234
|
-
var segmentsIntersectAt = (a, b) => {
|
|
235
|
-
const a0 = vectorFromPoint(a[0]);
|
|
236
|
-
const a1 = vectorFromPoint(a[1]);
|
|
237
|
-
const b0 = vectorFromPoint(b[0]);
|
|
238
|
-
const b1 = vectorFromPoint(b[1]);
|
|
239
|
-
const r = vectorSubtract(a1, a0);
|
|
240
|
-
const s = vectorSubtract(b1, b0);
|
|
241
|
-
const denominator = vectorCross(r, s);
|
|
242
|
-
if (denominator === 0) {
|
|
243
|
-
return null;
|
|
244
|
-
}
|
|
245
|
-
const i = vectorSubtract(vectorFromPoint(b[0]), vectorFromPoint(a[0]));
|
|
246
|
-
const u = vectorCross(i, r) / denominator;
|
|
247
|
-
const t = vectorCross(i, s) / denominator;
|
|
248
|
-
if (u === 0) {
|
|
249
|
-
return null;
|
|
250
|
-
}
|
|
251
|
-
const p = vectorAdd(a0, vectorScale(r, t));
|
|
252
|
-
if (t >= 0 && t < 1 && u >= 0 && u < 1) {
|
|
253
|
-
return pointFromVector(p);
|
|
254
|
-
}
|
|
255
|
-
return null;
|
|
256
|
-
};
|
|
257
|
-
var pointOnLineSegment = (point, line2, threshold = PRECISION) => {
|
|
258
|
-
const distance = distanceToLineSegment(point, line2);
|
|
259
|
-
if (distance === 0) {
|
|
260
|
-
return true;
|
|
261
|
-
}
|
|
262
|
-
return distance < threshold;
|
|
263
|
-
};
|
|
264
|
-
var distanceToLineSegment = (point, line2) => {
|
|
265
|
-
const [x, y] = point;
|
|
266
|
-
const [[x1, y1], [x2, y2]] = line2;
|
|
267
|
-
const A = x - x1;
|
|
268
|
-
const B = y - y1;
|
|
269
|
-
const C = x2 - x1;
|
|
270
|
-
const D = y2 - y1;
|
|
271
|
-
const dot = A * C + B * D;
|
|
272
|
-
const len_sq = C * C + D * D;
|
|
273
|
-
let param = -1;
|
|
274
|
-
if (len_sq !== 0) {
|
|
275
|
-
param = dot / len_sq;
|
|
276
|
-
}
|
|
277
|
-
let xx;
|
|
278
|
-
let yy;
|
|
279
|
-
if (param < 0) {
|
|
280
|
-
xx = x1;
|
|
281
|
-
yy = y1;
|
|
282
|
-
} else if (param > 1) {
|
|
283
|
-
xx = x2;
|
|
284
|
-
yy = y2;
|
|
285
|
-
} else {
|
|
286
|
-
xx = x1 + param * C;
|
|
287
|
-
yy = y1 + param * D;
|
|
288
|
-
}
|
|
289
|
-
const dx = x - xx;
|
|
290
|
-
const dy = y - yy;
|
|
291
|
-
return Math.sqrt(dx * dx + dy * dy);
|
|
292
|
-
};
|
|
293
|
-
function lineSegmentIntersectionPoints(l, s, threshold) {
|
|
294
|
-
const candidate = linesIntersectAt(line(l[0], l[1]), line(s[0], s[1]));
|
|
295
|
-
if (!candidate || !pointOnLineSegment(candidate, s, threshold) || !pointOnLineSegment(candidate, l, threshold)) {
|
|
296
|
-
return null;
|
|
297
|
-
}
|
|
298
|
-
return candidate;
|
|
299
|
-
}
|
|
300
|
-
function lineSegmentsDistance(s1, s2) {
|
|
301
|
-
if (lineSegmentIntersectionPoints(s1, s2)) {
|
|
302
|
-
return 0;
|
|
303
|
-
}
|
|
304
|
-
return Math.min(
|
|
305
|
-
distanceToLineSegment(s1[0], s2),
|
|
306
|
-
distanceToLineSegment(s1[1], s2),
|
|
307
|
-
distanceToLineSegment(s2[0], s1),
|
|
308
|
-
distanceToLineSegment(s2[1], s1)
|
|
309
|
-
);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
213
|
// src/curve.ts
|
|
313
214
|
function curve(a, b, c, d) {
|
|
314
215
|
return [a, b, c, d];
|
|
@@ -361,8 +262,15 @@ var initial_guesses = [
|
|
|
361
262
|
[0.2, 0],
|
|
362
263
|
[0.8, 0]
|
|
363
264
|
];
|
|
364
|
-
var calculate = ([t0, s0], l, c) => {
|
|
365
|
-
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
|
+
);
|
|
366
274
|
if (!solution) {
|
|
367
275
|
return null;
|
|
368
276
|
}
|
|
@@ -372,33 +280,37 @@ var calculate = ([t0, s0], l, c) => {
|
|
|
372
280
|
}
|
|
373
281
|
return bezierEquation(c, t);
|
|
374
282
|
};
|
|
375
|
-
function curveIntersectLineSegment(c, l) {
|
|
376
|
-
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
|
+
);
|
|
377
291
|
if (solution) {
|
|
378
292
|
return [solution];
|
|
379
293
|
}
|
|
380
|
-
solution = calculate(
|
|
294
|
+
solution = calculate(
|
|
295
|
+
initial_guesses[1],
|
|
296
|
+
l,
|
|
297
|
+
c,
|
|
298
|
+
opts?.tolerance,
|
|
299
|
+
opts?.iterLimit
|
|
300
|
+
);
|
|
381
301
|
if (solution) {
|
|
382
302
|
return [solution];
|
|
383
303
|
}
|
|
384
|
-
solution = calculate(
|
|
304
|
+
solution = calculate(
|
|
305
|
+
initial_guesses[2],
|
|
306
|
+
l,
|
|
307
|
+
c,
|
|
308
|
+
opts?.tolerance,
|
|
309
|
+
opts?.iterLimit
|
|
310
|
+
);
|
|
385
311
|
if (solution) {
|
|
386
312
|
return [solution];
|
|
387
313
|
}
|
|
388
|
-
const startHit = lineSegmentIntersectionPoints(
|
|
389
|
-
lineSegment(bezierEquation(c, 0), bezierEquation(c, 1 / 20)),
|
|
390
|
-
l
|
|
391
|
-
);
|
|
392
|
-
if (startHit) {
|
|
393
|
-
return [startHit];
|
|
394
|
-
}
|
|
395
|
-
const endHit = lineSegmentIntersectionPoints(
|
|
396
|
-
lineSegment(bezierEquation(c, 19 / 20), bezierEquation(c, 1)),
|
|
397
|
-
l
|
|
398
|
-
);
|
|
399
|
-
if (endHit) {
|
|
400
|
-
return [endHit];
|
|
401
|
-
}
|
|
402
314
|
return [];
|
|
403
315
|
}
|
|
404
316
|
function curveClosestPoint(c, p, tolerance = 1e-3) {
|
|
@@ -708,6 +620,113 @@ function ellipseLineIntersectionPoints({ center, halfWidth, halfHeight }, [g, h]
|
|
|
708
620
|
return candidates;
|
|
709
621
|
}
|
|
710
622
|
|
|
623
|
+
// src/line.ts
|
|
624
|
+
function line(a, b) {
|
|
625
|
+
return [a, b];
|
|
626
|
+
}
|
|
627
|
+
function linesIntersectAt(a, b) {
|
|
628
|
+
const A1 = a[1][1] - a[0][1];
|
|
629
|
+
const B1 = a[0][0] - a[1][0];
|
|
630
|
+
const A2 = b[1][1] - b[0][1];
|
|
631
|
+
const B2 = b[0][0] - b[1][0];
|
|
632
|
+
const D = A1 * B2 - A2 * B1;
|
|
633
|
+
if (D !== 0) {
|
|
634
|
+
const C1 = A1 * a[0][0] + B1 * a[0][1];
|
|
635
|
+
const C2 = A2 * b[0][0] + B2 * b[0][1];
|
|
636
|
+
return pointFrom((C1 * B2 - C2 * B1) / D, (A1 * C2 - A2 * C1) / D);
|
|
637
|
+
}
|
|
638
|
+
return null;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
// src/segment.ts
|
|
642
|
+
function lineSegment(a, b) {
|
|
643
|
+
return [a, b];
|
|
644
|
+
}
|
|
645
|
+
var isLineSegment = (segment) => Array.isArray(segment) && segment.length === 2 && isPoint(segment[0]) && isPoint(segment[1]);
|
|
646
|
+
var lineSegmentRotate = (l, angle, origin) => {
|
|
647
|
+
return lineSegment(
|
|
648
|
+
pointRotateRads(l[0], origin || pointCenter(l[0], l[1]), angle),
|
|
649
|
+
pointRotateRads(l[1], origin || pointCenter(l[0], l[1]), angle)
|
|
650
|
+
);
|
|
651
|
+
};
|
|
652
|
+
var segmentsIntersectAt = (a, b) => {
|
|
653
|
+
const a0 = vectorFromPoint(a[0]);
|
|
654
|
+
const a1 = vectorFromPoint(a[1]);
|
|
655
|
+
const b0 = vectorFromPoint(b[0]);
|
|
656
|
+
const b1 = vectorFromPoint(b[1]);
|
|
657
|
+
const r = vectorSubtract(a1, a0);
|
|
658
|
+
const s = vectorSubtract(b1, b0);
|
|
659
|
+
const denominator = vectorCross(r, s);
|
|
660
|
+
if (denominator === 0) {
|
|
661
|
+
return null;
|
|
662
|
+
}
|
|
663
|
+
const i = vectorSubtract(vectorFromPoint(b[0]), vectorFromPoint(a[0]));
|
|
664
|
+
const u = vectorCross(i, r) / denominator;
|
|
665
|
+
const t = vectorCross(i, s) / denominator;
|
|
666
|
+
if (u === 0) {
|
|
667
|
+
return null;
|
|
668
|
+
}
|
|
669
|
+
const p = vectorAdd(a0, vectorScale(r, t));
|
|
670
|
+
if (t >= 0 && t < 1 && u >= 0 && u < 1) {
|
|
671
|
+
return pointFromVector(p);
|
|
672
|
+
}
|
|
673
|
+
return null;
|
|
674
|
+
};
|
|
675
|
+
var pointOnLineSegment = (point, line2, threshold = PRECISION) => {
|
|
676
|
+
const distance = distanceToLineSegment(point, line2);
|
|
677
|
+
if (distance === 0) {
|
|
678
|
+
return true;
|
|
679
|
+
}
|
|
680
|
+
return distance < threshold;
|
|
681
|
+
};
|
|
682
|
+
var distanceToLineSegment = (point, line2) => {
|
|
683
|
+
const [x, y] = point;
|
|
684
|
+
const [[x1, y1], [x2, y2]] = line2;
|
|
685
|
+
const A = x - x1;
|
|
686
|
+
const B = y - y1;
|
|
687
|
+
const C = x2 - x1;
|
|
688
|
+
const D = y2 - y1;
|
|
689
|
+
const dot = A * C + B * D;
|
|
690
|
+
const len_sq = C * C + D * D;
|
|
691
|
+
let param = -1;
|
|
692
|
+
if (len_sq !== 0) {
|
|
693
|
+
param = dot / len_sq;
|
|
694
|
+
}
|
|
695
|
+
let xx;
|
|
696
|
+
let yy;
|
|
697
|
+
if (param < 0) {
|
|
698
|
+
xx = x1;
|
|
699
|
+
yy = y1;
|
|
700
|
+
} else if (param > 1) {
|
|
701
|
+
xx = x2;
|
|
702
|
+
yy = y2;
|
|
703
|
+
} else {
|
|
704
|
+
xx = x1 + param * C;
|
|
705
|
+
yy = y1 + param * D;
|
|
706
|
+
}
|
|
707
|
+
const dx = x - xx;
|
|
708
|
+
const dy = y - yy;
|
|
709
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
710
|
+
};
|
|
711
|
+
function lineSegmentIntersectionPoints(l, s, threshold) {
|
|
712
|
+
const candidate = linesIntersectAt(line(l[0], l[1]), line(s[0], s[1]));
|
|
713
|
+
if (!candidate || !pointOnLineSegment(candidate, s, threshold) || !pointOnLineSegment(candidate, l, threshold)) {
|
|
714
|
+
return null;
|
|
715
|
+
}
|
|
716
|
+
return candidate;
|
|
717
|
+
}
|
|
718
|
+
function lineSegmentsDistance(s1, s2) {
|
|
719
|
+
if (lineSegmentIntersectionPoints(s1, s2)) {
|
|
720
|
+
return 0;
|
|
721
|
+
}
|
|
722
|
+
return Math.min(
|
|
723
|
+
distanceToLineSegment(s1[0], s2),
|
|
724
|
+
distanceToLineSegment(s1[1], s2),
|
|
725
|
+
distanceToLineSegment(s2[0], s1),
|
|
726
|
+
distanceToLineSegment(s2[1], s1)
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
|
|
711
730
|
// src/polygon.ts
|
|
712
731
|
function polygon(...points) {
|
|
713
732
|
return polygonClose(points);
|
|
@@ -860,6 +879,7 @@ export {
|
|
|
860
879
|
isPoint,
|
|
861
880
|
isPointWithinBounds,
|
|
862
881
|
isRightAngleRads,
|
|
882
|
+
isValidPoint,
|
|
863
883
|
isVector,
|
|
864
884
|
line,
|
|
865
885
|
lineSegment,
|