@excalidraw/math 0.18.0-9ba0f5d → 0.18.0-a52cd20

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.
Files changed (278) hide show
  1. package/dist/dev/index.js +349 -160
  2. package/dist/dev/index.js.map +4 -4
  3. package/dist/prod/index.js +1 -1
  4. package/dist/types/common/debug.d.ts +21 -0
  5. package/dist/types/common/src/appEventBus.d.ts +27 -0
  6. package/dist/types/common/src/colors.d.ts +24 -2
  7. package/dist/types/common/src/constants.d.ts +70 -7
  8. package/dist/types/common/src/index.d.ts +3 -0
  9. package/dist/types/common/src/keys.d.ts +4 -0
  10. package/dist/types/common/src/points.d.ts +1 -1
  11. package/dist/types/common/src/random.d.ts +7 -0
  12. package/dist/types/common/src/utils.d.ts +10 -50
  13. package/dist/types/common/src/versionedSnapshotStore.d.ts +17 -0
  14. package/dist/types/element/src/Scene.d.ts +9 -5
  15. package/dist/types/element/src/align.d.ts +2 -2
  16. package/dist/types/element/src/arrowEndpointText.d.ts +49 -0
  17. package/dist/types/element/src/arrowheads.d.ts +3 -0
  18. package/dist/types/element/src/arrows/focus.d.ts +30 -0
  19. package/dist/types/element/src/arrows/helpers.d.ts +5 -0
  20. package/dist/types/element/src/binding.d.ts +37 -17
  21. package/dist/types/element/src/bounds.d.ts +23 -8
  22. package/dist/types/element/src/bucketFill.d.ts +110 -0
  23. package/dist/types/element/src/collision.d.ts +7 -3
  24. package/dist/types/element/src/comparisons.d.ts +8 -5
  25. package/dist/types/element/src/convertToShape.d.ts +23 -0
  26. package/dist/types/element/src/delta.d.ts +23 -1
  27. package/dist/types/element/src/distribute.d.ts +3 -2
  28. package/dist/types/element/src/dragElements.d.ts +27 -0
  29. package/dist/types/element/src/duplicate.d.ts +64 -3
  30. package/dist/types/element/src/elbowArrow.d.ts +2 -0
  31. package/dist/types/element/src/embeddable.d.ts +2 -2
  32. package/dist/types/element/src/flowchart.d.ts +11 -7
  33. package/dist/types/element/src/fractionalIndex.d.ts +2 -2
  34. package/dist/types/element/src/frame.d.ts +11 -10
  35. package/dist/types/element/src/groups.d.ts +9 -9
  36. package/dist/types/element/src/index.d.ts +8 -1
  37. package/dist/types/element/src/linearElementEditor.d.ts +32 -10
  38. package/dist/types/element/src/mutateElement.d.ts +3 -1
  39. package/dist/types/element/src/newElement.d.ts +53 -3
  40. package/dist/types/element/src/renderElement.d.ts +21 -7
  41. package/dist/types/element/src/resizeElements.d.ts +2 -2
  42. package/dist/types/element/src/selection.d.ts +11 -7
  43. package/dist/types/element/src/shape.d.ts +28 -2
  44. package/dist/types/element/src/sizeHelpers.d.ts +6 -0
  45. package/dist/types/element/src/sortElements.d.ts +10 -0
  46. package/dist/types/element/src/stickyNote.d.ts +183 -0
  47. package/dist/types/element/src/textElement.d.ts +21 -10
  48. package/dist/types/element/src/textWrapping.d.ts +26 -0
  49. package/dist/types/element/src/transform.d.ts +26 -7
  50. package/dist/types/element/src/typeChecks.d.ts +29 -27
  51. package/dist/types/element/src/types.d.ts +48 -9
  52. package/dist/types/element/src/utils.d.ts +19 -6
  53. package/dist/types/element/src/zindex.d.ts +2 -2
  54. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +125 -53
  55. package/dist/types/excalidraw/actions/actionAlign.d.ts +6 -6
  56. package/dist/types/excalidraw/actions/actionBoundText.d.ts +85 -37
  57. package/dist/types/excalidraw/actions/actionCanvas.d.ts +356 -1019
  58. package/dist/types/excalidraw/actions/actionClipboard.d.ts +84 -36
  59. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +42 -18
  60. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +130 -55
  61. package/dist/types/excalidraw/actions/actionDeselect.d.ts +182 -0
  62. package/dist/types/excalidraw/actions/actionDistribute.d.ts +2 -3
  63. package/dist/types/excalidraw/actions/actionElementLink.d.ts +38 -18
  64. package/dist/types/excalidraw/actions/actionElementLock.d.ts +85 -37
  65. package/dist/types/excalidraw/actions/actionExport.d.ts +133 -359
  66. package/dist/types/excalidraw/actions/actionFinalize.d.ts +1 -0
  67. package/dist/types/excalidraw/actions/actionFrame.d.ts +187 -236
  68. package/dist/types/excalidraw/actions/actionGroup.d.ts +100 -52
  69. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +99 -21
  70. package/dist/types/excalidraw/actions/actionLink.d.ts +43 -19
  71. package/dist/types/excalidraw/actions/actionMenu.d.ts +38 -18
  72. package/dist/types/excalidraw/actions/actionProperties.d.ts +120 -56
  73. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +46 -22
  74. package/dist/types/excalidraw/actions/actionStyles.d.ts +43 -18
  75. package/dist/types/excalidraw/actions/actionTextAutoResize.d.ts +3 -3
  76. package/dist/types/excalidraw/actions/{actionEmbeddable.d.ts → actionToggleArrowBinding.d.ts} +57 -32
  77. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +46 -23
  78. package/dist/types/excalidraw/actions/actionToggleMidpointSnapping.d.ts +195 -0
  79. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +43 -19
  80. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +42 -23
  81. package/dist/types/excalidraw/actions/actionToggleShapeSwitch.d.ts +1 -1
  82. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +43 -19
  83. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +44 -20
  84. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +43 -19
  85. package/dist/types/excalidraw/actions/colorTargets.d.ts +39 -0
  86. package/dist/types/excalidraw/actions/index.d.ts +4 -2
  87. package/dist/types/excalidraw/actions/manager.d.ts +1 -0
  88. package/dist/types/excalidraw/actions/shortcuts.d.ts +1 -1
  89. package/dist/types/excalidraw/actions/types.d.ts +8 -4
  90. package/dist/types/excalidraw/{animated-trail.d.ts → animatedTrail.d.ts} +4 -3
  91. package/dist/types/excalidraw/appState.d.ts +39 -13
  92. package/dist/types/excalidraw/charts/charts.bar.d.ts +2 -0
  93. package/dist/types/excalidraw/charts/charts.constants.d.ts +48 -0
  94. package/dist/types/excalidraw/charts/charts.helpers.d.ts +32 -0
  95. package/dist/types/excalidraw/charts/charts.line.d.ts +2 -0
  96. package/dist/types/excalidraw/charts/charts.parse.d.ts +10 -0
  97. package/dist/types/excalidraw/charts/charts.radar.d.ts +2 -0
  98. package/dist/types/excalidraw/charts/charts.types.d.ts +18 -0
  99. package/dist/types/excalidraw/charts/index.d.ts +7 -0
  100. package/dist/types/excalidraw/clipboard.d.ts +6 -7
  101. package/dist/types/excalidraw/components/Actions.d.ts +17 -12
  102. package/dist/types/excalidraw/components/ActiveConfirmDialog.d.ts +1 -1
  103. package/dist/types/excalidraw/components/App.arrowText.d.ts +70 -0
  104. package/dist/types/excalidraw/components/App.bucketFill.d.ts +48 -0
  105. package/dist/types/excalidraw/components/App.cursor.d.ts +38 -0
  106. package/dist/types/excalidraw/components/App.d.ts +604 -89
  107. package/dist/types/excalidraw/components/App.drawshape.d.ts +55 -0
  108. package/dist/types/excalidraw/components/App.duplicate.d.ts +51 -0
  109. package/dist/types/excalidraw/components/App.flowchart.d.ts +21 -0
  110. package/dist/types/excalidraw/components/App.pan.d.ts +62 -0
  111. package/dist/types/excalidraw/components/App.textTool.d.ts +140 -0
  112. package/dist/types/excalidraw/components/App.toolDrag.d.ts +63 -0
  113. package/dist/types/excalidraw/components/App.viewport.d.ts +113 -0
  114. package/dist/types/excalidraw/components/App.wheel.d.ts +26 -0
  115. package/dist/types/excalidraw/components/AppStateObserver.d.ts +37 -0
  116. package/dist/types/excalidraw/components/ColorPicker/ColorPicker.d.ts +9 -3
  117. package/dist/types/excalidraw/components/ColorPicker/CustomColorList.d.ts +3 -1
  118. package/dist/types/excalidraw/components/ColorPicker/Picker.d.ts +5 -1
  119. package/dist/types/excalidraw/components/ColorPicker/PickerColorList.d.ts +9 -2
  120. package/dist/types/excalidraw/components/ColorPicker/ShadeList.d.ts +4 -2
  121. package/dist/types/excalidraw/components/ColorPicker/TopPicks.d.ts +8 -1
  122. package/dist/types/excalidraw/components/ColorPicker/colorPickerUtils.d.ts +1 -1
  123. package/dist/types/excalidraw/components/ColorPicker/colorTopPicksDnD.d.ts +11 -0
  124. package/dist/types/excalidraw/components/ColorPicker/keyboardNavHandlers.d.ts +2 -1
  125. package/dist/types/excalidraw/components/CommandPalette/defaultCommandPaletteItems.d.ts +1 -2
  126. package/dist/types/excalidraw/components/CommandPalette/types.d.ts +1 -1
  127. package/dist/types/excalidraw/components/ConvertElementTypePopup.d.ts +2 -2
  128. package/dist/types/excalidraw/components/CursorHint.d.ts +46 -0
  129. package/dist/types/excalidraw/components/EyeDropper.d.ts +1 -1
  130. package/dist/types/excalidraw/components/FileDropOverlay.d.ts +2 -0
  131. package/dist/types/excalidraw/components/FontPicker/FontPicker.d.ts +4 -1
  132. package/dist/types/excalidraw/components/FontPicker/FontPickerList.d.ts +6 -1
  133. package/dist/types/excalidraw/components/FontPicker/fontTopPicksDnD.d.ts +12 -0
  134. package/dist/types/excalidraw/components/IconButton.d.ts +48 -0
  135. package/dist/types/excalidraw/components/IconPicker.d.ts +14 -9
  136. package/dist/types/excalidraw/components/Island.d.ts +7 -0
  137. package/dist/types/excalidraw/components/LaserPointerButton.d.ts +2 -4
  138. package/dist/types/excalidraw/components/LayerUI.d.ts +5 -2
  139. package/dist/types/excalidraw/components/LibraryMenu.d.ts +1 -1
  140. package/dist/types/excalidraw/components/LibraryMenuSection.d.ts +6 -2
  141. package/dist/types/excalidraw/components/LibraryUnit.d.ts +7 -2
  142. package/dist/types/excalidraw/components/LockButton.d.ts +3 -4
  143. package/dist/types/excalidraw/components/MagicButton.d.ts +0 -2
  144. package/dist/types/excalidraw/components/MobileMenu.d.ts +4 -4
  145. package/dist/types/excalidraw/components/MobileToolbar.d.ts +9 -0
  146. package/dist/types/excalidraw/components/OverwriteConfirm/OverwriteConfirmState.d.ts +1 -1
  147. package/dist/types/excalidraw/components/PasteChartDialog.d.ts +4 -5
  148. package/dist/types/excalidraw/components/PenModeButton.d.ts +2 -5
  149. package/dist/types/excalidraw/components/Popover.d.ts +1 -3
  150. package/dist/types/excalidraw/components/PropertiesPopover.d.ts +1 -1
  151. package/dist/types/excalidraw/components/{ButtonIcon.d.ts → RadioButton.d.ts} +2 -5
  152. package/dist/types/excalidraw/components/Range.d.ts +10 -4
  153. package/dist/types/excalidraw/components/SVGLayer.d.ts +1 -1
  154. package/dist/types/excalidraw/components/SearchMenu.d.ts +1 -1
  155. package/dist/types/excalidraw/components/Sidebar/Sidebar.d.ts +1 -1
  156. package/dist/types/excalidraw/components/Stats/Angle.d.ts +2 -2
  157. package/dist/types/excalidraw/components/Stats/Dimension.d.ts +2 -2
  158. package/dist/types/excalidraw/components/Stats/DragInput.d.ts +2 -2
  159. package/dist/types/excalidraw/components/Stats/MultiAngle.d.ts +2 -2
  160. package/dist/types/excalidraw/components/Stats/MultiDimension.d.ts +2 -2
  161. package/dist/types/excalidraw/components/Stats/MultiPosition.d.ts +2 -2
  162. package/dist/types/excalidraw/components/Stats/Position.d.ts +3 -3
  163. package/dist/types/excalidraw/components/Stats/utils.d.ts +1 -1
  164. package/dist/types/excalidraw/components/TTDDialog/Chat/ChatInterface.d.ts +2 -6
  165. package/dist/types/excalidraw/components/TTDDialog/Chat/TTDChatPanel.d.ts +2 -1
  166. package/dist/types/excalidraw/components/TTDDialog/CodeMirrorEditor.d.ts +11 -0
  167. package/dist/types/excalidraw/components/TTDDialog/TTDContext.d.ts +4 -4
  168. package/dist/types/excalidraw/components/TTDDialog/TTDDialog.d.ts +11 -7
  169. package/dist/types/excalidraw/components/TTDDialog/TTDDialogInput.d.ts +3 -3
  170. package/dist/types/excalidraw/components/TTDDialog/TTDDialogOutput.d.ts +4 -1
  171. package/dist/types/excalidraw/components/TTDDialog/TTDWelcomeMessage.d.ts +1 -0
  172. package/dist/types/excalidraw/components/TTDDialog/TextToDiagram.d.ts +2 -1
  173. package/dist/types/excalidraw/components/TTDDialog/mermaid-lang-lite.d.ts +2 -0
  174. package/dist/types/excalidraw/components/TTDDialog/types.d.ts +4 -0
  175. package/dist/types/excalidraw/components/TTDDialog/useTTDChatStorage.d.ts +3 -3
  176. package/dist/types/excalidraw/components/TTDDialog/utils/mermaidAutoFix.d.ts +1 -0
  177. package/dist/types/excalidraw/components/TTDDialog/utils/mermaidError.d.ts +10 -0
  178. package/dist/types/excalidraw/components/Toast.d.ts +8 -4
  179. package/dist/types/excalidraw/components/ToolPopover.d.ts +3 -6
  180. package/dist/types/excalidraw/components/Toolbar.d.ts +11 -0
  181. package/dist/types/excalidraw/components/Tools.d.ts +151 -0
  182. package/dist/types/excalidraw/components/Tooltip.d.ts +15 -1
  183. package/dist/types/excalidraw/components/TopPicksDnD/TopPicksContextMenu.d.ts +14 -0
  184. package/dist/types/excalidraw/components/TopPicksDnD/TopPicksTip.d.ts +11 -0
  185. package/dist/types/excalidraw/components/TopPicksDnD/topPicksDnD.d.ts +58 -0
  186. package/dist/types/excalidraw/components/UserList.d.ts +3 -2
  187. package/dist/types/excalidraw/components/ViewportStatusFrame/ViewportStatusFrame.d.ts +11 -0
  188. package/dist/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +4 -1
  189. package/dist/types/excalidraw/components/canvases/NewElementCanvas.d.ts +3 -0
  190. package/dist/types/excalidraw/components/canvases/StaticCanvas.d.ts +1 -1
  191. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenu.d.ts +30 -16
  192. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuContent.d.ts +3 -2
  193. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItem.d.ts +11 -12
  194. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemCheckbox.d.ts +5 -0
  195. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemContent.d.ts +2 -1
  196. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemContentRadio.d.ts +2 -1
  197. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuSub.d.ts +23 -0
  198. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuSubContent.d.ts +8 -0
  199. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuSubTrigger.d.ts +12 -0
  200. package/dist/types/excalidraw/components/dropdownMenu/common.d.ts +1 -1
  201. package/dist/types/excalidraw/components/dropdownMenu/dropdownMenuUtils.d.ts +2 -0
  202. package/dist/types/excalidraw/components/footer/Footer.d.ts +3 -1
  203. package/dist/types/excalidraw/components/hyperlink/helpers.d.ts +2 -2
  204. package/dist/types/excalidraw/components/icons.d.ts +30 -10
  205. package/dist/types/excalidraw/components/main-menu/DefaultItems.d.ts +26 -3
  206. package/dist/types/excalidraw/components/main-menu/MainMenu.d.ts +23 -14
  207. package/dist/types/excalidraw/components/positionElementBesideCursor.d.ts +26 -0
  208. package/dist/types/excalidraw/components/shapeActionPredicates.d.ts +39 -0
  209. package/dist/types/excalidraw/data/blob.d.ts +107 -60
  210. package/dist/types/excalidraw/data/filesystem.d.ts +3 -5
  211. package/dist/types/excalidraw/data/index.d.ts +6 -7
  212. package/dist/types/excalidraw/data/json.d.ts +62 -30
  213. package/dist/types/excalidraw/data/library.d.ts +1 -1
  214. package/dist/types/excalidraw/data/resave.d.ts +7 -2
  215. package/dist/types/excalidraw/drawShapeTrail.d.ts +16 -0
  216. package/dist/types/excalidraw/eraser/index.d.ts +2 -3
  217. package/dist/types/excalidraw/fonts/Fonts.d.ts +3 -2
  218. package/dist/types/excalidraw/hooks/useAppStateValue.d.ts +29 -0
  219. package/dist/types/excalidraw/hooks/useLibraryItemSvg.d.ts +1 -1
  220. package/dist/types/excalidraw/hooks/useTextEditorFocus.d.ts +5 -5
  221. package/dist/types/excalidraw/{laser-trails.d.ts → laserTrails.d.ts} +5 -7
  222. package/dist/types/excalidraw/lasso/index.d.ts +2 -3
  223. package/dist/types/excalidraw/lasso/utils.d.ts +2 -0
  224. package/dist/types/excalidraw/renderOverrides.d.ts +9 -0
  225. package/dist/types/excalidraw/renderer/animation.d.ts +5 -1
  226. package/dist/types/excalidraw/renderer/helpers.d.ts +25 -0
  227. package/dist/types/excalidraw/renderer/interactiveScene.d.ts +2 -4
  228. package/dist/types/excalidraw/scene/Renderer.d.ts +489 -20
  229. package/dist/types/excalidraw/scene/export.d.ts +3 -3
  230. package/dist/types/excalidraw/scene/index.d.ts +2 -2
  231. package/dist/types/excalidraw/scene/types.d.ts +7 -4
  232. package/dist/types/excalidraw/snapping.d.ts +7 -7
  233. package/dist/types/excalidraw/textAutoResizeHandle.d.ts +15 -0
  234. package/dist/types/excalidraw/types.d.ts +619 -42
  235. package/dist/types/excalidraw/viewport.d.ts +302 -0
  236. package/dist/types/excalidraw/wysiwyg/textWysiwyg.d.ts +12 -3
  237. package/dist/types/fractional-indexing/src/index.d.ts +29 -0
  238. package/dist/types/laser-pointer/src/index.d.ts +2 -0
  239. package/dist/types/laser-pointer/src/math.d.ts +16 -0
  240. package/dist/types/laser-pointer/src/simplify.d.ts +2 -0
  241. package/dist/types/laser-pointer/src/state.d.ts +36 -0
  242. package/dist/types/math/src/constants.d.ts +0 -1
  243. package/dist/types/math/src/curve.d.ts +23 -13
  244. package/dist/types/math/src/index.d.ts +1 -0
  245. package/dist/types/math/src/pca.d.ts +79 -0
  246. package/dist/types/math/src/point.d.ts +8 -2
  247. package/dist/types/math/src/polygon.d.ts +25 -1
  248. package/dist/types/math/src/segment.d.ts +6 -0
  249. package/dist/types/math/src/types.d.ts +25 -1
  250. package/dist/types/utils/src/export.d.ts +4 -3
  251. package/dist/types/utils/src/index.d.ts +1 -2
  252. package/dist/types/utils/src/shape.d.ts +2 -2
  253. package/package.json +2 -2
  254. package/dist/types/excalidraw/animation-frame-handler.d.ts +0 -16
  255. package/dist/types/excalidraw/charts.d.ts +0 -27
  256. package/dist/types/excalidraw/components/DiagramToCodePlugin/DiagramToCodePlugin.d.ts +0 -4
  257. package/dist/types/excalidraw/components/ExcalidrawLogo.d.ts +0 -15
  258. package/dist/types/excalidraw/components/FollowMode/FollowMode.d.ts +0 -10
  259. package/dist/types/excalidraw/components/HandButton.d.ts +0 -10
  260. package/dist/types/excalidraw/components/InitializeApp.d.ts +0 -10
  261. package/dist/types/excalidraw/components/MobileToolBar.d.ts +0 -10
  262. package/dist/types/excalidraw/components/TTDDialog/TTDDialogTrigger.d.ts +0 -8
  263. package/dist/types/excalidraw/components/TTDDialog/utils/TTDStreamFetch.d.ts +0 -24
  264. package/dist/types/excalidraw/components/ToolButton.d.ts +0 -49
  265. package/dist/types/excalidraw/components/footer/FooterCenter.d.ts +0 -8
  266. package/dist/types/excalidraw/components/live-collaboration/LiveCollaborationTrigger.d.ts +0 -11
  267. package/dist/types/excalidraw/components/shapes.d.ts +0 -190
  268. package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.Center.d.ts +0 -58
  269. package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.Hints.d.ts +0 -19
  270. package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.d.ts +0 -84
  271. package/dist/types/excalidraw/cursor.d.ts +0 -5
  272. package/dist/types/excalidraw/data/reconcile.d.ts +0 -7
  273. package/dist/types/excalidraw/index.d.ts +0 -46
  274. package/dist/types/excalidraw/polyfill.d.ts +0 -2
  275. package/dist/types/excalidraw/scene/scroll.d.ts +0 -18
  276. package/dist/types/excalidraw/scene/zoom.d.ts +0 -12
  277. package/dist/types/utils/src/bbox.d.ts +0 -9
  278. 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(x, y) {
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([x, y], [cx, cy], angle) {
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(c, l, t0, s0, 0.01, 3);
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,36 +280,40 @@ 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(initial_guesses[0], l, c);
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(initial_guesses[1], l, c);
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(initial_guesses[2], l, c);
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
- function curveClosestPoint(c, p, tolerance = 1e-3) {
316
+ function curveClosestParameter(c, p, tolerance = 1e-3) {
405
317
  const localMinimum = (min, max, f, e = tolerance) => {
406
318
  let m = min;
407
319
  let n = max;
@@ -418,7 +330,7 @@ function curveClosestPoint(c, p, tolerance = 1e-3) {
418
330
  };
419
331
  const maxSteps = 30;
420
332
  let closestStep = 0;
421
- for (let min = Infinity, step = 0; step < maxSteps; step++) {
333
+ for (let min = Infinity, step = 0; step <= maxSteps; step++) {
422
334
  const d = pointDistance(p, bezierEquation(c, step / maxSteps));
423
335
  if (d < min) {
424
336
  min = d;
@@ -427,22 +339,18 @@ function curveClosestPoint(c, p, tolerance = 1e-3) {
427
339
  }
428
340
  const t0 = Math.max((closestStep - 1) / maxSteps, 0);
429
341
  const t1 = Math.min((closestStep + 1) / maxSteps, 1);
430
- const solution = localMinimum(
342
+ const param = localMinimum(
431
343
  t0,
432
344
  t1,
433
345
  (t) => pointDistance(p, bezierEquation(c, t))
434
346
  );
435
- if (!solution) {
436
- return null;
437
- }
438
- return bezierEquation(c, solution);
347
+ return param ?? closestStep / maxSteps;
439
348
  }
440
- function curvePointDistance(c, p) {
441
- const closest = curveClosestPoint(c, p);
442
- if (!closest) {
443
- return 0;
444
- }
445
- return pointDistance(p, closest);
349
+ function curveClosestPoint(c, p, tolerance = 1e-3) {
350
+ return bezierEquation(c, curveClosestParameter(c, p, tolerance));
351
+ }
352
+ function curvePointDistance(c, p, tolerance = 1e-3) {
353
+ return pointDistance(p, curveClosestPoint(c, p, tolerance));
446
354
  }
447
355
  function isCurve(v) {
448
356
  return Array.isArray(v) && v.length === 4 && isPoint(v[0]) && isPoint(v[1]) && isPoint(v[2]) && isPoint(v[3]);
@@ -560,14 +468,13 @@ function curveLengthAtParameter(c, t) {
560
468
  }
561
469
  return z1 * sum;
562
470
  }
563
- function curvePointAtLength(c, percent) {
471
+ function curvePointAtLength(c, percent, totalLength = curveLength(c)) {
564
472
  if (percent <= 0) {
565
473
  return bezierEquation(c, 0);
566
474
  }
567
475
  if (percent >= 1) {
568
476
  return bezierEquation(c, 1);
569
477
  }
570
- const totalLength = curveLength(c);
571
478
  const targetLength = totalLength * percent;
572
479
  let tMin = 0;
573
480
  let tMax = 1;
@@ -616,6 +523,9 @@ var ellipseDistanceFromPoint = (p, ellipse2) => {
616
523
  vectorFromPoint(p),
617
524
  vectorScale(vectorFromPoint(center), -1)
618
525
  );
526
+ if (a === b) {
527
+ return Math.abs(Math.hypot(translatedPoint[0], translatedPoint[1]) - a);
528
+ }
619
529
  const px = Math.abs(translatedPoint[0]);
620
530
  const py = Math.abs(translatedPoint[1]);
621
531
  let tx = 0.707;
@@ -631,6 +541,9 @@ var ellipseDistanceFromPoint = (p, ellipse2) => {
631
541
  const qy = py - ey;
632
542
  const r = Math.hypot(ry, rx);
633
543
  const q = Math.hypot(qy, qx);
544
+ if (q === 0) {
545
+ break;
546
+ }
634
547
  tx = Math.min(1, Math.max(0, (qx * r / q + ex) / a));
635
548
  ty = Math.min(1, Math.max(0, (qy * r / q + ey) / b));
636
549
  const t = Math.hypot(ty, tx);
@@ -638,8 +551,8 @@ var ellipseDistanceFromPoint = (p, ellipse2) => {
638
551
  ty /= t;
639
552
  }
640
553
  const [minX, minY] = [
641
- a * tx * Math.sign(translatedPoint[0]),
642
- b * ty * Math.sign(translatedPoint[1])
554
+ a * tx * (translatedPoint[0] < 0 ? -1 : 1),
555
+ b * ty * (translatedPoint[1] < 0 ? -1 : 1)
643
556
  ];
644
557
  return pointDistance(pointFromVector(translatedPoint), pointFrom(minX, minY));
645
558
  };
@@ -708,6 +621,118 @@ function ellipseLineIntersectionPoints({ center, halfWidth, halfHeight }, [g, h]
708
621
  return candidates;
709
622
  }
710
623
 
624
+ // src/line.ts
625
+ function line(a, b) {
626
+ return [a, b];
627
+ }
628
+ function linesIntersectAt(a, b) {
629
+ const A1 = a[1][1] - a[0][1];
630
+ const B1 = a[0][0] - a[1][0];
631
+ const A2 = b[1][1] - b[0][1];
632
+ const B2 = b[0][0] - b[1][0];
633
+ const D = A1 * B2 - A2 * B1;
634
+ if (D !== 0) {
635
+ const C1 = A1 * a[0][0] + B1 * a[0][1];
636
+ const C2 = A2 * b[0][0] + B2 * b[0][1];
637
+ return pointFrom((C1 * B2 - C2 * B1) / D, (A1 * C2 - A2 * C1) / D);
638
+ }
639
+ return null;
640
+ }
641
+
642
+ // src/pca.ts
643
+ function centroid(points) {
644
+ let cx = 0;
645
+ let cy = 0;
646
+ for (const [x, y] of points) {
647
+ cx += x;
648
+ cy += y;
649
+ }
650
+ return pointFrom(cx / points.length, cy / points.length);
651
+ }
652
+ function principalAxes(points) {
653
+ if (points.length < 2) {
654
+ console.error("Degenerate point set: at least two points are required");
655
+ }
656
+ const c = centroid(points);
657
+ let m20 = 0;
658
+ let m02 = 0;
659
+ let m11 = 0;
660
+ for (const [x, y] of points) {
661
+ const dx = x - c[0];
662
+ const dy = y - c[1];
663
+ m20 += dx * dx;
664
+ m02 += dy * dy;
665
+ m11 += dx * dy;
666
+ }
667
+ m20 /= points.length;
668
+ m02 /= points.length;
669
+ m11 /= points.length;
670
+ const trace = m20 + m02;
671
+ const diff = Math.hypot(m20 - m02, 2 * m11);
672
+ const majorVariance = (trace + diff) / 2;
673
+ const minorVariance = (trace - diff) / 2;
674
+ let major;
675
+ if (Math.abs(m11) > Number.EPSILON) {
676
+ major = vectorNormalize(vector(majorVariance - m02, m11));
677
+ } else {
678
+ major = m20 >= m02 ? vector(1, 0) : vector(0, 1);
679
+ }
680
+ return {
681
+ centroid: c,
682
+ major,
683
+ minor: vectorNormal(major),
684
+ majorVariance,
685
+ minorVariance
686
+ };
687
+ }
688
+ function principalCoords(points, axes, scale = 1) {
689
+ const { centroid: c, major, minor } = axes;
690
+ return points.map(([x, y]) => {
691
+ const dx = x - c[0];
692
+ const dy = y - c[1];
693
+ return [
694
+ (dx * major[0] + dy * major[1]) * scale,
695
+ (dx * minor[0] + dy * minor[1]) * scale
696
+ ];
697
+ });
698
+ }
699
+ function orientPrincipalAxes(points, axes) {
700
+ const u = principalCoords(points, axes).map(([uu]) => uu);
701
+ if (skewness(u) <= 0) {
702
+ return axes;
703
+ }
704
+ const major = vectorScale(axes.major, -1);
705
+ return { ...axes, major, minor: vectorNormal(major) };
706
+ }
707
+ function elongation(axes) {
708
+ return axes.majorVariance > 0 ? axes.minorVariance / axes.majorVariance : 1;
709
+ }
710
+ function standardizedMoment(values, order) {
711
+ const n = values.length;
712
+ let mean = 0;
713
+ for (const v of values) {
714
+ mean += v;
715
+ }
716
+ mean /= n;
717
+ let variance = 0;
718
+ let moment = 0;
719
+ for (const v of values) {
720
+ const d = v - mean;
721
+ variance += d * d;
722
+ moment += d ** order;
723
+ }
724
+ variance /= n;
725
+ moment /= n;
726
+ const sigma = Math.sqrt(variance);
727
+ return sigma > Number.EPSILON ? moment / sigma ** order : 0;
728
+ }
729
+ function skewness(values) {
730
+ return standardizedMoment(values, 3);
731
+ }
732
+ function kurtosis(values) {
733
+ return standardizedMoment(values, 4);
734
+ }
735
+
711
736
  // src/polygon.ts
712
737
  function polygon(...points) {
713
738
  return polygonClose(points);
@@ -751,21 +776,84 @@ var polygonIncludesPointNonZero = (point, polygon2) => {
751
776
  }
752
777
  return windingNumber !== 0;
753
778
  };
754
- var pointOnPolygon = (p, poly, threshold = PRECISION) => {
755
- let on = false;
756
- for (let i = 0, l = poly.length - 1; i < l; i++) {
757
- if (pointOnLineSegment(p, lineSegment(poly[i], poly[i + 1]), threshold)) {
758
- on = true;
759
- break;
760
- }
761
- }
762
- return on;
763
- };
764
779
  function polygonClose(polygon2) {
765
780
  return polygonIsClosed(polygon2) ? polygon2 : [...polygon2, polygon2[0]];
766
781
  }
767
- function polygonIsClosed(polygon2) {
768
- return pointsEqual(polygon2[0], polygon2[polygon2.length - 1]);
782
+ function polygonIsClosed(polygon2, tolerance = PRECISION) {
783
+ return pointsEqual(polygon2[0], polygon2[polygon2.length - 1], tolerance);
784
+ }
785
+ function polygonSignedArea(polygon2, tolerance = PRECISION) {
786
+ const pts = polygonIsClosed(polygon2, tolerance) ? polygon2.slice(0, -1) : polygon2;
787
+ let sum = 0;
788
+ for (let i = 0, j = pts.length - 1; i < pts.length; j = i++) {
789
+ sum += pts[j][0] * pts[i][1] - pts[i][0] * pts[j][1];
790
+ }
791
+ return sum / 2;
792
+ }
793
+ function polygonArea(polygon2, tolerance = PRECISION) {
794
+ return Math.abs(polygonSignedArea(polygon2, tolerance));
795
+ }
796
+ function convexHull(points) {
797
+ if (points.length < 3) {
798
+ return [...points];
799
+ }
800
+ const sorted = [...points].sort(
801
+ (a, b) => a[0] === b[0] ? a[1] - b[1] : a[0] - b[0]
802
+ );
803
+ const cross = (o, a, b) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);
804
+ const half = (pts) => {
805
+ const chain = [];
806
+ for (const p of pts) {
807
+ while (chain.length >= 2 && cross(chain[chain.length - 2], chain[chain.length - 1], p) <= 0) {
808
+ chain.pop();
809
+ }
810
+ chain.push(p);
811
+ }
812
+ chain.pop();
813
+ return chain;
814
+ };
815
+ const hull = [...half(sorted), ...half([...sorted].reverse())];
816
+ return hull.length >= 3 ? hull : [...points];
817
+ }
818
+ function simplifyConvexPolygon(polygon2, angleThreshold) {
819
+ if (polygon2.length < 3) {
820
+ return [...polygon2];
821
+ }
822
+ const turnAt = (i) => {
823
+ const prev = polygon2[(i - 1 + polygon2.length) % polygon2.length];
824
+ const curr = polygon2[i];
825
+ const next = polygon2[(i + 1) % polygon2.length];
826
+ const inAngle = Math.atan2(curr[1] - prev[1], curr[0] - prev[0]);
827
+ const outAngle = Math.atan2(next[1] - curr[1], next[0] - curr[0]);
828
+ return Math.abs(normalizeTurn(outAngle - inAngle));
829
+ };
830
+ let start = 0;
831
+ for (let i = 1; i < polygon2.length; i++) {
832
+ if (turnAt(i) > turnAt(start)) {
833
+ start = i;
834
+ }
835
+ }
836
+ const simplified = [];
837
+ let accumulated = 0;
838
+ for (let k = 0; k < polygon2.length; k++) {
839
+ const i = (start + k) % polygon2.length;
840
+ accumulated += turnAt(i);
841
+ if (accumulated >= angleThreshold) {
842
+ simplified.push(polygon2[i]);
843
+ accumulated = 0;
844
+ }
845
+ }
846
+ return simplified.length >= 3 ? simplified : [...polygon2];
847
+ }
848
+ function normalizeTurn(angle) {
849
+ let a = angle;
850
+ while (a > Math.PI) {
851
+ a -= 2 * Math.PI;
852
+ }
853
+ while (a < -Math.PI) {
854
+ a += 2 * Math.PI;
855
+ }
856
+ return a;
769
857
  }
770
858
 
771
859
  // src/range.ts
@@ -797,6 +885,91 @@ var rangeIncludesValue = (value, [min, max]) => {
797
885
  return value >= min && value <= max;
798
886
  };
799
887
 
888
+ // src/segment.ts
889
+ function lineSegment(a, b) {
890
+ return [a, b];
891
+ }
892
+ var isLineSegment = (segment) => Array.isArray(segment) && segment.length === 2 && isPoint(segment[0]) && isPoint(segment[1]);
893
+ var lineSegmentRotate = (l, angle, origin) => {
894
+ return lineSegment(
895
+ pointRotateRads(l[0], origin || pointCenter(l[0], l[1]), angle),
896
+ pointRotateRads(l[1], origin || pointCenter(l[0], l[1]), angle)
897
+ );
898
+ };
899
+ var segmentsIntersectAt = (a, b) => {
900
+ const a0 = vectorFromPoint(a[0]);
901
+ const a1 = vectorFromPoint(a[1]);
902
+ const b0 = vectorFromPoint(b[0]);
903
+ const b1 = vectorFromPoint(b[1]);
904
+ const r = vectorSubtract(a1, a0);
905
+ const s = vectorSubtract(b1, b0);
906
+ const denominator = vectorCross(r, s);
907
+ if (denominator === 0) {
908
+ return null;
909
+ }
910
+ const i = vectorSubtract(vectorFromPoint(b[0]), vectorFromPoint(a[0]));
911
+ const u = vectorCross(i, r) / denominator;
912
+ const t = vectorCross(i, s) / denominator;
913
+ if (u === 0) {
914
+ return null;
915
+ }
916
+ const p = vectorAdd(a0, vectorScale(r, t));
917
+ if (t >= 0 && t < 1 && u >= 0 && u < 1) {
918
+ return pointFromVector(p);
919
+ }
920
+ return null;
921
+ };
922
+ var pointOnLineSegment = (point, line2, threshold = PRECISION) => {
923
+ const distance = distanceToLineSegment(point, line2);
924
+ if (distance === 0) {
925
+ return true;
926
+ }
927
+ return distance < threshold;
928
+ };
929
+ var distanceToLineSegment = (point, line2) => {
930
+ return pointDistance(
931
+ point,
932
+ lineSegmentPointAt(line2, lineSegmentClosestParameter(point, line2))
933
+ );
934
+ };
935
+ function lineSegmentPointAt(line2, t) {
936
+ const [[x1, y1], [x2, y2]] = line2;
937
+ return pointFrom(x1 + t * (x2 - x1), y1 + t * (y2 - y1));
938
+ }
939
+ function lineSegmentIntersectionPoints(l, s, threshold) {
940
+ const candidate = linesIntersectAt(line(l[0], l[1]), line(s[0], s[1]));
941
+ if (!candidate || !pointOnLineSegment(candidate, s, threshold) || !pointOnLineSegment(candidate, l, threshold)) {
942
+ return null;
943
+ }
944
+ return candidate;
945
+ }
946
+ function lineSegmentsDistance(s1, s2) {
947
+ if (lineSegmentIntersectionPoints(s1, s2)) {
948
+ return 0;
949
+ }
950
+ return Math.min(
951
+ distanceToLineSegment(s1[0], s2),
952
+ distanceToLineSegment(s1[1], s2),
953
+ distanceToLineSegment(s2[0], s1),
954
+ distanceToLineSegment(s2[1], s1)
955
+ );
956
+ }
957
+ function lineSegmentClosestParameter(point, line2) {
958
+ const [x, y] = point;
959
+ const [[x1, y1], [x2, y2]] = line2;
960
+ const A = x - x1;
961
+ const B = y - y1;
962
+ const C = x2 - x1;
963
+ const D = y2 - y1;
964
+ const dot = A * C + B * D;
965
+ const len_sq = C * C + D * D;
966
+ let param = 0;
967
+ if (len_sq !== 0) {
968
+ param = dot / len_sq;
969
+ }
970
+ return Math.max(0, Math.min(1, param));
971
+ }
972
+
800
973
  // src/rectangle.ts
801
974
  function rectangle(topLeft, bottomRight) {
802
975
  return [topLeft, bottomRight];
@@ -833,10 +1006,13 @@ export {
833
1006
  average,
834
1007
  bezierEquation,
835
1008
  cartesian2Polar,
1009
+ centroid,
836
1010
  clamp,
1011
+ convexHull,
837
1012
  curve,
838
1013
  curveCatmullRomCubicApproxPoints,
839
1014
  curveCatmullRomQuadraticApproxPoints,
1015
+ curveClosestParameter,
840
1016
  curveClosestPoint,
841
1017
  curveIntersectLineSegment,
842
1018
  curveLength,
@@ -853,6 +1029,7 @@ export {
853
1029
  ellipseLineIntersectionPoints,
854
1030
  ellipseSegmentInterceptPoints,
855
1031
  ellipseTouchesPoint,
1032
+ elongation,
856
1033
  isCloseTo,
857
1034
  isCurve,
858
1035
  isFiniteNumber,
@@ -860,15 +1037,20 @@ export {
860
1037
  isPoint,
861
1038
  isPointWithinBounds,
862
1039
  isRightAngleRads,
1040
+ isValidPoint,
863
1041
  isVector,
1042
+ kurtosis,
864
1043
  line,
865
1044
  lineSegment,
1045
+ lineSegmentClosestParameter,
866
1046
  lineSegmentIntersectionPoints,
1047
+ lineSegmentPointAt,
867
1048
  lineSegmentRotate,
868
1049
  lineSegmentsDistance,
869
1050
  linesIntersectAt,
870
1051
  normalizeRadians,
871
1052
  offsetPointsForQuadraticBezier,
1053
+ orientPrincipalAxes,
872
1054
  pointCenter,
873
1055
  pointDistance,
874
1056
  pointDistanceSq,
@@ -877,16 +1059,20 @@ export {
877
1059
  pointFromPair,
878
1060
  pointFromVector,
879
1061
  pointOnLineSegment,
880
- pointOnPolygon,
881
1062
  pointRotateDegs,
882
1063
  pointRotateRads,
883
1064
  pointScaleFromOrigin,
884
1065
  pointTranslate,
885
1066
  pointsEqual,
886
1067
  polygon,
1068
+ polygonArea,
887
1069
  polygonFromPoints,
888
1070
  polygonIncludesPoint,
889
1071
  polygonIncludesPointNonZero,
1072
+ polygonIsClosed,
1073
+ polygonSignedArea,
1074
+ principalAxes,
1075
+ principalCoords,
890
1076
  radiansBetweenAngles,
891
1077
  radiansDifference,
892
1078
  radiansToDegrees,
@@ -902,6 +1088,9 @@ export {
902
1088
  round,
903
1089
  roundToStep,
904
1090
  segmentsIntersectAt,
1091
+ simplifyConvexPolygon,
1092
+ skewness,
1093
+ standardizedMoment,
905
1094
  triangleIncludesPoint,
906
1095
  vector,
907
1096
  vectorAdd,