@cornerstonejs/tools 1.33.0 → 1.35.0

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 (338) hide show
  1. package/dist/cjs/eventDispatchers/mouseEventHandlers/mouseDown.js +4 -4
  2. package/dist/cjs/eventDispatchers/mouseEventHandlers/mouseDown.js.map +1 -1
  3. package/dist/cjs/eventDispatchers/shared/getToolsWithActionsForMouseEvent.js +3 -2
  4. package/dist/cjs/eventDispatchers/shared/getToolsWithActionsForMouseEvent.js.map +1 -1
  5. package/dist/cjs/index.d.ts +2 -2
  6. package/dist/cjs/index.js +3 -2
  7. package/dist/cjs/index.js.map +1 -1
  8. package/dist/cjs/store/SynchronizerManager/Synchronizer.d.ts +1 -0
  9. package/dist/cjs/store/SynchronizerManager/Synchronizer.js +17 -1
  10. package/dist/cjs/store/SynchronizerManager/Synchronizer.js.map +1 -1
  11. package/dist/cjs/synchronizers/callbacks/areViewportsCoplanar .d.ts +1 -1
  12. package/dist/cjs/synchronizers/callbacks/areViewportsCoplanar .js.map +1 -1
  13. package/dist/cjs/synchronizers/callbacks/{stackImageSyncCallback.d.ts → imageSliceSyncCallback.d.ts} +1 -1
  14. package/dist/cjs/synchronizers/callbacks/{stackImageSyncCallback.js → imageSliceSyncCallback.js} +8 -4
  15. package/dist/cjs/synchronizers/callbacks/{stackImageSyncCallback.js.map → imageSliceSyncCallback.js.map} +1 -1
  16. package/dist/cjs/synchronizers/index.d.ts +3 -2
  17. package/dist/cjs/synchronizers/index.js +5 -3
  18. package/dist/cjs/synchronizers/index.js.map +1 -1
  19. package/dist/cjs/synchronizers/synchronizers/{createStackImageSynchronizer.d.ts → createImageSliceSynchronizer.d.ts} +1 -1
  20. package/dist/cjs/synchronizers/synchronizers/createImageSliceSynchronizer.js +17 -0
  21. package/dist/cjs/synchronizers/synchronizers/createImageSliceSynchronizer.js.map +1 -0
  22. package/dist/cjs/synchronizers/synchronizers/index.d.ts +3 -2
  23. package/dist/cjs/synchronizers/synchronizers/index.js +5 -3
  24. package/dist/cjs/synchronizers/synchronizers/index.js.map +1 -1
  25. package/dist/cjs/tools/AdvancedMagnifyTool.d.ts +4 -0
  26. package/dist/cjs/tools/AdvancedMagnifyTool.js +8 -3
  27. package/dist/cjs/tools/AdvancedMagnifyTool.js.map +1 -1
  28. package/dist/cjs/tools/annotation/SplineROITool.d.ts +59 -0
  29. package/dist/cjs/tools/annotation/SplineROITool.js +709 -0
  30. package/dist/cjs/tools/annotation/SplineROITool.js.map +1 -0
  31. package/dist/cjs/tools/annotation/splines/BSpline.d.ts +5 -0
  32. package/dist/cjs/tools/annotation/splines/BSpline.js +14 -0
  33. package/dist/cjs/tools/annotation/splines/BSpline.js.map +1 -0
  34. package/dist/cjs/tools/annotation/splines/CardinalSpline.d.ts +12 -0
  35. package/dist/cjs/tools/annotation/splines/CardinalSpline.js +38 -0
  36. package/dist/cjs/tools/annotation/splines/CardinalSpline.js.map +1 -0
  37. package/dist/cjs/tools/annotation/splines/CatmullRomSpline.d.ts +5 -0
  38. package/dist/cjs/tools/annotation/splines/CatmullRomSpline.js +12 -0
  39. package/dist/cjs/tools/annotation/splines/CatmullRomSpline.js.map +1 -0
  40. package/dist/cjs/tools/annotation/splines/CubicSpline.d.ts +13 -0
  41. package/dist/cjs/tools/annotation/splines/CubicSpline.js +192 -0
  42. package/dist/cjs/tools/annotation/splines/CubicSpline.js.map +1 -0
  43. package/dist/cjs/tools/annotation/splines/LinearSpline.d.ts +5 -0
  44. package/dist/cjs/tools/annotation/splines/LinearSpline.js +12 -0
  45. package/dist/cjs/tools/annotation/splines/LinearSpline.js.map +1 -0
  46. package/dist/cjs/tools/annotation/splines/QuadraticBezier.d.ts +6 -0
  47. package/dist/cjs/tools/annotation/splines/QuadraticBezier.js +20 -0
  48. package/dist/cjs/tools/annotation/splines/QuadraticBezier.js.map +1 -0
  49. package/dist/cjs/tools/annotation/splines/QuadraticSpline.d.ts +9 -0
  50. package/dist/cjs/tools/annotation/splines/QuadraticSpline.js +18 -0
  51. package/dist/cjs/tools/annotation/splines/QuadraticSpline.js.map +1 -0
  52. package/dist/cjs/tools/annotation/splines/Spline.d.ts +49 -0
  53. package/dist/cjs/tools/annotation/splines/Spline.js +420 -0
  54. package/dist/cjs/tools/annotation/splines/Spline.js.map +1 -0
  55. package/dist/cjs/tools/index.d.ts +2 -1
  56. package/dist/cjs/tools/index.js +3 -1
  57. package/dist/cjs/tools/index.js.map +1 -1
  58. package/dist/cjs/types/CardinalSplineProps.d.ts +5 -0
  59. package/dist/cjs/types/CardinalSplineProps.js +3 -0
  60. package/dist/cjs/types/CardinalSplineProps.js.map +1 -0
  61. package/dist/cjs/types/ClosestControlPoint.d.ts +4 -0
  62. package/dist/cjs/types/ClosestControlPoint.js +3 -0
  63. package/dist/cjs/types/ClosestControlPoint.js.map +1 -0
  64. package/dist/cjs/types/ClosestPoint.d.ts +5 -0
  65. package/dist/cjs/types/ClosestPoint.js +3 -0
  66. package/dist/cjs/types/ClosestPoint.js.map +1 -0
  67. package/dist/cjs/types/ClosestSplinePoint.d.ts +4 -0
  68. package/dist/cjs/types/ClosestSplinePoint.js +3 -0
  69. package/dist/cjs/types/ClosestSplinePoint.js.map +1 -0
  70. package/dist/cjs/types/ControlPointInfo.d.ts +5 -0
  71. package/dist/cjs/types/ControlPointInfo.js +3 -0
  72. package/dist/cjs/types/ControlPointInfo.js.map +1 -0
  73. package/dist/cjs/types/ISpline.d.ts +29 -0
  74. package/dist/cjs/types/ISpline.js +3 -0
  75. package/dist/cjs/types/ISpline.js.map +1 -0
  76. package/dist/cjs/types/SplineCurveSegment.d.ts +14 -0
  77. package/dist/cjs/types/SplineCurveSegment.js +3 -0
  78. package/dist/cjs/types/SplineCurveSegment.js.map +1 -0
  79. package/dist/cjs/types/SplineLineSegment.d.ts +10 -0
  80. package/dist/cjs/types/SplineLineSegment.js +3 -0
  81. package/dist/cjs/types/SplineLineSegment.js.map +1 -0
  82. package/dist/cjs/types/SplineProps.d.ts +4 -0
  83. package/dist/cjs/types/SplineProps.js +3 -0
  84. package/dist/cjs/types/SplineProps.js.map +1 -0
  85. package/dist/cjs/types/ToolSpecificAnnotationTypes.d.ts +34 -0
  86. package/dist/cjs/types/index.d.ts +10 -1
  87. package/dist/cjs/utilities/index.d.ts +2 -3
  88. package/dist/cjs/utilities/index.js +5 -5
  89. package/dist/cjs/utilities/index.js.map +1 -1
  90. package/dist/cjs/utilities/math/aabb/distanceToPoint.d.ts +2 -0
  91. package/dist/cjs/utilities/math/aabb/distanceToPoint.js +11 -0
  92. package/dist/cjs/utilities/math/aabb/distanceToPoint.js.map +1 -0
  93. package/dist/cjs/utilities/math/aabb/distanceToPointSquared.d.ts +2 -0
  94. package/dist/cjs/utilities/math/aabb/distanceToPointSquared.js +24 -0
  95. package/dist/cjs/utilities/math/aabb/distanceToPointSquared.js.map +1 -0
  96. package/dist/cjs/utilities/math/aabb/index.d.ts +2 -0
  97. package/dist/cjs/utilities/math/aabb/index.js +11 -0
  98. package/dist/cjs/utilities/math/aabb/index.js.map +1 -0
  99. package/dist/cjs/utilities/math/index.d.ts +6 -5
  100. package/dist/cjs/utilities/math/index.js +11 -9
  101. package/dist/cjs/utilities/math/index.js.map +1 -1
  102. package/dist/cjs/utilities/math/line/distanceToPointSquared.js +5 -21
  103. package/dist/cjs/utilities/math/line/distanceToPointSquared.js.map +1 -1
  104. package/dist/cjs/utilities/math/line/distanceToPointSquaredInfo.d.ts +5 -0
  105. package/dist/cjs/utilities/math/line/distanceToPointSquaredInfo.js +56 -0
  106. package/dist/cjs/utilities/math/line/distanceToPointSquaredInfo.js.map +1 -0
  107. package/dist/cjs/utilities/math/line/index.d.ts +2 -1
  108. package/dist/cjs/utilities/math/line/index.js +3 -1
  109. package/dist/cjs/utilities/math/line/index.js.map +1 -1
  110. package/dist/cjs/utilities/math/point/distanceToPoint.js +5 -6
  111. package/dist/cjs/utilities/math/point/distanceToPoint.js.map +1 -1
  112. package/dist/cjs/utilities/math/point/distanceToPointSquared.d.ts +4 -0
  113. package/dist/cjs/utilities/math/point/distanceToPointSquared.js +12 -0
  114. package/dist/cjs/utilities/math/point/distanceToPointSquared.js.map +1 -0
  115. package/dist/cjs/utilities/math/point/index.d.ts +3 -2
  116. package/dist/cjs/utilities/math/point/index.js +7 -3
  117. package/dist/cjs/utilities/math/point/index.js.map +1 -1
  118. package/dist/cjs/utilities/math/point/mirror.d.ts +2 -0
  119. package/dist/cjs/utilities/math/point/mirror.js +11 -0
  120. package/dist/cjs/utilities/math/point/mirror.js.map +1 -0
  121. package/dist/esm/eventDispatchers/mouseEventHandlers/mouseDown.js +4 -4
  122. package/dist/esm/eventDispatchers/mouseEventHandlers/mouseDown.js.map +1 -1
  123. package/dist/esm/eventDispatchers/shared/getToolsWithActionsForMouseEvent.js +2 -1
  124. package/dist/esm/eventDispatchers/shared/getToolsWithActionsForMouseEvent.js.map +1 -1
  125. package/dist/esm/index.js +2 -2
  126. package/dist/esm/index.js.map +1 -1
  127. package/dist/esm/store/SynchronizerManager/Synchronizer.js +17 -1
  128. package/dist/esm/store/SynchronizerManager/Synchronizer.js.map +1 -1
  129. package/dist/esm/synchronizers/callbacks/areViewportsCoplanar .js.map +1 -1
  130. package/dist/esm/synchronizers/callbacks/{stackImageSyncCallback.js → imageSliceSyncCallback.js} +8 -4
  131. package/dist/esm/synchronizers/callbacks/imageSliceSyncCallback.js.map +1 -0
  132. package/dist/esm/synchronizers/index.js +3 -2
  133. package/dist/esm/synchronizers/index.js.map +1 -1
  134. package/dist/esm/synchronizers/synchronizers/createImageSliceSynchronizer.js +11 -0
  135. package/dist/esm/synchronizers/synchronizers/createImageSliceSynchronizer.js.map +1 -0
  136. package/dist/esm/synchronizers/synchronizers/index.js +3 -2
  137. package/dist/esm/synchronizers/synchronizers/index.js.map +1 -1
  138. package/dist/esm/tools/AdvancedMagnifyTool.js +8 -3
  139. package/dist/esm/tools/AdvancedMagnifyTool.js.map +1 -1
  140. package/dist/esm/tools/annotation/SplineROITool.js +703 -0
  141. package/dist/esm/tools/annotation/SplineROITool.js.map +1 -0
  142. package/dist/esm/tools/annotation/splines/BSpline.js +10 -0
  143. package/dist/esm/tools/annotation/splines/BSpline.js.map +1 -0
  144. package/dist/esm/tools/annotation/splines/CardinalSpline.js +33 -0
  145. package/dist/esm/tools/annotation/splines/CardinalSpline.js.map +1 -0
  146. package/dist/esm/tools/annotation/splines/CatmullRomSpline.js +8 -0
  147. package/dist/esm/tools/annotation/splines/CatmullRomSpline.js.map +1 -0
  148. package/dist/esm/tools/annotation/splines/CubicSpline.js +165 -0
  149. package/dist/esm/tools/annotation/splines/CubicSpline.js.map +1 -0
  150. package/dist/esm/tools/annotation/splines/LinearSpline.js +8 -0
  151. package/dist/esm/tools/annotation/splines/LinearSpline.js.map +1 -0
  152. package/dist/esm/tools/annotation/splines/QuadraticBezier.js +16 -0
  153. package/dist/esm/tools/annotation/splines/QuadraticBezier.js.map +1 -0
  154. package/dist/esm/tools/annotation/splines/QuadraticSpline.js +14 -0
  155. package/dist/esm/tools/annotation/splines/QuadraticSpline.js.map +1 -0
  156. package/dist/esm/tools/annotation/splines/Spline.js +392 -0
  157. package/dist/esm/tools/annotation/splines/Spline.js.map +1 -0
  158. package/dist/esm/tools/index.js +2 -1
  159. package/dist/esm/tools/index.js.map +1 -1
  160. package/dist/esm/types/CardinalSplineProps.js +2 -0
  161. package/dist/esm/types/CardinalSplineProps.js.map +1 -0
  162. package/dist/esm/types/ClosestControlPoint.js +2 -0
  163. package/dist/esm/types/ClosestControlPoint.js.map +1 -0
  164. package/dist/esm/types/ClosestPoint.js +2 -0
  165. package/dist/esm/types/ClosestPoint.js.map +1 -0
  166. package/dist/esm/types/ClosestSplinePoint.js +2 -0
  167. package/dist/esm/types/ClosestSplinePoint.js.map +1 -0
  168. package/dist/esm/types/ControlPointInfo.js +2 -0
  169. package/dist/esm/types/ControlPointInfo.js.map +1 -0
  170. package/dist/esm/types/ISpline.js +2 -0
  171. package/dist/esm/types/ISpline.js.map +1 -0
  172. package/dist/esm/types/SplineCurveSegment.js +2 -0
  173. package/dist/esm/types/SplineCurveSegment.js.map +1 -0
  174. package/dist/esm/types/SplineLineSegment.js +2 -0
  175. package/dist/esm/types/SplineLineSegment.js.map +1 -0
  176. package/dist/esm/types/SplineProps.js +2 -0
  177. package/dist/esm/types/SplineProps.js.map +1 -0
  178. package/dist/esm/utilities/index.js +2 -3
  179. package/dist/esm/utilities/index.js.map +1 -1
  180. package/dist/esm/utilities/math/aabb/distanceToPoint.js +5 -0
  181. package/dist/esm/utilities/math/aabb/distanceToPoint.js.map +1 -0
  182. package/dist/esm/utilities/math/aabb/distanceToPointSquared.js +21 -0
  183. package/dist/esm/utilities/math/aabb/distanceToPointSquared.js.map +1 -0
  184. package/dist/esm/utilities/math/aabb/index.js +3 -0
  185. package/dist/esm/utilities/math/aabb/index.js.map +1 -0
  186. package/dist/esm/utilities/math/index.js +6 -5
  187. package/dist/esm/utilities/math/index.js.map +1 -1
  188. package/dist/esm/utilities/math/line/distanceToPointSquared.js +2 -21
  189. package/dist/esm/utilities/math/line/distanceToPointSquared.js.map +1 -1
  190. package/dist/esm/utilities/math/line/distanceToPointSquaredInfo.js +30 -0
  191. package/dist/esm/utilities/math/line/distanceToPointSquaredInfo.js.map +1 -0
  192. package/dist/esm/utilities/math/line/index.js +2 -1
  193. package/dist/esm/utilities/math/line/index.js.map +1 -1
  194. package/dist/esm/utilities/math/point/distanceToPoint.js +2 -6
  195. package/dist/esm/utilities/math/point/distanceToPoint.js.map +1 -1
  196. package/dist/esm/utilities/math/point/distanceToPointSquared.js +9 -0
  197. package/dist/esm/utilities/math/point/distanceToPointSquared.js.map +1 -0
  198. package/dist/esm/utilities/math/point/index.js +3 -2
  199. package/dist/esm/utilities/math/point/index.js.map +1 -1
  200. package/dist/esm/utilities/math/point/mirror.js +8 -0
  201. package/dist/esm/utilities/math/point/mirror.js.map +1 -0
  202. package/dist/types/eventDispatchers/mouseEventHandlers/mouseDown.d.ts.map +1 -1
  203. package/dist/types/eventDispatchers/shared/getToolsWithActionsForMouseEvent.d.ts.map +1 -1
  204. package/dist/types/index.d.ts +2 -2
  205. package/dist/types/index.d.ts.map +1 -1
  206. package/dist/types/store/SynchronizerManager/Synchronizer.d.ts +1 -0
  207. package/dist/types/store/SynchronizerManager/Synchronizer.d.ts.map +1 -1
  208. package/dist/types/synchronizers/callbacks/areViewportsCoplanar .d.ts +1 -1
  209. package/dist/types/synchronizers/callbacks/areViewportsCoplanar .d.ts.map +1 -1
  210. package/dist/types/synchronizers/callbacks/{stackImageSyncCallback.d.ts → imageSliceSyncCallback.d.ts} +2 -2
  211. package/dist/types/synchronizers/callbacks/imageSliceSyncCallback.d.ts.map +1 -0
  212. package/dist/types/synchronizers/index.d.ts +3 -2
  213. package/dist/types/synchronizers/index.d.ts.map +1 -1
  214. package/dist/types/synchronizers/synchronizers/createImageSliceSynchronizer.d.ts +3 -0
  215. package/dist/types/synchronizers/synchronizers/createImageSliceSynchronizer.d.ts.map +1 -0
  216. package/dist/types/synchronizers/synchronizers/index.d.ts +3 -2
  217. package/dist/types/synchronizers/synchronizers/index.d.ts.map +1 -1
  218. package/dist/types/tools/AdvancedMagnifyTool.d.ts +4 -0
  219. package/dist/types/tools/AdvancedMagnifyTool.d.ts.map +1 -1
  220. package/dist/types/tools/annotation/SplineROITool.d.ts +60 -0
  221. package/dist/types/tools/annotation/SplineROITool.d.ts.map +1 -0
  222. package/dist/types/tools/annotation/splines/BSpline.d.ts +6 -0
  223. package/dist/types/tools/annotation/splines/BSpline.d.ts.map +1 -0
  224. package/dist/types/tools/annotation/splines/CardinalSpline.d.ts +13 -0
  225. package/dist/types/tools/annotation/splines/CardinalSpline.d.ts.map +1 -0
  226. package/dist/types/tools/annotation/splines/CatmullRomSpline.d.ts +6 -0
  227. package/dist/types/tools/annotation/splines/CatmullRomSpline.d.ts.map +1 -0
  228. package/dist/types/tools/annotation/splines/CubicSpline.d.ts +14 -0
  229. package/dist/types/tools/annotation/splines/CubicSpline.d.ts.map +1 -0
  230. package/dist/types/tools/annotation/splines/LinearSpline.d.ts +6 -0
  231. package/dist/types/tools/annotation/splines/LinearSpline.d.ts.map +1 -0
  232. package/dist/types/tools/annotation/splines/QuadraticBezier.d.ts +7 -0
  233. package/dist/types/tools/annotation/splines/QuadraticBezier.d.ts.map +1 -0
  234. package/dist/types/tools/annotation/splines/QuadraticSpline.d.ts +10 -0
  235. package/dist/types/tools/annotation/splines/QuadraticSpline.d.ts.map +1 -0
  236. package/dist/types/tools/annotation/splines/Spline.d.ts +50 -0
  237. package/dist/types/tools/annotation/splines/Spline.d.ts.map +1 -0
  238. package/dist/types/tools/index.d.ts +2 -1
  239. package/dist/types/tools/index.d.ts.map +1 -1
  240. package/dist/types/types/CardinalSplineProps.d.ts +6 -0
  241. package/dist/types/types/CardinalSplineProps.d.ts.map +1 -0
  242. package/dist/types/types/ClosestControlPoint.d.ts +5 -0
  243. package/dist/types/types/ClosestControlPoint.d.ts.map +1 -0
  244. package/dist/types/types/ClosestPoint.d.ts +6 -0
  245. package/dist/types/types/ClosestPoint.d.ts.map +1 -0
  246. package/dist/types/types/ClosestSplinePoint.d.ts +5 -0
  247. package/dist/types/types/ClosestSplinePoint.d.ts.map +1 -0
  248. package/dist/types/types/ControlPointInfo.d.ts +6 -0
  249. package/dist/types/types/ControlPointInfo.d.ts.map +1 -0
  250. package/dist/types/types/ISpline.d.ts +30 -0
  251. package/dist/types/types/ISpline.d.ts.map +1 -0
  252. package/dist/types/types/SplineCurveSegment.d.ts +15 -0
  253. package/dist/types/types/SplineCurveSegment.d.ts.map +1 -0
  254. package/dist/types/types/SplineLineSegment.d.ts +11 -0
  255. package/dist/types/types/SplineLineSegment.d.ts.map +1 -0
  256. package/dist/types/types/SplineProps.d.ts +5 -0
  257. package/dist/types/types/SplineProps.d.ts.map +1 -0
  258. package/dist/types/types/ToolSpecificAnnotationTypes.d.ts +34 -0
  259. package/dist/types/types/ToolSpecificAnnotationTypes.d.ts.map +1 -1
  260. package/dist/types/types/index.d.ts +10 -1
  261. package/dist/types/types/index.d.ts.map +1 -1
  262. package/dist/types/utilities/index.d.ts +2 -3
  263. package/dist/types/utilities/index.d.ts.map +1 -1
  264. package/dist/types/utilities/math/aabb/distanceToPoint.d.ts +3 -0
  265. package/dist/types/utilities/math/aabb/distanceToPoint.d.ts.map +1 -0
  266. package/dist/types/utilities/math/aabb/distanceToPointSquared.d.ts +3 -0
  267. package/dist/types/utilities/math/aabb/distanceToPointSquared.d.ts.map +1 -0
  268. package/dist/types/utilities/math/aabb/index.d.ts +3 -0
  269. package/dist/types/utilities/math/aabb/index.d.ts.map +1 -0
  270. package/dist/types/utilities/math/index.d.ts +6 -5
  271. package/dist/types/utilities/math/index.d.ts.map +1 -1
  272. package/dist/types/utilities/math/line/distanceToPointSquared.d.ts.map +1 -1
  273. package/dist/types/utilities/math/line/distanceToPointSquaredInfo.d.ts +6 -0
  274. package/dist/types/utilities/math/line/distanceToPointSquaredInfo.d.ts.map +1 -0
  275. package/dist/types/utilities/math/line/index.d.ts +2 -1
  276. package/dist/types/utilities/math/line/index.d.ts.map +1 -1
  277. package/dist/types/utilities/math/point/distanceToPoint.d.ts.map +1 -1
  278. package/dist/types/utilities/math/point/distanceToPointSquared.d.ts +5 -0
  279. package/dist/types/utilities/math/point/distanceToPointSquared.d.ts.map +1 -0
  280. package/dist/types/utilities/math/point/index.d.ts +3 -2
  281. package/dist/types/utilities/math/point/index.d.ts.map +1 -1
  282. package/dist/types/utilities/math/point/mirror.d.ts +3 -0
  283. package/dist/types/utilities/math/point/mirror.d.ts.map +1 -0
  284. package/dist/umd/index.js +2 -1
  285. package/dist/umd/index.js.LICENSE.txt +6 -0
  286. package/dist/umd/index.js.map +1 -1
  287. package/package.json +3 -3
  288. package/src/eventDispatchers/mouseEventHandlers/mouseDown.ts +8 -6
  289. package/src/eventDispatchers/shared/getToolsWithActionsForMouseEvent.ts +3 -2
  290. package/src/index.ts +2 -0
  291. package/src/store/SynchronizerManager/Synchronizer.ts +28 -3
  292. package/src/synchronizers/callbacks/areViewportsCoplanar .ts +2 -2
  293. package/src/synchronizers/callbacks/{stackImageSyncCallback.ts → imageSliceSyncCallback.ts} +16 -8
  294. package/src/synchronizers/index.ts +5 -1
  295. package/src/synchronizers/synchronizers/{createStackImageSynchronizer.ts → createImageSliceSynchronizer.ts} +8 -5
  296. package/src/synchronizers/synchronizers/index.ts +4 -1
  297. package/src/tools/AdvancedMagnifyTool.ts +8 -3
  298. package/src/tools/annotation/SplineROITool.ts +1151 -0
  299. package/src/tools/annotation/splines/BSpline.ts +22 -0
  300. package/src/tools/annotation/splines/CardinalSpline.ts +45 -0
  301. package/src/tools/annotation/splines/CatmullRomSpline.ts +19 -0
  302. package/src/tools/annotation/splines/CubicSpline.ts +288 -0
  303. package/src/tools/annotation/splines/LinearSpline.ts +20 -0
  304. package/src/tools/annotation/splines/QuadraticBezier.ts +20 -0
  305. package/src/tools/annotation/splines/QuadraticSpline.ts +25 -0
  306. package/src/tools/annotation/splines/Spline.ts +729 -0
  307. package/src/tools/index.ts +2 -0
  308. package/src/types/CardinalSplineProps.ts +11 -0
  309. package/src/types/ClosestControlPoint.ts +6 -0
  310. package/src/types/ClosestPoint.ts +8 -0
  311. package/src/types/ClosestSplinePoint.ts +6 -0
  312. package/src/types/ControlPointInfo.ts +8 -0
  313. package/src/types/ISpline.ts +164 -0
  314. package/src/types/SplineCurveSegment.ts +28 -0
  315. package/src/types/SplineLineSegment.ts +20 -0
  316. package/src/types/SplineProps.ts +15 -0
  317. package/src/types/ToolSpecificAnnotationTypes.ts +35 -0
  318. package/src/types/index.ts +21 -0
  319. package/src/utilities/index.ts +6 -2
  320. package/src/utilities/math/aabb/distanceToPoint.ts +20 -0
  321. package/src/utilities/math/aabb/distanceToPointSquared.ts +47 -0
  322. package/src/utilities/math/aabb/index.ts +2 -0
  323. package/src/utilities/math/index.ts +10 -8
  324. package/src/utilities/math/line/distanceToPointSquared.ts +3 -29
  325. package/src/utilities/math/line/distanceToPointSquaredInfo.ts +54 -0
  326. package/src/utilities/math/line/index.ts +7 -1
  327. package/src/utilities/math/point/distanceToPoint.ts +2 -10
  328. package/src/utilities/math/point/distanceToPointSquared.ts +21 -0
  329. package/src/utilities/math/point/index.ts +3 -3
  330. package/src/utilities/math/point/mirror.ts +21 -0
  331. package/dist/cjs/synchronizers/synchronizers/createStackImageSynchronizer.js +0 -15
  332. package/dist/cjs/synchronizers/synchronizers/createStackImageSynchronizer.js.map +0 -1
  333. package/dist/esm/synchronizers/callbacks/stackImageSyncCallback.js.map +0 -1
  334. package/dist/esm/synchronizers/synchronizers/createStackImageSynchronizer.js +0 -9
  335. package/dist/esm/synchronizers/synchronizers/createStackImageSynchronizer.js.map +0 -1
  336. package/dist/types/synchronizers/callbacks/stackImageSyncCallback.d.ts.map +0 -1
  337. package/dist/types/synchronizers/synchronizers/createStackImageSynchronizer.d.ts +0 -3
  338. package/dist/types/synchronizers/synchronizers/createStackImageSynchronizer.d.ts.map +0 -1
@@ -26,6 +26,7 @@ import DragProbeTool from './annotation/DragProbeTool';
26
26
  import RectangleROITool from './annotation/RectangleROITool';
27
27
  import EllipticalROITool from './annotation/EllipticalROITool';
28
28
  import CircleROITool from './annotation/CircleROITool';
29
+ import SplineROITool from './annotation/SplineROITool';
29
30
  import PlanarFreehandROITool from './annotation/PlanarFreehandROITool';
30
31
  import ArrowAnnotateTool from './annotation/ArrowAnnotateTool';
31
32
  import AngleTool from './annotation/AngleTool';
@@ -73,6 +74,7 @@ export {
73
74
  RectangleROITool,
74
75
  EllipticalROITool,
75
76
  CircleROITool,
77
+ SplineROITool,
76
78
  PlanarFreehandROITool,
77
79
  ArrowAnnotateTool,
78
80
  AngleTool,
@@ -0,0 +1,11 @@
1
+ import { SplineProps } from './SplineProps';
2
+
3
+ /**
4
+ * Cardinal spline properties
5
+ */
6
+ export type CardinalSplineProps = SplineProps & {
7
+ /** Scale that must be in 0-1 range */
8
+ scale?: number;
9
+ /** Fixed scale used by children classes (Catmull-Rom and Linear splines) */
10
+ fixedScale?: boolean;
11
+ };
@@ -0,0 +1,6 @@
1
+ import type { ClosestPoint } from './ClosestPoint';
2
+
3
+ export type ClosestControlPoint = ClosestPoint & {
4
+ /** Control point index */
5
+ index: number;
6
+ };
@@ -0,0 +1,8 @@
1
+ import { Types } from '@cornerstonejs/core';
2
+
3
+ export type ClosestPoint = {
4
+ /** 2D coordinate */
5
+ point: Types.Point2;
6
+ /** Distance to the reference point */
7
+ distance: number;
8
+ };
@@ -0,0 +1,6 @@
1
+ import type { ClosestPoint } from './ClosestPoint';
2
+
3
+ export type ClosestSplinePoint = ClosestPoint & {
4
+ /** `u` value in Parameter Space (curve segment index + `t` value from 0-1) */
5
+ uValue: number;
6
+ };
@@ -0,0 +1,8 @@
1
+ import { Types } from '@cornerstonejs/core';
2
+
3
+ export type ControlPointInfo = {
4
+ /** Control point index */
5
+ index: number;
6
+ /** 2D coordinate */
7
+ point: Types.Point2;
8
+ };
@@ -0,0 +1,164 @@
1
+ import { Types } from '@cornerstonejs/core';
2
+ import type {
3
+ ClosestPoint,
4
+ ClosestControlPoint,
5
+ ClosestSplinePoint,
6
+ ControlPointInfo,
7
+ } from './';
8
+
9
+ /**
10
+ * Spline curve interface
11
+ */
12
+ export interface ISpline {
13
+ /** Number of control points */
14
+ get numControlPoints(): number;
15
+
16
+ /** Resolution of the spline curve (greater than or equal to 0) */
17
+ get resolution(): number;
18
+
19
+ /** Set the resolution of the spline curve */
20
+ set resolution(resolution: number);
21
+
22
+ /** Flag that is set to true when the curve is already closed */
23
+ get closed(): boolean;
24
+
25
+ /** Set the curve as closed which connects the last to the first point */
26
+ set closed(closed: boolean);
27
+
28
+ /** Axis-aligned bounding box (minX, minY, maxX, maxY) */
29
+ get aabb(): Types.AABB2;
30
+
31
+ /** Length of the spline curve in pixels */
32
+ get length(): number;
33
+
34
+ /**
35
+ * Flag that is set to true when the spline needs to be updated. The update
36
+ * runs automaticaly when needed (eg: getPolylinePoints).
37
+ */
38
+ get invalidated(): boolean;
39
+
40
+ /**
41
+ * Bézier curves have tangent points connected to control points
42
+ * @returns True if the spline has tangent point or false otherwise
43
+ */
44
+ hasTangentPoints(): boolean;
45
+
46
+ /**
47
+ * Add a control point to the end of the array
48
+ * @param point - Control point (2D)
49
+ */
50
+ addControlPoint(point: Types.Point2): void;
51
+
52
+ /**
53
+ * Add a list of control poits to the end of the array
54
+ * @param points - Control points to be added
55
+ */
56
+ addControlPoints(points: Types.Point2[]): void;
57
+
58
+ /**
59
+ * Add a control point specifying its `u` value in Parameter Space which is a number from 0 to N
60
+ * where N is the number of curve segments. The integer part is the curve segment index and the
61
+ * decimal part is the `t` value on that curve segment.
62
+ * @param u - `u` value in Parameter Space
63
+ */
64
+ addControlPointAtU(u: number): ControlPointInfo;
65
+
66
+ /**
67
+ * Delete a control point given its index
68
+ * @param index - Control point index to be removed
69
+ * @returns True if the control point is removed or false otherwise
70
+ */
71
+ deleteControlPointByIndex(index: number): boolean;
72
+
73
+ /**
74
+ * Remove all control points
75
+ */
76
+ clearControlPoints(): void;
77
+
78
+ /**
79
+ * Replace all control points by some new ones
80
+ * @param points - Control points to be added to the array
81
+ */
82
+ setControlPoints(points: Types.Point2[]): void;
83
+
84
+ /**
85
+ * Update the coordinate of a control point given its index
86
+ * @param index - Control point index
87
+ * @param newControlPoint - New control point
88
+ */
89
+ updateControlPoint(index: number, newControlPoint: Types.Point2): void;
90
+
91
+ /**
92
+ * Get a list with all control points. The control points are cloned to prevent
93
+ * any caller from changing them resulting in unexpected behaviors
94
+ * @returns - List of all control points
95
+ */
96
+ getControlPoints(): Types.Point2[];
97
+
98
+ /**
99
+ * Finds the closest control point given a 2D point
100
+ * @param point - Reference point
101
+ * @returns Closest control point
102
+ */
103
+ getClosestControlPoint(point: Types.Point2): ClosestControlPoint;
104
+
105
+ /**
106
+ * Finds the closest control point given a 2D point and a maximum distance
107
+ * @param point - Reference 2D point
108
+ * @param maxDist - Maximum distance
109
+ * @returns Closest control point that is within the given range or undefined otherwise
110
+ */
111
+ getClosestControlPointWithinDistance(
112
+ point: Types.Point2,
113
+ range: number
114
+ ): ClosestControlPoint;
115
+
116
+ /**
117
+ * Finds the closest point on the spline curve given 2D point
118
+ * @param point - Reference 2D point
119
+ * @returns Closest point on the spline curve
120
+ */
121
+ getClosestPoint(point: Types.Point2): ClosestSplinePoint;
122
+
123
+ /**
124
+ * Finds the closest point on the straight line that connects all control points given a 2D point
125
+ * @param point - Reference point
126
+ * @returns Closest point on the straight line that connects all control points
127
+ */
128
+ getClosestPointOnControlPointLines(point: Types.Point2): ClosestPoint;
129
+
130
+ /**
131
+ * Get all points necessary to draw a spline curve
132
+ * @returns Array with all points necessary to draw a spline curve
133
+ */
134
+ getPolylinePoints(): Types.Point2[];
135
+
136
+ /**
137
+ * Get all points necessary to draw the preview curve for a new possible control point
138
+ * @returns Array with all points necessary to draw the preview curve
139
+ */
140
+ getPreviewPolylinePoints(
141
+ controlPointPreview: Types.Point2,
142
+ closeDistance: number
143
+ ): Types.Point2[];
144
+
145
+ /**
146
+ * Checks if a point is near to the spline curve
147
+ * @param point - Reference point
148
+ * @param maxDist - Maximum allowed distance
149
+ * @returns True if the point is close to the spline curve or false otherwise
150
+ */
151
+ isPointNearCurve(point: Types.Point2, maxDist: number): boolean;
152
+
153
+ /**
154
+ * Checks if a 2D point is inside the spline curve.
155
+ *
156
+ * A point is inside a curve/polygon if the number of intersections between the horizontal
157
+ * ray emanating from the given point and to the right and the line segments is odd.
158
+ * https://www.eecs.umich.edu/courses/eecs380/HANDOUTS/PROJ2/InsidePoly.html
159
+ *
160
+ * @param point - 2D Point
161
+ * @returns True is the point is inside the spline curve or false otherwise
162
+ */
163
+ containsPoint(point: Types.Point2): boolean;
164
+ }
@@ -0,0 +1,28 @@
1
+ import { Types } from '@cornerstonejs/core';
2
+ import type { SplineLineSegment } from './SplineLineSegment';
3
+
4
+ /**
5
+ * Spline curve segment the is part of a spline path
6
+ */
7
+ export type SplineCurveSegment = {
8
+ /**
9
+ * Control Points that influences the spline curve segment.
10
+ *
11
+ * For cubic splines the curve goes from P1 and P2 but it is also influenced by the
12
+ * previous point (P0) and the next point (P3)
13
+ */
14
+ controlPoints: {
15
+ p0: Types.Point2;
16
+ p1: Types.Point2;
17
+ p2: Types.Point2;
18
+ p3: Types.Point2;
19
+ };
20
+ /** Axis-aligned bounding (minX, minY, maxX, maxY) */
21
+ aabb: Types.AABB2;
22
+ /** Length of the curve segment */
23
+ length: number;
24
+ /** Total length of all previous curve segments */
25
+ previousCurveSegmentsLength: number;
26
+ /** Line segments that makes the curve segment */
27
+ lineSegments: SplineLineSegment[];
28
+ };
@@ -0,0 +1,20 @@
1
+ import { Types } from '@cornerstonejs/core';
2
+
3
+ /**
4
+ * Line segment the is part of a curve segment based on its resolution.
5
+ * Each curve segment shall have 20 line segments when spline resolution
6
+ * is set to 20.
7
+ */
8
+ export type SplineLineSegment = {
9
+ /** Start and end points for the line segment */
10
+ points: {
11
+ start: Types.Point2;
12
+ end: Types.Point2;
13
+ };
14
+ /** Axis-aligned bounding (minX, minY, maxX, maxY) */
15
+ aabb: Types.AABB2;
16
+ /** Length of the line segment */
17
+ length: number;
18
+ /** Total length of all previous line segments for a given curve segment */
19
+ previousLineSegmentsLength: number;
20
+ };
@@ -0,0 +1,15 @@
1
+ export type SplineProps = {
2
+ /**
3
+ * Resolution of the spline curve
4
+ *
5
+ * The number assigned to the resolution is the number of intermediate points on each
6
+ * curve segment that makes the spline path. For example, if the resolution is set to 0
7
+ * that means that each curve segment will have no intermediate points but only a straight
8
+ * line similar to Linear Spline. For a resolution equal to 20 that means the curve shall
9
+ * have 20 intermediate points or 21 line segments total making it look more like a curve.
10
+ */
11
+ resolution?: number;
12
+
13
+ /** Flag that is set to true when the curve is closed */
14
+ closed?: boolean;
15
+ };
@@ -1,5 +1,6 @@
1
1
  import type { Types } from '@cornerstonejs/core';
2
2
  import { Annotation } from './AnnotationTypes';
3
+ import { ISpline } from './';
3
4
 
4
5
  interface ROICachedStats {
5
6
  [targetId: string]: {
@@ -117,6 +118,40 @@ export interface CircleROIAnnotation extends Annotation {
117
118
  };
118
119
  }
119
120
 
121
+ export interface SplineROIAnnotation extends Annotation {
122
+ data: {
123
+ label?: string;
124
+ handles: {
125
+ points: Types.Point3[];
126
+ activeHandleIndex: number | null;
127
+ textBox?: {
128
+ hasMoved: boolean;
129
+ worldPosition: Types.Point3;
130
+ worldBoundingBox: {
131
+ topLeft: Types.Point3;
132
+ topRight: Types.Point3;
133
+ bottomLeft: Types.Point3;
134
+ bottomRight: Types.Point3;
135
+ };
136
+ };
137
+ };
138
+ spline: {
139
+ type: string;
140
+ instance: ISpline;
141
+ resolution: number;
142
+ polyline: Types.Point3[];
143
+ closed: boolean;
144
+ };
145
+ cachedStats?: {
146
+ [targetId: string]: {
147
+ Modality: string;
148
+ area: number;
149
+ areaUnit: string;
150
+ };
151
+ };
152
+ };
153
+ }
154
+
120
155
  export interface EllipticalROIAnnotation extends Annotation {
121
156
  data: {
122
157
  handles: {
@@ -64,6 +64,17 @@ import {
64
64
  LabelmapToolOperationDataVolume,
65
65
  } from './LabelmapToolOperationData';
66
66
 
67
+ // Splines
68
+ import type { CardinalSplineProps } from './CardinalSplineProps';
69
+ import type { ClosestControlPoint } from './ClosestControlPoint';
70
+ import type { ClosestPoint } from './ClosestPoint';
71
+ import type { ClosestSplinePoint } from './ClosestSplinePoint';
72
+ import type { ControlPointInfo } from './ControlPointInfo';
73
+ import type { ISpline } from './ISpline';
74
+ import type { SplineCurveSegment } from './SplineCurveSegment';
75
+ import type { SplineLineSegment } from './SplineLineSegment';
76
+ import type { SplineProps } from './SplineProps';
77
+
67
78
  export type {
68
79
  // AnnotationState
69
80
  Annotation,
@@ -132,4 +143,14 @@ export type {
132
143
  LabelmapToolOperationData,
133
144
  LabelmapToolOperationDataStack,
134
145
  LabelmapToolOperationDataVolume,
146
+ // Splines
147
+ CardinalSplineProps,
148
+ ClosestControlPoint,
149
+ ClosestPoint,
150
+ ClosestSplinePoint,
151
+ ControlPointInfo,
152
+ ISpline,
153
+ SplineCurveSegment,
154
+ SplineLineSegment,
155
+ SplineProps,
135
156
  };
@@ -9,8 +9,11 @@ import throttle from './throttle';
9
9
  import isObject from './isObject';
10
10
  import clip from './clip';
11
11
  import calibrateImageSpacing from './calibrateImageSpacing';
12
- import getCalibratedLengthUnits from './getCalibratedUnits';
13
- import { getCalibratedScale } from './getCalibratedUnits';
12
+ import {
13
+ getCalibratedLengthUnits,
14
+ getCalibratedAreaUnits,
15
+ getCalibratedScale,
16
+ } from './getCalibratedUnits';
14
17
  import triggerAnnotationRenderForViewportIds from './triggerAnnotationRenderForViewportIds';
15
18
  import triggerAnnotationRender from './triggerAnnotationRender';
16
19
  import jumpToSlice from './viewport/jumpToSlice';
@@ -57,6 +60,7 @@ export {
57
60
  triggerEvent,
58
61
  calibrateImageSpacing,
59
62
  getCalibratedLengthUnits,
63
+ getCalibratedAreaUnits,
60
64
  getCalibratedScale,
61
65
  segmentation,
62
66
  triggerAnnotationRenderForViewportIds,
@@ -0,0 +1,20 @@
1
+ import { Types } from '@cornerstonejs/core';
2
+ import distanceToPointSquared from './distanceToPointSquared';
3
+
4
+ /**
5
+ * Calculates the squared distance of a point to an AABB using
6
+ * 2D Box SDF (Signed Distance Field)
7
+ *
8
+ * The SDF of a Box
9
+ * https://www.youtube.com/watch?v=62-pRVZuS5c
10
+ *
11
+ * @param aabb - Axis-aligned bound box (minX, minY, maxX and maxY)
12
+ * @param point - 2D point
13
+ * @returns The squared distance between the 2D point and the AABB
14
+ */
15
+ export default function distanceToPoint(
16
+ aabb: Types.AABB2,
17
+ point: Types.Point2
18
+ ): number {
19
+ return Math.sqrt(distanceToPointSquared(aabb, point));
20
+ }
@@ -0,0 +1,47 @@
1
+ import { Types } from '@cornerstonejs/core';
2
+
3
+ /**
4
+ * Calculates the distance of a point to an AABB using 2D Box SDF (Signed Distance Field)
5
+ *
6
+ * The SDF of a Box
7
+ * https://www.youtube.com/watch?v=62-pRVZuS5c
8
+ *
9
+ * @param aabb - Axis-aligned bound box
10
+ * @param point - 2D point
11
+ * @returns The closest distance between the 2D point and the AABB
12
+ */
13
+ export default function distanceToPointSquared(
14
+ aabb: Types.AABB2,
15
+ point: Types.Point2
16
+ ): number {
17
+ const aabbWidth = aabb.maxX - aabb.minX;
18
+ const aabbHeight = aabb.maxY - aabb.minY;
19
+ const aabbSize = [aabbWidth, aabbHeight];
20
+ const aabbCenter: Types.Point2 = [
21
+ aabb.minX + aabbWidth / 2,
22
+ aabb.minY + aabbHeight / 2,
23
+ ];
24
+
25
+ // Translates the point as the center of the AABB is the new origin.
26
+ // THe point is also mirroed to the first quadrant to simplify the math.
27
+ const translatedPoint = [
28
+ Math.abs(point[0] - aabbCenter[0]),
29
+ Math.abs(point[1] - aabbCenter[1]),
30
+ ];
31
+
32
+ // Calculate the distance from the point to the vertical and horizontal AABB borders
33
+ const dx = translatedPoint[0] - aabbSize[0] * 0.5;
34
+ const dy = translatedPoint[1] - aabbSize[1] * 0.5;
35
+
36
+ // dx > 0 && dy > 0: diagonal line connecting the point to AABB's corner
37
+ // dx > 0 && dy <= 0: a line parallel to x-axis connecting the point to AABB's right side
38
+ // dx <= 0 && dy > 0: a line parallel to y-axis connecting the point to AABB's top side
39
+ // dx <= 0 && dy <= 0: the point is inside the AABB
40
+ if (dx > 0 && dy > 0) {
41
+ return dx * dx + dy * dy;
42
+ }
43
+
44
+ const dist = Math.max(dx, 0) + Math.max(dy, 0);
45
+
46
+ return dist * dist;
47
+ }
@@ -0,0 +1,2 @@
1
+ export { default as distanceToPoint } from './distanceToPoint';
2
+ export { default as distanceToPointSquared } from './distanceToPointSquared';
@@ -1,17 +1,19 @@
1
- import * as vec2 from './vec2';
1
+ import * as aabb from './aabb';
2
+ import * as BasicStatsCalculator from './basic';
2
3
  import * as ellipse from './ellipse';
3
4
  import * as lineSegment from './line';
4
- import * as rectangle from './rectangle';
5
- import * as polyline from './polyline';
6
5
  import * as point from './point';
7
- import * as BasicStatsCalculator from './basic';
6
+ import * as polyline from './polyline';
7
+ import * as rectangle from './rectangle';
8
+ import * as vec2 from './vec2';
8
9
 
9
10
  export {
10
- vec2,
11
+ aabb,
12
+ BasicStatsCalculator,
11
13
  ellipse,
12
14
  lineSegment,
13
- rectangle,
14
- polyline,
15
15
  point,
16
- BasicStatsCalculator,
16
+ polyline,
17
+ rectangle,
18
+ vec2,
17
19
  };
@@ -1,11 +1,8 @@
1
1
  import { Types } from '@cornerstonejs/core';
2
-
3
- function dist2(p1: Types.Point2, p2: Types.Point2): number {
4
- return (p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]);
5
- }
2
+ import distanceToPointSquaredInfo from './distanceToPointSquaredInfo';
6
3
 
7
4
  /**
8
- * Calculates the distance-squared of a point to a line
5
+ * Calculates the distance-squared of a point to a line segment
9
6
  *
10
7
  * @param lineStart - x,y coordinates of the start of the line
11
8
  * @param lineEnd - x,y coordinates of the end of the line
@@ -17,28 +14,5 @@ export default function distanceToPointSquared(
17
14
  lineEnd: Types.Point2,
18
15
  point: Types.Point2
19
16
  ): number {
20
- const d2 = dist2(lineStart, lineEnd);
21
-
22
- if (d2 === 0) {
23
- return dist2(point, lineStart);
24
- }
25
-
26
- const t =
27
- ((point[0] - lineStart[0]) * (lineEnd[0] - lineStart[0]) +
28
- (point[1] - lineStart[1]) * (lineEnd[1] - lineStart[1])) /
29
- d2;
30
-
31
- if (t < 0) {
32
- return dist2(point, lineStart);
33
- }
34
- if (t > 1) {
35
- return dist2(point, lineEnd);
36
- }
37
-
38
- const pt: Types.Point2 = [
39
- lineStart[0] + t * (lineEnd[0] - lineStart[0]),
40
- lineStart[1] + t * (lineEnd[1] - lineStart[1]),
41
- ];
42
-
43
- return dist2(point, pt);
17
+ return distanceToPointSquaredInfo(lineStart, lineEnd, point).distanceSquared;
44
18
  }
@@ -0,0 +1,54 @@
1
+ import type { Types } from '@cornerstonejs/core';
2
+ import * as math from '../';
3
+
4
+ /**
5
+ * Calculate the closest point and the squared distance between a reference point and a line segment.
6
+ *
7
+ * It projects the reference point onto the line segment but it shall be bounded by the
8
+ * start/end points since this is a line segment and not a line which could be extended.
9
+ *
10
+ * @param lineStart - Start point of the line segment
11
+ * @param lineEnd - End point of the line segment
12
+ * @param point - Reference point
13
+ * @returns Closest point and the squared distance between a `point` and a line
14
+ * segment defined by `lineStart` and `lineEnd` points
15
+ */
16
+ export default function distanceToPointSquaredInfo(
17
+ lineStart: Types.Point2,
18
+ lineEnd: Types.Point2,
19
+ point: Types.Point2
20
+ ): {
21
+ point: Types.Point2;
22
+ distanceSquared: number;
23
+ } {
24
+ let closestPoint: Types.Point2;
25
+ const distanceSquared = math.point.distanceToPointSquared(lineStart, lineEnd);
26
+
27
+ // Check if lineStart is the same as lineEnd which means
28
+ if (lineStart[0] === lineEnd[0] && lineStart[1] === lineEnd[1]) {
29
+ closestPoint = lineStart;
30
+ }
31
+
32
+ if (!closestPoint) {
33
+ const dotProduct =
34
+ ((point[0] - lineStart[0]) * (lineEnd[0] - lineStart[0]) +
35
+ (point[1] - lineStart[1]) * (lineEnd[1] - lineStart[1])) /
36
+ distanceSquared;
37
+
38
+ if (dotProduct < 0) {
39
+ closestPoint = lineStart;
40
+ } else if (dotProduct > 1) {
41
+ closestPoint = lineEnd;
42
+ } else {
43
+ closestPoint = [
44
+ lineStart[0] + dotProduct * (lineEnd[0] - lineStart[0]),
45
+ lineStart[1] + dotProduct * (lineEnd[1] - lineStart[1]),
46
+ ];
47
+ }
48
+ }
49
+
50
+ return {
51
+ point: [...closestPoint],
52
+ distanceSquared: math.point.distanceToPointSquared(point, closestPoint),
53
+ };
54
+ }
@@ -1,5 +1,11 @@
1
1
  import distanceToPoint from './distanceToPoint';
2
2
  import distanceToPointSquared from './distanceToPointSquared';
3
+ import distanceToPointSquaredInfo from './distanceToPointSquaredInfo';
3
4
  import intersectLine from './intersectLine';
4
5
 
5
- export { distanceToPoint, distanceToPointSquared, intersectLine };
6
+ export {
7
+ distanceToPoint,
8
+ distanceToPointSquared,
9
+ distanceToPointSquaredInfo,
10
+ intersectLine,
11
+ };
@@ -1,4 +1,5 @@
1
1
  import type { Types } from '@cornerstonejs/core';
2
+ import distanceToPointSquared from './distanceToPointSquared';
2
3
 
3
4
  type Point = Types.Point2 | Types.Point3;
4
5
 
@@ -10,14 +11,5 @@ type Point = Types.Point2 | Types.Point3;
10
11
  * @returns distance
11
12
  */
12
13
  export default function distanceToPoint(p1: Point, p2: Point): number {
13
- if (p1.length !== p2.length) {
14
- throw Error('Both points should have the same dimensionality');
15
- }
16
-
17
- const [x1, y1, z1 = 0] = p1;
18
- const [x2, y2, z2 = 0] = p2;
19
-
20
- return Math.sqrt(
21
- Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2) + Math.pow(z1 - z2, 2)
22
- );
14
+ return Math.sqrt(distanceToPointSquared(p1, p2));
23
15
  }
@@ -0,0 +1,21 @@
1
+ import type { Types } from '@cornerstonejs/core';
2
+
3
+ type Point = Types.Point2 | Types.Point3;
4
+
5
+ /**
6
+ * Calculates the distance squared of a point to another point
7
+ *
8
+ * @param p1 - x,y or x,y,z of the point
9
+ * @param p2 - x,y or x,y,z of the point
10
+ * @returns distance
11
+ */
12
+ export default function distanceToPointSquared(p1: Point, p2: Point): number {
13
+ if (p1.length !== p2.length) {
14
+ throw Error('Both points should have the same dimensionality');
15
+ }
16
+
17
+ const [x1, y1, z1 = 0] = p1;
18
+ const [x2, y2, z2 = 0] = p2;
19
+
20
+ return Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2) + Math.pow(z1 - z2, 2);
21
+ }
@@ -1,3 +1,3 @@
1
- import distanceToPoint from './distanceToPoint';
2
-
3
- export { distanceToPoint };
1
+ export { default as distanceToPoint } from './distanceToPoint';
2
+ export { default as distanceToPointSquared } from './distanceToPointSquared';
3
+ export { default as mirror } from './mirror';