@excalidraw/math 0.18.0-91c7748 → 0.18.0-9ba0f5d
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 +167 -168
- package/dist/dev/index.js.map +4 -4
- package/dist/prod/index.js +1 -1
- package/dist/types/common/src/bounds.d.ts +10 -0
- package/dist/types/common/src/colors.d.ts +59 -39
- package/dist/types/common/src/constants.d.ts +19 -27
- package/dist/types/common/src/editorInterface.d.ts +34 -0
- package/dist/types/common/src/font-metadata.d.ts +1 -3
- package/dist/types/common/src/index.d.ts +2 -0
- package/dist/types/common/src/keys.d.ts +1 -1
- package/dist/types/common/src/utility-types.d.ts +0 -1
- package/dist/types/common/src/utils.d.ts +49 -35
- package/dist/types/element/src/Scene.d.ts +3 -3
- package/dist/types/element/src/binding.d.ts +58 -44
- package/dist/types/element/src/bounds.d.ts +2 -10
- package/dist/types/element/src/collision.d.ts +6 -2
- package/dist/types/element/src/comparisons.d.ts +7 -7
- package/dist/types/element/src/dragElements.d.ts +3 -3
- package/dist/types/element/src/duplicate.d.ts +3 -3
- package/dist/types/element/src/fractionalIndex.d.ts +2 -2
- package/dist/types/element/src/frame.d.ts +5 -1
- package/dist/types/element/src/heading.d.ts +2 -1
- package/dist/types/element/src/image.d.ts +1 -11
- package/dist/types/element/src/index.d.ts +1 -3
- package/dist/types/element/src/linearElementEditor.d.ts +16 -20
- package/dist/types/element/src/mutateElement.d.ts +3 -1
- package/dist/types/element/src/newElement.d.ts +6 -6
- package/dist/types/element/src/renderElement.d.ts +1 -7
- package/dist/types/element/src/resizeElements.d.ts +10 -10
- package/dist/types/element/src/resizeTest.d.ts +6 -5
- package/dist/types/element/src/selection.d.ts +3 -7
- package/dist/types/element/src/shape.d.ts +8 -7
- package/dist/types/element/src/textMeasurements.d.ts +1 -3
- package/dist/types/{excalidraw/data → element/src}/transform.d.ts +3 -3
- package/dist/types/element/src/transformHandles.d.ts +8 -27
- package/dist/types/element/src/typeChecks.d.ts +4 -7
- package/dist/types/element/src/types.d.ts +7 -11
- package/dist/types/element/src/utils.d.ts +5 -2
- package/dist/types/element/src/zindex.d.ts +7 -1
- package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +138 -184
- package/dist/types/excalidraw/actions/actionAlign.d.ts +6 -7
- package/dist/types/excalidraw/actions/actionBoundText.d.ts +67 -98
- package/dist/types/excalidraw/actions/actionCanvas.d.ts +401 -771
- package/dist/types/excalidraw/actions/actionClipboard.d.ts +103 -879
- package/dist/types/excalidraw/actions/actionCropEditor.d.ts +32 -48
- package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +107 -159
- package/dist/types/excalidraw/actions/actionDistribute.d.ts +2 -3
- package/dist/types/excalidraw/actions/actionDuplicateSelection.d.ts +3 -4
- package/dist/types/excalidraw/actions/actionElementLink.d.ts +47 -65
- package/dist/types/excalidraw/actions/actionElementLock.d.ts +66 -97
- package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +49 -65
- package/dist/types/excalidraw/actions/actionExport.d.ts +144 -1113
- package/dist/types/excalidraw/actions/actionFinalize.d.ts +10 -396
- package/dist/types/excalidraw/actions/actionFlip.d.ts +2 -3
- package/dist/types/excalidraw/actions/actionFrame.d.ts +213 -312
- package/dist/types/excalidraw/actions/actionGroup.d.ts +70 -109
- package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +122 -178
- package/dist/types/excalidraw/actions/actionLink.d.ts +49 -65
- package/dist/types/excalidraw/actions/actionMenu.d.ts +42 -428
- package/dist/types/excalidraw/actions/actionNavigate.d.ts +18 -361
- package/dist/types/excalidraw/actions/actionProperties.d.ts +127 -2510
- package/dist/types/excalidraw/actions/actionSelectAll.d.ts +35 -55
- package/dist/types/excalidraw/actions/actionStyles.d.ts +32 -48
- package/dist/types/excalidraw/actions/actionTextAutoResize.d.ts +3 -3
- package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +49 -65
- package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +49 -65
- package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +41 -59
- package/dist/types/excalidraw/actions/actionToggleShapeSwitch.d.ts +1 -1
- package/dist/types/excalidraw/actions/actionToggleStats.d.ts +48 -64
- package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +49 -65
- package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +49 -65
- package/dist/types/excalidraw/actions/actionZindex.d.ts +8 -9
- package/dist/types/excalidraw/actions/index.d.ts +1 -1
- package/dist/types/excalidraw/actions/register.d.ts +2 -2
- package/dist/types/excalidraw/actions/types.d.ts +4 -4
- package/dist/types/excalidraw/appState.d.ts +20 -16
- package/dist/types/excalidraw/clipboard.d.ts +7 -31
- package/dist/types/excalidraw/components/Actions.d.ts +14 -4
- package/dist/types/excalidraw/components/App.d.ts +58 -59
- package/dist/types/excalidraw/components/Card.d.ts +1 -3
- package/dist/types/excalidraw/components/ColorPicker/ColorInput.d.ts +2 -4
- package/dist/types/excalidraw/components/ColorPicker/ColorPicker.d.ts +1 -3
- 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/ColorPicker/colorPickerUtils.d.ts +0 -1
- package/dist/types/excalidraw/components/ColorPicker/keyboardNavHandlers.d.ts +0 -1
- package/dist/types/excalidraw/components/CommandPalette/CommandPalette.d.ts +1 -0
- package/dist/types/excalidraw/components/CommandPalette/types.d.ts +1 -3
- package/dist/types/excalidraw/components/ConvertElementTypePopup.d.ts +2 -2
- package/dist/types/excalidraw/components/DarkModeToggle.d.ts +1 -1
- package/dist/types/excalidraw/components/DefaultSidebar.d.ts +9 -13
- package/dist/types/excalidraw/components/ElementLinkDialog.d.ts +1 -1
- package/dist/types/excalidraw/components/Ellipsify.d.ts +1 -2
- package/dist/types/excalidraw/components/ErrorDialog.d.ts +1 -1
- package/dist/types/excalidraw/components/ExcalidrawLogo.d.ts +1 -2
- package/dist/types/excalidraw/components/EyeDropper.d.ts +0 -1
- package/dist/types/excalidraw/components/FilledButton.d.ts +2 -1
- package/dist/types/excalidraw/components/FontPicker/FontPickerTrigger.d.ts +2 -1
- package/dist/types/excalidraw/components/FontPicker/keyboardNavHandlers.d.ts +0 -1
- package/dist/types/excalidraw/components/HelpDialog.d.ts +1 -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/LibraryMenuControlButtons.d.ts +1 -1
- package/dist/types/excalidraw/components/LibraryMenuHeaderContent.d.ts +1 -2
- package/dist/types/excalidraw/components/LibraryMenuSection.d.ts +1 -1
- package/dist/types/excalidraw/components/LibraryUnit.d.ts +2 -3
- package/dist/types/excalidraw/components/LoadingMessage.d.ts +0 -1
- package/dist/types/excalidraw/components/MobileMenu.d.ts +3 -5
- package/dist/types/excalidraw/components/MobileToolBar.d.ts +10 -0
- package/dist/types/excalidraw/components/Modal.d.ts +0 -1
- package/dist/types/excalidraw/components/OverwriteConfirm/OverwriteConfirm.d.ts +1 -1
- package/dist/types/excalidraw/components/Popover.d.ts +2 -1
- package/dist/types/excalidraw/components/RadioGroup.d.ts +0 -1
- package/dist/types/excalidraw/components/RadioSelection.d.ts +4 -4
- package/dist/types/excalidraw/components/ScrollableList.d.ts +0 -1
- package/dist/types/excalidraw/components/Sidebar/Sidebar.d.ts +15 -21
- package/dist/types/excalidraw/components/Sidebar/SidebarHeader.d.ts +1 -1
- package/dist/types/excalidraw/components/Sidebar/SidebarTab.d.ts +1 -2
- package/dist/types/excalidraw/components/Sidebar/SidebarTabTrigger.d.ts +1 -2
- package/dist/types/excalidraw/components/Sidebar/SidebarTabTriggers.d.ts +1 -2
- package/dist/types/excalidraw/components/Sidebar/SidebarTabs.d.ts +1 -2
- package/dist/types/excalidraw/components/Spinner.d.ts +4 -4
- package/dist/types/excalidraw/components/Stats/CanvasGrid.d.ts +0 -1
- package/dist/types/excalidraw/components/Stats/Collapsible.d.ts +0 -1
- package/dist/types/excalidraw/components/Stats/DragInput.d.ts +0 -1
- package/dist/types/excalidraw/components/Stats/index.d.ts +7 -8
- package/dist/types/excalidraw/components/Stats/utils.d.ts +1 -1
- package/dist/types/excalidraw/components/TTDDialog/Chat/ChatHistoryMenu.d.ts +15 -0
- package/dist/types/excalidraw/components/TTDDialog/Chat/ChatInterface.d.ts +27 -0
- package/dist/types/excalidraw/components/TTDDialog/Chat/ChatMessage.d.ts +14 -0
- package/dist/types/excalidraw/components/TTDDialog/Chat/TTDChatPanel.d.ts +26 -0
- package/dist/types/excalidraw/components/TTDDialog/Chat/index.d.ts +3 -0
- package/dist/types/excalidraw/components/TTDDialog/Chat/useChatAgent.d.ts +8 -0
- package/dist/types/excalidraw/components/TTDDialog/MermaidToExcalidraw.d.ts +3 -2
- package/dist/types/excalidraw/components/TTDDialog/TTDContext.d.ts +13 -0
- package/dist/types/excalidraw/components/TTDDialog/TTDDialog.d.ts +4 -25
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogOutput.d.ts +2 -2
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogPanel.d.ts +13 -9
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogTab.d.ts +1 -2
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogTabTrigger.d.ts +1 -2
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogTabTriggers.d.ts +1 -2
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogTrigger.d.ts +2 -3
- package/dist/types/excalidraw/components/TTDDialog/TTDPreviewPanel.d.ts +9 -0
- package/dist/types/excalidraw/components/TTDDialog/TextToDiagram.d.ts +8 -0
- package/dist/types/excalidraw/components/TTDDialog/common.d.ts +16 -16
- package/dist/types/excalidraw/components/TTDDialog/hooks/useChatManagement.d.ts +13 -0
- package/dist/types/excalidraw/components/TTDDialog/hooks/useMermaidRenderer.d.ts +14 -0
- package/dist/types/excalidraw/components/TTDDialog/hooks/useTextGeneration.d.ts +7 -0
- package/dist/types/excalidraw/components/TTDDialog/types.d.ts +91 -0
- package/dist/types/excalidraw/components/TTDDialog/useTTDChatStorage.d.ts +22 -0
- package/dist/types/excalidraw/components/TTDDialog/utils/TTDStreamFetch.d.ts +24 -0
- package/dist/types/excalidraw/components/TTDDialog/utils/chat.d.ts +10 -0
- package/dist/types/excalidraw/components/TTDDialog/utils/mermaidValidation.d.ts +1 -0
- package/dist/types/excalidraw/components/TextField.d.ts +1 -0
- package/dist/types/excalidraw/components/Toast.d.ts +3 -3
- package/dist/types/excalidraw/components/ToolPopover.d.ts +25 -0
- package/dist/types/excalidraw/components/Trans.d.ts +2 -2
- package/dist/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +6 -3
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenu.d.ts +30 -32
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuContent.d.ts +6 -5
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuGroup.d.ts +3 -3
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItem.d.ts +10 -18
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemContent.d.ts +3 -3
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemContentRadio.d.ts +0 -1
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemCustom.d.ts +2 -2
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemLink.d.ts +6 -6
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuTrigger.d.ts +3 -4
- package/dist/types/excalidraw/components/dropdownMenu/common.d.ts +1 -1
- package/dist/types/excalidraw/components/hoc/withInternalFallback.d.ts +1 -1
- package/dist/types/excalidraw/components/hyperlink/helpers.d.ts +1 -1
- package/dist/types/excalidraw/components/icons.d.ts +21 -13
- package/dist/types/excalidraw/components/live-collaboration/LiveCollaborationTrigger.d.ts +4 -3
- package/dist/types/excalidraw/components/main-menu/DefaultItems.d.ts +2 -2
- package/dist/types/excalidraw/components/main-menu/MainMenu.d.ts +25 -30
- package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.Center.d.ts +6 -6
- package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.d.ts +15 -16
- package/dist/types/excalidraw/data/blob.d.ts +323 -5
- package/dist/types/excalidraw/data/encode.d.ts +4 -4
- package/dist/types/excalidraw/data/encryption.d.ts +5 -5
- package/dist/types/excalidraw/data/filesystem.d.ts +2 -2
- package/dist/types/excalidraw/data/index.d.ts +3 -3
- package/dist/types/excalidraw/data/json.d.ts +159 -2
- package/dist/types/excalidraw/data/library.d.ts +24 -9
- package/dist/types/excalidraw/data/restore.d.ts +25 -10
- package/dist/types/excalidraw/editor-jotai.d.ts +11 -11
- package/dist/types/excalidraw/errors.d.ts +14 -0
- package/dist/types/excalidraw/hooks/useLibraryItemSvg.d.ts +1 -1
- package/dist/types/excalidraw/hooks/useOutsideClick.d.ts +4 -3
- package/dist/types/excalidraw/hooks/useScrollPosition.d.ts +1 -2
- package/dist/types/excalidraw/i18n.d.ts +2 -2
- package/dist/types/excalidraw/index.d.ts +6 -7
- package/dist/types/excalidraw/renderer/animation.d.ts +12 -0
- package/dist/types/excalidraw/renderer/helpers.d.ts +6 -8
- package/dist/types/excalidraw/renderer/interactiveScene.d.ts +8 -14
- package/dist/types/excalidraw/scene/Renderer.d.ts +5 -2
- package/dist/types/excalidraw/scene/export.d.ts +2 -2
- package/dist/types/excalidraw/scene/scroll.d.ts +1 -6
- package/dist/types/excalidraw/scene/types.d.ts +22 -5
- package/dist/types/excalidraw/shortcut.d.ts +1 -0
- package/dist/types/excalidraw/snapping.d.ts +5 -5
- package/dist/types/excalidraw/subset/harfbuzz/harfbuzz-bindings.d.ts +1 -1
- package/dist/types/excalidraw/subset/harfbuzz/harfbuzz-loader.d.ts +1 -1
- package/dist/types/excalidraw/subset/harfbuzz/harfbuzz-wasm.d.ts +1 -1
- package/dist/types/excalidraw/subset/woff2/woff2-loader.d.ts +2 -2
- package/dist/types/excalidraw/subset/woff2/woff2-wasm.d.ts +1 -1
- package/dist/types/excalidraw/types.d.ts +29 -22
- package/dist/types/excalidraw/wysiwyg/textWysiwyg.d.ts +2 -2
- package/dist/types/math/src/polygon.d.ts +2 -2
- package/dist/types/math/src/range.d.ts +1 -3
- package/dist/types/math/src/segment.d.ts +3 -3
- package/dist/types/utils/src/bbox.d.ts +1 -1
- package/dist/types/utils/src/export.d.ts +5 -5
- package/dist/types/utils/src/shape.d.ts +6 -6
- package/dist/types/utils/src/withinBounds.d.ts +2 -2
- package/package.json +2 -2
package/dist/dev/index.js
CHANGED
|
@@ -202,45 +202,152 @@ var LegendreGaussN24CValues = [
|
|
|
202
202
|
0.0123412297999872
|
|
203
203
|
];
|
|
204
204
|
|
|
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
|
+
|
|
205
312
|
// src/curve.ts
|
|
206
313
|
function curve(a, b, c, d) {
|
|
207
314
|
return [a, b, c, d];
|
|
208
315
|
}
|
|
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) {
|
|
316
|
+
function solveWithAnalyticalJacobian(curve2, lineSegment2, t0, s0, tolerance = 1e-3, iterLimit = 10) {
|
|
216
317
|
let error = Infinity;
|
|
217
318
|
let iter = 0;
|
|
218
319
|
while (error >= tolerance) {
|
|
219
320
|
if (iter >= iterLimit) {
|
|
220
321
|
return null;
|
|
221
322
|
}
|
|
222
|
-
const
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
-
const
|
|
229
|
-
|
|
323
|
+
const bt = 1 - t0;
|
|
324
|
+
const bt2 = bt * bt;
|
|
325
|
+
const bt3 = bt2 * bt;
|
|
326
|
+
const t0_2 = t0 * t0;
|
|
327
|
+
const t0_3 = t0_2 * t0;
|
|
328
|
+
const bezierX = bt3 * curve2[0][0] + 3 * bt2 * t0 * curve2[1][0] + 3 * bt * t0_2 * curve2[2][0] + t0_3 * curve2[3][0];
|
|
329
|
+
const bezierY = bt3 * curve2[0][1] + 3 * bt2 * t0 * curve2[1][1] + 3 * bt * t0_2 * curve2[2][1] + t0_3 * curve2[3][1];
|
|
330
|
+
const lineX = lineSegment2[0][0] + s0 * (lineSegment2[1][0] - lineSegment2[0][0]);
|
|
331
|
+
const lineY = lineSegment2[0][1] + s0 * (lineSegment2[1][1] - lineSegment2[0][1]);
|
|
332
|
+
const fx = bezierX - lineX;
|
|
333
|
+
const fy = bezierY - lineY;
|
|
334
|
+
error = Math.abs(fx) + Math.abs(fy);
|
|
335
|
+
if (error < tolerance) {
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
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];
|
|
339
|
+
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];
|
|
340
|
+
const dfx_ds = -(lineSegment2[1][0] - lineSegment2[0][0]);
|
|
341
|
+
const dfy_ds = -(lineSegment2[1][1] - lineSegment2[0][1]);
|
|
342
|
+
const det = dfx_dt * dfy_ds - dfx_ds * dfy_dt;
|
|
343
|
+
if (Math.abs(det) < 1e-12) {
|
|
230
344
|
return null;
|
|
231
345
|
}
|
|
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));
|
|
346
|
+
const invDet = 1 / det;
|
|
347
|
+
const dt = invDet * (dfy_ds * -fx - dfx_ds * -fy);
|
|
348
|
+
const ds = invDet * (-dfy_dt * -fx + dfx_dt * -fy);
|
|
349
|
+
t0 += dt;
|
|
350
|
+
s0 += ds;
|
|
244
351
|
iter += 1;
|
|
245
352
|
}
|
|
246
353
|
return [t0, s0];
|
|
@@ -249,50 +356,49 @@ var bezierEquation = (c, t) => pointFrom(
|
|
|
249
356
|
(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
357
|
(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
358
|
);
|
|
359
|
+
var initial_guesses = [
|
|
360
|
+
[0.5, 0],
|
|
361
|
+
[0.2, 0],
|
|
362
|
+
[0.8, 0]
|
|
363
|
+
];
|
|
364
|
+
var calculate = ([t0, s0], l, c) => {
|
|
365
|
+
const solution = solveWithAnalyticalJacobian(c, l, t0, s0, 0.01, 3);
|
|
366
|
+
if (!solution) {
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
const [t, s] = solution;
|
|
370
|
+
if (t < 0 || t > 1 || s < 0 || s > 1) {
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
return bezierEquation(c, t);
|
|
374
|
+
};
|
|
252
375
|
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]);
|
|
376
|
+
let solution = calculate(initial_guesses[0], l, c);
|
|
285
377
|
if (solution) {
|
|
286
378
|
return [solution];
|
|
287
379
|
}
|
|
288
|
-
solution = calculate(initial_guesses[1]);
|
|
380
|
+
solution = calculate(initial_guesses[1], l, c);
|
|
289
381
|
if (solution) {
|
|
290
382
|
return [solution];
|
|
291
383
|
}
|
|
292
|
-
solution = calculate(initial_guesses[2]);
|
|
384
|
+
solution = calculate(initial_guesses[2], l, c);
|
|
293
385
|
if (solution) {
|
|
294
386
|
return [solution];
|
|
295
387
|
}
|
|
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
|
+
}
|
|
296
402
|
return [];
|
|
297
403
|
}
|
|
298
404
|
function curveClosestPoint(c, p, tolerance = 1e-3) {
|
|
@@ -602,113 +708,6 @@ function ellipseLineIntersectionPoints({ center, halfWidth, halfHeight }, [g, h]
|
|
|
602
708
|
return candidates;
|
|
603
709
|
}
|
|
604
710
|
|
|
605
|
-
// src/line.ts
|
|
606
|
-
function line(a, b) {
|
|
607
|
-
return [a, b];
|
|
608
|
-
}
|
|
609
|
-
function linesIntersectAt(a, b) {
|
|
610
|
-
const A1 = a[1][1] - a[0][1];
|
|
611
|
-
const B1 = a[0][0] - a[1][0];
|
|
612
|
-
const A2 = b[1][1] - b[0][1];
|
|
613
|
-
const B2 = b[0][0] - b[1][0];
|
|
614
|
-
const D = A1 * B2 - A2 * B1;
|
|
615
|
-
if (D !== 0) {
|
|
616
|
-
const C1 = A1 * a[0][0] + B1 * a[0][1];
|
|
617
|
-
const C2 = A2 * b[0][0] + B2 * b[0][1];
|
|
618
|
-
return pointFrom((C1 * B2 - C2 * B1) / D, (A1 * C2 - A2 * C1) / D);
|
|
619
|
-
}
|
|
620
|
-
return null;
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
// src/segment.ts
|
|
624
|
-
function lineSegment(a, b) {
|
|
625
|
-
return [a, b];
|
|
626
|
-
}
|
|
627
|
-
var isLineSegment = (segment) => Array.isArray(segment) && segment.length === 2 && isPoint(segment[0]) && isPoint(segment[0]);
|
|
628
|
-
var lineSegmentRotate = (l, angle, origin) => {
|
|
629
|
-
return lineSegment(
|
|
630
|
-
pointRotateRads(l[0], origin || pointCenter(l[0], l[1]), angle),
|
|
631
|
-
pointRotateRads(l[1], origin || pointCenter(l[0], l[1]), angle)
|
|
632
|
-
);
|
|
633
|
-
};
|
|
634
|
-
var segmentsIntersectAt = (a, b) => {
|
|
635
|
-
const a0 = vectorFromPoint(a[0]);
|
|
636
|
-
const a1 = vectorFromPoint(a[1]);
|
|
637
|
-
const b0 = vectorFromPoint(b[0]);
|
|
638
|
-
const b1 = vectorFromPoint(b[1]);
|
|
639
|
-
const r = vectorSubtract(a1, a0);
|
|
640
|
-
const s = vectorSubtract(b1, b0);
|
|
641
|
-
const denominator = vectorCross(r, s);
|
|
642
|
-
if (denominator === 0) {
|
|
643
|
-
return null;
|
|
644
|
-
}
|
|
645
|
-
const i = vectorSubtract(vectorFromPoint(b[0]), vectorFromPoint(a[0]));
|
|
646
|
-
const u = vectorCross(i, r) / denominator;
|
|
647
|
-
const t = vectorCross(i, s) / denominator;
|
|
648
|
-
if (u === 0) {
|
|
649
|
-
return null;
|
|
650
|
-
}
|
|
651
|
-
const p = vectorAdd(a0, vectorScale(r, t));
|
|
652
|
-
if (t >= 0 && t < 1 && u >= 0 && u < 1) {
|
|
653
|
-
return pointFromVector(p);
|
|
654
|
-
}
|
|
655
|
-
return null;
|
|
656
|
-
};
|
|
657
|
-
var pointOnLineSegment = (point, line2, threshold = PRECISION) => {
|
|
658
|
-
const distance = distanceToLineSegment(point, line2);
|
|
659
|
-
if (distance === 0) {
|
|
660
|
-
return true;
|
|
661
|
-
}
|
|
662
|
-
return distance < threshold;
|
|
663
|
-
};
|
|
664
|
-
var distanceToLineSegment = (point, line2) => {
|
|
665
|
-
const [x, y] = point;
|
|
666
|
-
const [[x1, y1], [x2, y2]] = line2;
|
|
667
|
-
const A = x - x1;
|
|
668
|
-
const B = y - y1;
|
|
669
|
-
const C = x2 - x1;
|
|
670
|
-
const D = y2 - y1;
|
|
671
|
-
const dot = A * C + B * D;
|
|
672
|
-
const len_sq = C * C + D * D;
|
|
673
|
-
let param = -1;
|
|
674
|
-
if (len_sq !== 0) {
|
|
675
|
-
param = dot / len_sq;
|
|
676
|
-
}
|
|
677
|
-
let xx;
|
|
678
|
-
let yy;
|
|
679
|
-
if (param < 0) {
|
|
680
|
-
xx = x1;
|
|
681
|
-
yy = y1;
|
|
682
|
-
} else if (param > 1) {
|
|
683
|
-
xx = x2;
|
|
684
|
-
yy = y2;
|
|
685
|
-
} else {
|
|
686
|
-
xx = x1 + param * C;
|
|
687
|
-
yy = y1 + param * D;
|
|
688
|
-
}
|
|
689
|
-
const dx = x - xx;
|
|
690
|
-
const dy = y - yy;
|
|
691
|
-
return Math.sqrt(dx * dx + dy * dy);
|
|
692
|
-
};
|
|
693
|
-
function lineSegmentIntersectionPoints(l, s, threshold) {
|
|
694
|
-
const candidate = linesIntersectAt(line(l[0], l[1]), line(s[0], s[1]));
|
|
695
|
-
if (!candidate || !pointOnLineSegment(candidate, s, threshold) || !pointOnLineSegment(candidate, l, threshold)) {
|
|
696
|
-
return null;
|
|
697
|
-
}
|
|
698
|
-
return candidate;
|
|
699
|
-
}
|
|
700
|
-
function lineSegmentsDistance(s1, s2) {
|
|
701
|
-
if (lineSegmentIntersectionPoints(s1, s2)) {
|
|
702
|
-
return 0;
|
|
703
|
-
}
|
|
704
|
-
return Math.min(
|
|
705
|
-
distanceToLineSegment(s1[0], s2),
|
|
706
|
-
distanceToLineSegment(s1[1], s2),
|
|
707
|
-
distanceToLineSegment(s2[0], s1),
|
|
708
|
-
distanceToLineSegment(s2[1], s1)
|
|
709
|
-
);
|
|
710
|
-
}
|
|
711
|
-
|
|
712
711
|
// src/polygon.ts
|
|
713
712
|
function polygon(...points) {
|
|
714
713
|
return polygonClose(points);
|