@itwin/core-geometry 4.0.0-dev.4 → 4.0.0-dev.41

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 (344) hide show
  1. package/CHANGELOG.md +17 -3
  2. package/lib/cjs/Geometry.d.ts +56 -16
  3. package/lib/cjs/Geometry.d.ts.map +1 -1
  4. package/lib/cjs/Geometry.js +87 -30
  5. package/lib/cjs/Geometry.js.map +1 -1
  6. package/lib/cjs/bspline/BSplineCurveOps.js +4 -5
  7. package/lib/cjs/bspline/BSplineCurveOps.js.map +1 -1
  8. package/lib/cjs/bspline/InterpolationCurve3d.js +7 -10
  9. package/lib/cjs/bspline/InterpolationCurve3d.js.map +1 -1
  10. package/lib/cjs/clipping/ClipPrimitive.js +2 -2
  11. package/lib/cjs/clipping/ClipPrimitive.js.map +1 -1
  12. package/lib/cjs/clipping/ClipUtils.js +4 -4
  13. package/lib/cjs/clipping/ClipUtils.js.map +1 -1
  14. package/lib/cjs/clipping/internalContexts/LineStringOffsetClipperContext.js +2 -2
  15. package/lib/cjs/clipping/internalContexts/LineStringOffsetClipperContext.js.map +1 -1
  16. package/lib/cjs/curve/CurveChainWithDistanceIndex.d.ts.map +1 -1
  17. package/lib/cjs/curve/CurveChainWithDistanceIndex.js +20 -13
  18. package/lib/cjs/curve/CurveChainWithDistanceIndex.js.map +1 -1
  19. package/lib/cjs/curve/CurveCollection.js +1 -1
  20. package/lib/cjs/curve/CurveCollection.js.map +1 -1
  21. package/lib/cjs/curve/CurveCurve.d.ts +11 -8
  22. package/lib/cjs/curve/CurveCurve.d.ts.map +1 -1
  23. package/lib/cjs/curve/CurveCurve.js +16 -12
  24. package/lib/cjs/curve/CurveCurve.js.map +1 -1
  25. package/lib/cjs/curve/CurveCurveIntersectXY.d.ts +5 -1
  26. package/lib/cjs/curve/CurveCurveIntersectXY.d.ts.map +1 -1
  27. package/lib/cjs/curve/CurveCurveIntersectXY.js +11 -10
  28. package/lib/cjs/curve/CurveCurveIntersectXY.js.map +1 -1
  29. package/lib/cjs/curve/Loop.d.ts +2 -2
  30. package/lib/cjs/curve/Loop.d.ts.map +1 -1
  31. package/lib/cjs/curve/Loop.js +6 -0
  32. package/lib/cjs/curve/Loop.js.map +1 -1
  33. package/lib/cjs/curve/RegionOps.d.ts +10 -10
  34. package/lib/cjs/curve/RegionOps.d.ts.map +1 -1
  35. package/lib/cjs/curve/RegionOps.js +11 -11
  36. package/lib/cjs/curve/RegionOps.js.map +1 -1
  37. package/lib/cjs/curve/RegionOpsClassificationSweeps.d.ts +2 -1
  38. package/lib/cjs/curve/RegionOpsClassificationSweeps.d.ts.map +1 -1
  39. package/lib/cjs/curve/RegionOpsClassificationSweeps.js +5 -2
  40. package/lib/cjs/curve/RegionOpsClassificationSweeps.js.map +1 -1
  41. package/lib/cjs/curve/StrokeOptions.js +1 -2
  42. package/lib/cjs/curve/StrokeOptions.js.map +1 -1
  43. package/lib/cjs/curve/spiral/DirectSpiral3d.js +1 -2
  44. package/lib/cjs/curve/spiral/DirectSpiral3d.js.map +1 -1
  45. package/lib/cjs/curve/spiral/IntegratedSpiral3d.js +1 -2
  46. package/lib/cjs/curve/spiral/IntegratedSpiral3d.js.map +1 -1
  47. package/lib/cjs/geometry3d/Angle.d.ts +19 -0
  48. package/lib/cjs/geometry3d/Angle.d.ts.map +1 -1
  49. package/lib/cjs/geometry3d/Angle.js +39 -0
  50. package/lib/cjs/geometry3d/Angle.js.map +1 -1
  51. package/lib/cjs/geometry3d/AngleSweep.d.ts +1 -0
  52. package/lib/cjs/geometry3d/AngleSweep.d.ts.map +1 -1
  53. package/lib/cjs/geometry3d/AngleSweep.js +1 -0
  54. package/lib/cjs/geometry3d/AngleSweep.js.map +1 -1
  55. package/lib/cjs/geometry3d/BarycentricTriangle.d.ts +195 -8
  56. package/lib/cjs/geometry3d/BarycentricTriangle.d.ts.map +1 -1
  57. package/lib/cjs/geometry3d/BarycentricTriangle.js +459 -11
  58. package/lib/cjs/geometry3d/BarycentricTriangle.js.map +1 -1
  59. package/lib/cjs/geometry3d/CoincidentGeometryOps.d.ts +1 -0
  60. package/lib/cjs/geometry3d/CoincidentGeometryOps.d.ts.map +1 -1
  61. package/lib/cjs/geometry3d/CoincidentGeometryOps.js +3 -0
  62. package/lib/cjs/geometry3d/CoincidentGeometryOps.js.map +1 -1
  63. package/lib/cjs/geometry3d/GrowableFloat64Array.js +2 -2
  64. package/lib/cjs/geometry3d/GrowableFloat64Array.js.map +1 -1
  65. package/lib/cjs/geometry3d/GrowableXYArray.d.ts +1 -1
  66. package/lib/cjs/geometry3d/GrowableXYArray.d.ts.map +1 -1
  67. package/lib/cjs/geometry3d/GrowableXYArray.js +2 -2
  68. package/lib/cjs/geometry3d/GrowableXYArray.js.map +1 -1
  69. package/lib/cjs/geometry3d/GrowableXYZArray.js +1 -1
  70. package/lib/cjs/geometry3d/GrowableXYZArray.js.map +1 -1
  71. package/lib/cjs/geometry3d/IndexedXYCollection.d.ts +22 -7
  72. package/lib/cjs/geometry3d/IndexedXYCollection.d.ts.map +1 -1
  73. package/lib/cjs/geometry3d/IndexedXYCollection.js +41 -5
  74. package/lib/cjs/geometry3d/IndexedXYCollection.js.map +1 -1
  75. package/lib/cjs/geometry3d/IndexedXYZCollection.d.ts +58 -4
  76. package/lib/cjs/geometry3d/IndexedXYZCollection.d.ts.map +1 -1
  77. package/lib/cjs/geometry3d/IndexedXYZCollection.js +102 -4
  78. package/lib/cjs/geometry3d/IndexedXYZCollection.js.map +1 -1
  79. package/lib/cjs/geometry3d/Matrix3d.d.ts +479 -265
  80. package/lib/cjs/geometry3d/Matrix3d.d.ts.map +1 -1
  81. package/lib/cjs/geometry3d/Matrix3d.js +996 -784
  82. package/lib/cjs/geometry3d/Matrix3d.js.map +1 -1
  83. package/lib/cjs/geometry3d/OrderedRotationAngles.d.ts +1 -0
  84. package/lib/cjs/geometry3d/OrderedRotationAngles.d.ts.map +1 -1
  85. package/lib/cjs/geometry3d/OrderedRotationAngles.js +1 -0
  86. package/lib/cjs/geometry3d/OrderedRotationAngles.js.map +1 -1
  87. package/lib/cjs/geometry3d/Point2dArrayCarrier.d.ts +10 -0
  88. package/lib/cjs/geometry3d/Point2dArrayCarrier.d.ts.map +1 -1
  89. package/lib/cjs/geometry3d/Point2dArrayCarrier.js +14 -0
  90. package/lib/cjs/geometry3d/Point2dArrayCarrier.js.map +1 -1
  91. package/lib/cjs/geometry3d/Point2dVector2d.js +4 -6
  92. package/lib/cjs/geometry3d/Point2dVector2d.js.map +1 -1
  93. package/lib/cjs/geometry3d/Point3dArrayCarrier.d.ts +0 -6
  94. package/lib/cjs/geometry3d/Point3dArrayCarrier.d.ts.map +1 -1
  95. package/lib/cjs/geometry3d/Point3dArrayCarrier.js +0 -6
  96. package/lib/cjs/geometry3d/Point3dArrayCarrier.js.map +1 -1
  97. package/lib/cjs/geometry3d/Point3dVector3d.d.ts +57 -57
  98. package/lib/cjs/geometry3d/Point3dVector3d.d.ts.map +1 -1
  99. package/lib/cjs/geometry3d/Point3dVector3d.js +63 -65
  100. package/lib/cjs/geometry3d/Point3dVector3d.js.map +1 -1
  101. package/lib/cjs/geometry3d/PointHelpers.d.ts +14 -1
  102. package/lib/cjs/geometry3d/PointHelpers.d.ts.map +1 -1
  103. package/lib/cjs/geometry3d/PointHelpers.js +33 -1
  104. package/lib/cjs/geometry3d/PointHelpers.js.map +1 -1
  105. package/lib/cjs/geometry3d/PolygonOps.d.ts +127 -19
  106. package/lib/cjs/geometry3d/PolygonOps.d.ts.map +1 -1
  107. package/lib/cjs/geometry3d/PolygonOps.js +420 -22
  108. package/lib/cjs/geometry3d/PolygonOps.js.map +1 -1
  109. package/lib/cjs/geometry3d/Ray3d.js +1 -1
  110. package/lib/cjs/geometry3d/Ray3d.js.map +1 -1
  111. package/lib/cjs/geometry3d/Segment1d.d.ts +1 -1
  112. package/lib/cjs/geometry3d/Segment1d.js +1 -1
  113. package/lib/cjs/geometry3d/Segment1d.js.map +1 -1
  114. package/lib/cjs/numerics/Polynomials.d.ts +12 -0
  115. package/lib/cjs/numerics/Polynomials.d.ts.map +1 -1
  116. package/lib/cjs/numerics/Polynomials.js +14 -0
  117. package/lib/cjs/numerics/Polynomials.js.map +1 -1
  118. package/lib/cjs/polyface/AuxData.js +1 -1
  119. package/lib/cjs/polyface/AuxData.js.map +1 -1
  120. package/lib/cjs/polyface/FacetLocationDetail.d.ts +264 -0
  121. package/lib/cjs/polyface/FacetLocationDetail.d.ts.map +1 -0
  122. package/lib/cjs/polyface/FacetLocationDetail.js +376 -0
  123. package/lib/cjs/polyface/FacetLocationDetail.js.map +1 -0
  124. package/lib/cjs/polyface/IndexedPolyfaceVisitor.d.ts +2 -5
  125. package/lib/cjs/polyface/IndexedPolyfaceVisitor.d.ts.map +1 -1
  126. package/lib/cjs/polyface/IndexedPolyfaceVisitor.js +5 -2
  127. package/lib/cjs/polyface/IndexedPolyfaceVisitor.js.map +1 -1
  128. package/lib/cjs/polyface/PolyfaceBuilder.d.ts +24 -14
  129. package/lib/cjs/polyface/PolyfaceBuilder.d.ts.map +1 -1
  130. package/lib/cjs/polyface/PolyfaceBuilder.js +74 -23
  131. package/lib/cjs/polyface/PolyfaceBuilder.js.map +1 -1
  132. package/lib/cjs/polyface/PolyfaceClip.js +6 -7
  133. package/lib/cjs/polyface/PolyfaceClip.js.map +1 -1
  134. package/lib/cjs/polyface/PolyfaceData.d.ts +1 -1
  135. package/lib/cjs/polyface/PolyfaceData.d.ts.map +1 -1
  136. package/lib/cjs/polyface/PolyfaceData.js.map +1 -1
  137. package/lib/cjs/polyface/PolyfaceQuery.d.ts +76 -1
  138. package/lib/cjs/polyface/PolyfaceQuery.d.ts.map +1 -1
  139. package/lib/cjs/polyface/PolyfaceQuery.js +123 -3
  140. package/lib/cjs/polyface/PolyfaceQuery.js.map +1 -1
  141. package/lib/cjs/polyface/multiclip/OffsetMeshContext.d.ts +202 -0
  142. package/lib/cjs/polyface/multiclip/OffsetMeshContext.d.ts.map +1 -0
  143. package/lib/cjs/polyface/multiclip/OffsetMeshContext.js +1038 -0
  144. package/lib/cjs/polyface/multiclip/OffsetMeshContext.js.map +1 -0
  145. package/lib/cjs/serialization/BGFBReader.js +4 -4
  146. package/lib/cjs/serialization/BGFBReader.js.map +1 -1
  147. package/lib/cjs/serialization/GeometrySamples.d.ts +8 -6
  148. package/lib/cjs/serialization/GeometrySamples.d.ts.map +1 -1
  149. package/lib/cjs/serialization/GeometrySamples.js +26 -19
  150. package/lib/cjs/serialization/GeometrySamples.js.map +1 -1
  151. package/lib/cjs/serialization/IModelJsonSchema.js +1 -2
  152. package/lib/cjs/serialization/IModelJsonSchema.js.map +1 -1
  153. package/lib/cjs/solid/Sphere.d.ts +5 -5
  154. package/lib/cjs/solid/Sphere.js +5 -5
  155. package/lib/cjs/solid/Sphere.js.map +1 -1
  156. package/lib/cjs/solid/SweepContour.d.ts.map +1 -1
  157. package/lib/cjs/solid/SweepContour.js +8 -1
  158. package/lib/cjs/solid/SweepContour.js.map +1 -1
  159. package/lib/cjs/topology/Graph.d.ts +113 -7
  160. package/lib/cjs/topology/Graph.d.ts.map +1 -1
  161. package/lib/cjs/topology/Graph.js +185 -7
  162. package/lib/cjs/topology/Graph.js.map +1 -1
  163. package/lib/cjs/topology/HalfEdgeGraphFromIndexedLoopsContext.d.ts +38 -0
  164. package/lib/cjs/topology/HalfEdgeGraphFromIndexedLoopsContext.d.ts.map +1 -0
  165. package/lib/cjs/topology/HalfEdgeGraphFromIndexedLoopsContext.js +82 -0
  166. package/lib/cjs/topology/HalfEdgeGraphFromIndexedLoopsContext.js.map +1 -0
  167. package/lib/cjs/topology/HalfEdgeGraphSearch.d.ts +2 -1
  168. package/lib/cjs/topology/HalfEdgeGraphSearch.d.ts.map +1 -1
  169. package/lib/cjs/topology/HalfEdgeGraphSearch.js +1 -0
  170. package/lib/cjs/topology/HalfEdgeGraphSearch.js.map +1 -1
  171. package/lib/cjs/topology/Triangulation.js +1 -1
  172. package/lib/cjs/topology/Triangulation.js.map +1 -1
  173. package/lib/esm/Geometry.d.ts +56 -16
  174. package/lib/esm/Geometry.d.ts.map +1 -1
  175. package/lib/esm/Geometry.js +86 -29
  176. package/lib/esm/Geometry.js.map +1 -1
  177. package/lib/esm/bspline/BSplineCurveOps.js +4 -5
  178. package/lib/esm/bspline/BSplineCurveOps.js.map +1 -1
  179. package/lib/esm/bspline/InterpolationCurve3d.js +7 -10
  180. package/lib/esm/bspline/InterpolationCurve3d.js.map +1 -1
  181. package/lib/esm/clipping/ClipPrimitive.js +2 -2
  182. package/lib/esm/clipping/ClipPrimitive.js.map +1 -1
  183. package/lib/esm/clipping/ClipUtils.js +4 -4
  184. package/lib/esm/clipping/ClipUtils.js.map +1 -1
  185. package/lib/esm/clipping/internalContexts/LineStringOffsetClipperContext.js +2 -2
  186. package/lib/esm/clipping/internalContexts/LineStringOffsetClipperContext.js.map +1 -1
  187. package/lib/esm/curve/CurveChainWithDistanceIndex.d.ts.map +1 -1
  188. package/lib/esm/curve/CurveChainWithDistanceIndex.js +21 -14
  189. package/lib/esm/curve/CurveChainWithDistanceIndex.js.map +1 -1
  190. package/lib/esm/curve/CurveCollection.js +1 -1
  191. package/lib/esm/curve/CurveCollection.js.map +1 -1
  192. package/lib/esm/curve/CurveCurve.d.ts +11 -8
  193. package/lib/esm/curve/CurveCurve.d.ts.map +1 -1
  194. package/lib/esm/curve/CurveCurve.js +16 -12
  195. package/lib/esm/curve/CurveCurve.js.map +1 -1
  196. package/lib/esm/curve/CurveCurveIntersectXY.d.ts +5 -1
  197. package/lib/esm/curve/CurveCurveIntersectXY.d.ts.map +1 -1
  198. package/lib/esm/curve/CurveCurveIntersectXY.js +11 -10
  199. package/lib/esm/curve/CurveCurveIntersectXY.js.map +1 -1
  200. package/lib/esm/curve/Loop.d.ts +2 -2
  201. package/lib/esm/curve/Loop.d.ts.map +1 -1
  202. package/lib/esm/curve/Loop.js +6 -0
  203. package/lib/esm/curve/Loop.js.map +1 -1
  204. package/lib/esm/curve/RegionOps.d.ts +10 -10
  205. package/lib/esm/curve/RegionOps.d.ts.map +1 -1
  206. package/lib/esm/curve/RegionOps.js +11 -11
  207. package/lib/esm/curve/RegionOps.js.map +1 -1
  208. package/lib/esm/curve/RegionOpsClassificationSweeps.d.ts +2 -1
  209. package/lib/esm/curve/RegionOpsClassificationSweeps.d.ts.map +1 -1
  210. package/lib/esm/curve/RegionOpsClassificationSweeps.js +5 -2
  211. package/lib/esm/curve/RegionOpsClassificationSweeps.js.map +1 -1
  212. package/lib/esm/curve/StrokeOptions.js +1 -2
  213. package/lib/esm/curve/StrokeOptions.js.map +1 -1
  214. package/lib/esm/curve/spiral/DirectSpiral3d.js +1 -2
  215. package/lib/esm/curve/spiral/DirectSpiral3d.js.map +1 -1
  216. package/lib/esm/curve/spiral/IntegratedSpiral3d.js +1 -2
  217. package/lib/esm/curve/spiral/IntegratedSpiral3d.js.map +1 -1
  218. package/lib/esm/geometry3d/Angle.d.ts +19 -0
  219. package/lib/esm/geometry3d/Angle.d.ts.map +1 -1
  220. package/lib/esm/geometry3d/Angle.js +39 -0
  221. package/lib/esm/geometry3d/Angle.js.map +1 -1
  222. package/lib/esm/geometry3d/AngleSweep.d.ts +1 -0
  223. package/lib/esm/geometry3d/AngleSweep.d.ts.map +1 -1
  224. package/lib/esm/geometry3d/AngleSweep.js +1 -0
  225. package/lib/esm/geometry3d/AngleSweep.js.map +1 -1
  226. package/lib/esm/geometry3d/BarycentricTriangle.d.ts +195 -8
  227. package/lib/esm/geometry3d/BarycentricTriangle.d.ts.map +1 -1
  228. package/lib/esm/geometry3d/BarycentricTriangle.js +459 -12
  229. package/lib/esm/geometry3d/BarycentricTriangle.js.map +1 -1
  230. package/lib/esm/geometry3d/CoincidentGeometryOps.d.ts +1 -0
  231. package/lib/esm/geometry3d/CoincidentGeometryOps.d.ts.map +1 -1
  232. package/lib/esm/geometry3d/CoincidentGeometryOps.js +3 -0
  233. package/lib/esm/geometry3d/CoincidentGeometryOps.js.map +1 -1
  234. package/lib/esm/geometry3d/GrowableFloat64Array.js +2 -2
  235. package/lib/esm/geometry3d/GrowableFloat64Array.js.map +1 -1
  236. package/lib/esm/geometry3d/GrowableXYArray.d.ts +1 -1
  237. package/lib/esm/geometry3d/GrowableXYArray.d.ts.map +1 -1
  238. package/lib/esm/geometry3d/GrowableXYArray.js +2 -2
  239. package/lib/esm/geometry3d/GrowableXYArray.js.map +1 -1
  240. package/lib/esm/geometry3d/GrowableXYZArray.js +1 -1
  241. package/lib/esm/geometry3d/GrowableXYZArray.js.map +1 -1
  242. package/lib/esm/geometry3d/IndexedXYCollection.d.ts +22 -7
  243. package/lib/esm/geometry3d/IndexedXYCollection.d.ts.map +1 -1
  244. package/lib/esm/geometry3d/IndexedXYCollection.js +41 -5
  245. package/lib/esm/geometry3d/IndexedXYCollection.js.map +1 -1
  246. package/lib/esm/geometry3d/IndexedXYZCollection.d.ts +58 -4
  247. package/lib/esm/geometry3d/IndexedXYZCollection.d.ts.map +1 -1
  248. package/lib/esm/geometry3d/IndexedXYZCollection.js +103 -5
  249. package/lib/esm/geometry3d/IndexedXYZCollection.js.map +1 -1
  250. package/lib/esm/geometry3d/Matrix3d.d.ts +479 -265
  251. package/lib/esm/geometry3d/Matrix3d.d.ts.map +1 -1
  252. package/lib/esm/geometry3d/Matrix3d.js +996 -784
  253. package/lib/esm/geometry3d/Matrix3d.js.map +1 -1
  254. package/lib/esm/geometry3d/OrderedRotationAngles.d.ts +1 -0
  255. package/lib/esm/geometry3d/OrderedRotationAngles.d.ts.map +1 -1
  256. package/lib/esm/geometry3d/OrderedRotationAngles.js +1 -0
  257. package/lib/esm/geometry3d/OrderedRotationAngles.js.map +1 -1
  258. package/lib/esm/geometry3d/Point2dArrayCarrier.d.ts +10 -0
  259. package/lib/esm/geometry3d/Point2dArrayCarrier.d.ts.map +1 -1
  260. package/lib/esm/geometry3d/Point2dArrayCarrier.js +14 -0
  261. package/lib/esm/geometry3d/Point2dArrayCarrier.js.map +1 -1
  262. package/lib/esm/geometry3d/Point2dVector2d.js +4 -6
  263. package/lib/esm/geometry3d/Point2dVector2d.js.map +1 -1
  264. package/lib/esm/geometry3d/Point3dArrayCarrier.d.ts +0 -6
  265. package/lib/esm/geometry3d/Point3dArrayCarrier.d.ts.map +1 -1
  266. package/lib/esm/geometry3d/Point3dArrayCarrier.js +0 -6
  267. package/lib/esm/geometry3d/Point3dArrayCarrier.js.map +1 -1
  268. package/lib/esm/geometry3d/Point3dVector3d.d.ts +57 -57
  269. package/lib/esm/geometry3d/Point3dVector3d.d.ts.map +1 -1
  270. package/lib/esm/geometry3d/Point3dVector3d.js +63 -65
  271. package/lib/esm/geometry3d/Point3dVector3d.js.map +1 -1
  272. package/lib/esm/geometry3d/PointHelpers.d.ts +14 -1
  273. package/lib/esm/geometry3d/PointHelpers.d.ts.map +1 -1
  274. package/lib/esm/geometry3d/PointHelpers.js +33 -1
  275. package/lib/esm/geometry3d/PointHelpers.js.map +1 -1
  276. package/lib/esm/geometry3d/PolygonOps.d.ts +127 -19
  277. package/lib/esm/geometry3d/PolygonOps.d.ts.map +1 -1
  278. package/lib/esm/geometry3d/PolygonOps.js +419 -22
  279. package/lib/esm/geometry3d/PolygonOps.js.map +1 -1
  280. package/lib/esm/geometry3d/Ray3d.js +1 -1
  281. package/lib/esm/geometry3d/Ray3d.js.map +1 -1
  282. package/lib/esm/geometry3d/Segment1d.d.ts +1 -1
  283. package/lib/esm/geometry3d/Segment1d.js +1 -1
  284. package/lib/esm/geometry3d/Segment1d.js.map +1 -1
  285. package/lib/esm/numerics/Polynomials.d.ts +12 -0
  286. package/lib/esm/numerics/Polynomials.d.ts.map +1 -1
  287. package/lib/esm/numerics/Polynomials.js +14 -0
  288. package/lib/esm/numerics/Polynomials.js.map +1 -1
  289. package/lib/esm/polyface/AuxData.js +1 -1
  290. package/lib/esm/polyface/AuxData.js.map +1 -1
  291. package/lib/esm/polyface/FacetLocationDetail.d.ts +264 -0
  292. package/lib/esm/polyface/FacetLocationDetail.d.ts.map +1 -0
  293. package/lib/esm/polyface/FacetLocationDetail.js +369 -0
  294. package/lib/esm/polyface/FacetLocationDetail.js.map +1 -0
  295. package/lib/esm/polyface/IndexedPolyfaceVisitor.d.ts +2 -5
  296. package/lib/esm/polyface/IndexedPolyfaceVisitor.d.ts.map +1 -1
  297. package/lib/esm/polyface/IndexedPolyfaceVisitor.js +5 -2
  298. package/lib/esm/polyface/IndexedPolyfaceVisitor.js.map +1 -1
  299. package/lib/esm/polyface/PolyfaceBuilder.d.ts +24 -14
  300. package/lib/esm/polyface/PolyfaceBuilder.d.ts.map +1 -1
  301. package/lib/esm/polyface/PolyfaceBuilder.js +74 -23
  302. package/lib/esm/polyface/PolyfaceBuilder.js.map +1 -1
  303. package/lib/esm/polyface/PolyfaceClip.js +6 -7
  304. package/lib/esm/polyface/PolyfaceClip.js.map +1 -1
  305. package/lib/esm/polyface/PolyfaceData.d.ts +1 -1
  306. package/lib/esm/polyface/PolyfaceData.d.ts.map +1 -1
  307. package/lib/esm/polyface/PolyfaceData.js.map +1 -1
  308. package/lib/esm/polyface/PolyfaceQuery.d.ts +76 -1
  309. package/lib/esm/polyface/PolyfaceQuery.d.ts.map +1 -1
  310. package/lib/esm/polyface/PolyfaceQuery.js +121 -2
  311. package/lib/esm/polyface/PolyfaceQuery.js.map +1 -1
  312. package/lib/esm/polyface/multiclip/OffsetMeshContext.d.ts +202 -0
  313. package/lib/esm/polyface/multiclip/OffsetMeshContext.d.ts.map +1 -0
  314. package/lib/esm/polyface/multiclip/OffsetMeshContext.js +1032 -0
  315. package/lib/esm/polyface/multiclip/OffsetMeshContext.js.map +1 -0
  316. package/lib/esm/serialization/BGFBReader.js +4 -4
  317. package/lib/esm/serialization/BGFBReader.js.map +1 -1
  318. package/lib/esm/serialization/GeometrySamples.d.ts +8 -6
  319. package/lib/esm/serialization/GeometrySamples.d.ts.map +1 -1
  320. package/lib/esm/serialization/GeometrySamples.js +26 -19
  321. package/lib/esm/serialization/GeometrySamples.js.map +1 -1
  322. package/lib/esm/serialization/IModelJsonSchema.js +1 -2
  323. package/lib/esm/serialization/IModelJsonSchema.js.map +1 -1
  324. package/lib/esm/solid/Sphere.d.ts +5 -5
  325. package/lib/esm/solid/Sphere.js +5 -5
  326. package/lib/esm/solid/Sphere.js.map +1 -1
  327. package/lib/esm/solid/SweepContour.d.ts.map +1 -1
  328. package/lib/esm/solid/SweepContour.js +8 -1
  329. package/lib/esm/solid/SweepContour.js.map +1 -1
  330. package/lib/esm/topology/Graph.d.ts +113 -7
  331. package/lib/esm/topology/Graph.d.ts.map +1 -1
  332. package/lib/esm/topology/Graph.js +185 -7
  333. package/lib/esm/topology/Graph.js.map +1 -1
  334. package/lib/esm/topology/HalfEdgeGraphFromIndexedLoopsContext.d.ts +38 -0
  335. package/lib/esm/topology/HalfEdgeGraphFromIndexedLoopsContext.d.ts.map +1 -0
  336. package/lib/esm/topology/HalfEdgeGraphFromIndexedLoopsContext.js +78 -0
  337. package/lib/esm/topology/HalfEdgeGraphFromIndexedLoopsContext.js.map +1 -0
  338. package/lib/esm/topology/HalfEdgeGraphSearch.d.ts +2 -1
  339. package/lib/esm/topology/HalfEdgeGraphSearch.d.ts.map +1 -1
  340. package/lib/esm/topology/HalfEdgeGraphSearch.js +1 -0
  341. package/lib/esm/topology/HalfEdgeGraphSearch.js.map +1 -1
  342. package/lib/esm/topology/Triangulation.js +1 -1
  343. package/lib/esm/topology/Triangulation.js.map +1 -1
  344. package/package.json +5 -5
@@ -5,18 +5,75 @@
5
5
  /** @packageDocumentation
6
6
  * @module CartesianGeometry
7
7
  */
8
- import { Geometry } from "../Geometry";
8
+ import { assert } from "@itwin/core-bentley";
9
+ import { AxisOrder, Geometry, PolygonLocation } from "../Geometry";
9
10
  import { Matrix4d } from "../geometry4d/Matrix4d";
10
11
  import { Point4d } from "../geometry4d/Point4d";
11
12
  import { XYParitySearchContext } from "../topology/XYParitySearchContext";
12
13
  import { FrameBuilder } from "./FrameBuilder";
13
14
  import { GrowableXYZArray } from "./GrowableXYZArray";
14
15
  import { IndexedXYZCollection } from "./IndexedXYZCollection";
16
+ import { Matrix3d } from "./Matrix3d";
17
+ import { Plane3dByOriginAndUnitNormal } from "./Plane3dByOriginAndUnitNormal";
15
18
  import { Point2d, Vector2d } from "./Point2dVector2d";
16
19
  import { Point3dArrayCarrier } from "./Point3dArrayCarrier";
17
20
  import { Point3d, Vector3d } from "./Point3dVector3d";
18
21
  import { Ray3d } from "./Ray3d";
19
22
  import { SortablePolygon } from "./SortablePolygon";
23
+ /**
24
+ * Carries data about a point in the plane of a polygon.
25
+ * @public
26
+ */
27
+ export class PolygonLocationDetail {
28
+ constructor() {
29
+ this.point = new Point3d();
30
+ this.a = 0.0;
31
+ this.v = new Vector3d();
32
+ this.code = PolygonLocation.Unknown;
33
+ this.closestEdgeIndex = 0;
34
+ this.closestEdgeParam = 0.0;
35
+ }
36
+ /** Invalidate this detail. */
37
+ invalidate() {
38
+ this.point.setZero();
39
+ this.a = 0.0;
40
+ this.v.setZero();
41
+ this.code = PolygonLocation.Unknown;
42
+ this.closestEdgeIndex = 0;
43
+ this.closestEdgeParam = 0.0;
44
+ }
45
+ /** Create an invalid detail.
46
+ * @param result optional pre-allocated object to fill and return
47
+ */
48
+ static create(result) {
49
+ if (undefined === result)
50
+ result = new PolygonLocationDetail();
51
+ else
52
+ result.invalidate();
53
+ return result;
54
+ }
55
+ /** Set the instance contents from the other detail.
56
+ * @param other detail to clone
57
+ */
58
+ copyContentsFrom(other) {
59
+ this.point.setFrom(other.point);
60
+ this.a = other.a;
61
+ this.v.setFrom(other.v);
62
+ this.code = other.code;
63
+ this.closestEdgeIndex = other.closestEdgeIndex;
64
+ this.closestEdgeParam = other.closestEdgeParam;
65
+ }
66
+ /** Whether this detail is valid. */
67
+ get isValid() {
68
+ return this.code !== PolygonLocation.Unknown;
69
+ }
70
+ /** Whether this instance specifies a location inside or on the polygon. */
71
+ get isInsideOrOn() {
72
+ return this.code === PolygonLocation.InsidePolygon ||
73
+ this.code === PolygonLocation.OnPolygonVertex || this.code === PolygonLocation.OnPolygonEdgeInterior ||
74
+ this.code === PolygonLocation.InsidePolygonProjectsToVertex || this.code === PolygonLocation.InsidePolygonProjectsToEdgeInterior;
75
+ }
76
+ }
20
77
  /**
21
78
  * Carrier for a loop extracted from clip operation, annotated for sorting
22
79
  * @internal
@@ -533,29 +590,27 @@ export class PolygonOps {
533
590
  }
534
591
  }
535
592
  /** Test the direction of turn at the vertices of the polygon, ignoring z-coordinates.
536
- *
537
- * * For a polygon without self intersections, this is a convexity and orientation test: all positive is convex and counterclockwise,
538
- * all negative is convex and clockwise
539
- * * Beware that a polygon which turns through more than a full turn can cross itself and close, but is not convex
540
- * * Returns 1 if all turns are to the left, -1 if all to the right, and 0 if there are any zero or reverse turns
593
+ * * For a polygon without self-intersections and successive colinear edges, this is a convexity and orientation test: all positive is convex and counterclockwise, all negative is convex and clockwise.
594
+ * * Beware that a polygon which turns through more than a full turn can cross itself and close, but is not convex.
595
+ * @returns 1 if all turns are to the left, -1 if all to the right, and 0 if there are any zero or reverse turns
541
596
  */
542
- static testXYPolygonTurningDirections(pPointArray) {
597
+ static testXYPolygonTurningDirections(points) {
543
598
  // Reduce count by trailing duplicates; leaves iLast at final index
544
- let numPoint = pPointArray.length;
599
+ let numPoint = points.length;
545
600
  let iLast = numPoint - 1;
546
- while (iLast > 1 && pPointArray[iLast].x === pPointArray[0].x && pPointArray[iLast].y === pPointArray[0].y) {
601
+ while (iLast > 1 && points[iLast].x === points[0].x && points[iLast].y === points[0].y) {
547
602
  numPoint = iLast--;
548
603
  }
549
604
  if (numPoint > 2) {
550
- let vector0 = Point2d.create(pPointArray[iLast].x - pPointArray[iLast - 1].x, pPointArray[iLast].y - pPointArray[iLast - 1].y);
551
- const vector1 = Point2d.create(pPointArray[0].x - pPointArray[iLast].x, pPointArray[0].y - pPointArray[iLast].y);
605
+ let vector0 = Point2d.create(points[iLast].x - points[iLast - 1].x, points[iLast].y - points[iLast - 1].y);
606
+ const vector1 = Point2d.create(points[0].x - points[iLast].x, points[0].y - points[iLast].y);
552
607
  const baseArea = vector0.x * vector1.y - vector0.y * vector1.x;
553
608
  // In a convex polygon, all successive-vector cross products will
554
609
  // have the same sign as the base area, hence all products will be
555
610
  // positive.
556
611
  for (let i1 = 1; i1 < numPoint; i1++) {
557
612
  vector0 = vector1.clone();
558
- Point2d.create(pPointArray[i1].x - pPointArray[i1 - 1].x, pPointArray[i1].y - pPointArray[i1 - 1].y, vector1);
613
+ Point2d.create(points[i1].x - points[i1 - 1].x, points[i1].y - points[i1 - 1].y, vector1);
559
614
  const currArea = vector0.x * vector1.y - vector0.y * vector1.x;
560
615
  if (currArea * baseArea <= 0.0)
561
616
  return 0;
@@ -565,6 +620,36 @@ export class PolygonOps {
565
620
  }
566
621
  return 0;
567
622
  }
623
+ /**
624
+ * Determine whether the polygon is convex.
625
+ * @param polygon vertices, closure point optional
626
+ * @returns whether the polygon is convex.
627
+ */
628
+ static isConvex(polygon) {
629
+ if (!(polygon instanceof IndexedXYZCollection))
630
+ return this.isConvex(new Point3dArrayCarrier(polygon));
631
+ let n = polygon.length;
632
+ if (n > 1 && polygon.getPoint3dAtUncheckedPointIndex(0).isExactEqual(polygon.getPoint3dAtUncheckedPointIndex(n - 1)))
633
+ --n; // ignore closure point
634
+ const normal = Vector3d.create();
635
+ if (!this.unitNormal(polygon, normal))
636
+ return false;
637
+ let positiveArea = 0.0;
638
+ let negativeArea = 0.0;
639
+ const vecA = this._vector0;
640
+ let vecB = Vector3d.createStartEnd(polygon.getPoint3dAtUncheckedPointIndex(n - 1), polygon.getPoint3dAtUncheckedPointIndex(0), this._vector1);
641
+ for (let i = 1; i <= n; i++) {
642
+ // check turn through vertices i-1,i,i+1
643
+ vecA.setFromVector3d(vecB);
644
+ vecB = Vector3d.createStartEnd(polygon.getPoint3dAtUncheckedPointIndex(i - 1), polygon.getPoint3dAtUncheckedPointIndex(i % n), vecB);
645
+ const signedArea = normal.tripleProduct(vecA, vecB);
646
+ if (signedArea >= 0.0)
647
+ positiveArea += signedArea;
648
+ else
649
+ negativeArea += signedArea;
650
+ }
651
+ return Math.abs(negativeArea) < Geometry.smallMetricDistanceSquared * positiveArea;
652
+ }
568
653
  /**
569
654
  * Test if point (x,y) is IN, OUT or ON a polygon.
570
655
  * @return (1) for in, (-1) for OUT, (0) for ON
@@ -661,15 +746,12 @@ export class PolygonOps {
661
746
  return numReverse;
662
747
  }
663
748
  /**
664
- * Reverse loops as necessary to make them all have CCW orientation for given outward normal.
665
- * * Return an array of arrays which capture the input pointers.
666
- * * In each first level array:
667
- * * The first loop is an outer loop.
668
- * * all subsequent loops are holes
669
- * * The outer loop is CCW
670
- * * The holes are CW.
671
- * * Call RegionOps.sortOuterAndHoleLoopsXY to have the result returned as a UnionRegion
672
- * @param loops multiple loops to sort and reverse.
749
+ * Reverse and reorder loops in the xy-plane for consistency and containment.
750
+ * @param loops multiple polygons in any order and orientation, z-coordinates ignored
751
+ * @returns array of arrays of polygons that capture the input pointers. In each first level array:
752
+ * * The first polygon is an outer loop, oriented counterclockwise.
753
+ * * Any subsequent polygons are holes of the outer loop, oriented clockwise.
754
+ * @see RegionOps.sortOuterAndHoleLoopsXY
673
755
  */
674
756
  static sortOuterAndHoleLoopsXY(loops) {
675
757
  const loopAndArea = [];
@@ -682,10 +764,11 @@ export class PolygonOps {
682
764
  * Exactly like `sortOuterAndHoleLoopsXY` but allows loops in any plane.
683
765
  * @param loops multiple loops to sort and reverse.
684
766
  * @param defaultNormal optional normal for the loops, if known
767
+ * @see sortOuterAndHoleLoopsXY
685
768
  */
686
769
  static sortOuterAndHoleLoops(loops, defaultNormal) {
687
770
  const localToWorld = FrameBuilder.createRightHandedFrame(defaultNormal, loops);
688
- const worldToLocal = localToWorld === null || localToWorld === void 0 ? void 0 : localToWorld.inverse();
771
+ const worldToLocal = localToWorld?.inverse();
689
772
  const xyLoops = [];
690
773
  if (worldToLocal !== undefined) {
691
774
  // transform into plane so we can ignore z in the sort
@@ -712,6 +795,320 @@ export class PolygonOps {
712
795
  }
713
796
  return sortedLoopsArray;
714
797
  }
798
+ /** Compute the closest point on the polygon boundary to the given point.
799
+ * @param polygon points of the polygon, closure point optional
800
+ * @param testPoint point p to project onto the polygon edges. Works best when p is in the plane of the polygon.
801
+ * @param tolerance optional distance tolerance to determine point-vertex and point-edge coincidence.
802
+ * @param result optional pre-allocated object to fill and return
803
+ * @returns details d of the closest point `d.point`:
804
+ * * `d.isValid()` returns true if and only if the polygon is nontrivial.
805
+ * * `d.edgeIndex` and `d.edgeParam` specify the location of the closest point, within `distTol`.
806
+ * * `d.code` classifies the closest point as a vertex (`PolygonLocation.OnPolygonVertex`) or as a point on an edge (`PolygonLocation.OnPolygonEdgeInterior`).
807
+ * * `d.a` is the distance from testPoint to the closest point.
808
+ * * `d.v` can be used to classify p (if p and polygon are coplanar): if n is the polygon normal then `d.v.dotProduct(n)` is +/-/0 if and only if p is inside/outside/on the polygon.
809
+ */
810
+ static closestPointOnBoundary(polygon, testPoint, tolerance = Geometry.smallMetricDistance, result) {
811
+ if (!(polygon instanceof IndexedXYZCollection))
812
+ return this.closestPointOnBoundary(new Point3dArrayCarrier(polygon), testPoint, tolerance, result);
813
+ const distTol2 = tolerance * tolerance;
814
+ let numPoints = polygon.length;
815
+ while (numPoints > 1) {
816
+ if (polygon.distanceSquaredIndexIndex(0, numPoints - 1) > distTol2)
817
+ break;
818
+ --numPoints; // ignore closure point
819
+ }
820
+ result = PolygonLocationDetail.create(result);
821
+ if (0 === numPoints)
822
+ return result; // invalid
823
+ if (1 === numPoints) {
824
+ polygon.getPoint3dAtUncheckedPointIndex(0, result.point);
825
+ result.a = result.point.distance(testPoint);
826
+ result.v.setZero();
827
+ result.code = PolygonLocation.OnPolygonVertex;
828
+ result.closestEdgeIndex = 0;
829
+ result.closestEdgeParam = 0.0;
830
+ return result;
831
+ }
832
+ let iPrev = numPoints - 1;
833
+ let minDist2 = Geometry.largeCoordinateResult;
834
+ for (let iBase = 0; iBase < numPoints; ++iBase) {
835
+ let iNext = iBase + 1;
836
+ if (iNext === numPoints)
837
+ iNext = 0;
838
+ const uDotU = polygon.distanceSquaredIndexIndex(iBase, iNext);
839
+ if (uDotU <= distTol2)
840
+ continue; // ignore trivial polygon edge (keep iPrev)
841
+ const vDotV = polygon.distanceSquaredIndexXYAndZ(iBase, testPoint);
842
+ const uDotV = polygon.dotProductIndexIndexXYAndZ(iBase, iNext, testPoint);
843
+ const edgeParam = uDotV / uDotU; // param of projection of testPoint onto this edge
844
+ if (edgeParam <= 0.0) { // testPoint projects to/before edge start
845
+ const distToStart2 = vDotV;
846
+ if (distToStart2 <= distTol2) {
847
+ // testPoint is at edge start; we are done
848
+ polygon.getPoint3dAtUncheckedPointIndex(iBase, result.point);
849
+ result.a = Math.sqrt(distToStart2);
850
+ result.v.setZero();
851
+ result.code = PolygonLocation.OnPolygonVertex;
852
+ result.closestEdgeIndex = iBase;
853
+ result.closestEdgeParam = 0.0;
854
+ return result;
855
+ }
856
+ if (distToStart2 < minDist2) {
857
+ if (polygon.dotProductIndexIndexXYAndZ(iBase, iPrev, testPoint) <= 0.0) {
858
+ // update candidate (to edge start) only if previous edge was NOOP
859
+ polygon.getPoint3dAtUncheckedPointIndex(iBase, result.point);
860
+ result.a = Math.sqrt(distToStart2);
861
+ polygon.crossProductIndexIndexIndex(iBase, iPrev, iNext, result.v);
862
+ result.code = PolygonLocation.OnPolygonVertex;
863
+ result.closestEdgeIndex = iBase;
864
+ result.closestEdgeParam = 0.0;
865
+ minDist2 = distToStart2;
866
+ }
867
+ }
868
+ }
869
+ else if (edgeParam <= 1.0) { // testPoint projects inside edge, or to edge end
870
+ const projDist2 = vDotV - edgeParam * edgeParam * uDotU;
871
+ if (projDist2 <= distTol2) {
872
+ // testPoint is on edge; we are done
873
+ const distToStart2 = vDotV;
874
+ if (edgeParam <= 0.5 && distToStart2 <= distTol2) {
875
+ // testPoint is at edge start
876
+ polygon.getPoint3dAtUncheckedPointIndex(iBase, result.point);
877
+ result.a = Math.sqrt(distToStart2);
878
+ result.v.setZero();
879
+ result.code = PolygonLocation.OnPolygonVertex;
880
+ result.closestEdgeIndex = iBase;
881
+ result.closestEdgeParam = 0.0;
882
+ return result;
883
+ }
884
+ const distToEnd2 = projDist2 + (1.0 - edgeParam) * (1.0 - edgeParam) * uDotU;
885
+ if (edgeParam > 0.5 && distToEnd2 <= distTol2) {
886
+ // testPoint is at edge end
887
+ polygon.getPoint3dAtUncheckedPointIndex(iNext, result.point);
888
+ result.a = Math.sqrt(distToEnd2);
889
+ result.v.setZero();
890
+ result.code = PolygonLocation.OnPolygonVertex;
891
+ result.closestEdgeIndex = iNext;
892
+ result.closestEdgeParam = 0.0;
893
+ return result;
894
+ }
895
+ // testPoint is on edge interior
896
+ polygon.interpolateIndexIndex(iBase, edgeParam, iNext, result.point);
897
+ result.a = Math.sqrt(projDist2);
898
+ result.v.setZero();
899
+ result.code = PolygonLocation.OnPolygonEdgeInterior;
900
+ result.closestEdgeIndex = iBase;
901
+ result.closestEdgeParam = edgeParam;
902
+ return result;
903
+ }
904
+ if (projDist2 < minDist2) {
905
+ // update candidate (to edge interior)
906
+ polygon.interpolateIndexIndex(iBase, edgeParam, iNext, result.point);
907
+ result.a = Math.sqrt(projDist2);
908
+ polygon.crossProductIndexIndexXYAndZ(iBase, iNext, testPoint, result.v);
909
+ result.code = PolygonLocation.OnPolygonEdgeInterior;
910
+ result.closestEdgeIndex = iBase;
911
+ result.closestEdgeParam = edgeParam;
912
+ minDist2 = projDist2;
913
+ }
914
+ }
915
+ else { // edgeParam > 1.0
916
+ // NOOP: testPoint projects beyond edge end, handled by next edge
917
+ }
918
+ iPrev = iBase;
919
+ }
920
+ return result;
921
+ }
922
+ /** Compute the intersection of a line (parameterized as a ray) with the plane of this polygon.
923
+ * @param polygon points of the polygon, closure point optional
924
+ * @param ray infinite line to intersect, as a ray
925
+ * @param tolerance optional distance tolerance to determine point-vertex and point-edge coincidence.
926
+ * @param result optional pre-allocated object to fill and return
927
+ * @returns details d of the line-plane intersection `d.point`:
928
+ * * `d.isValid()` returns true if and only if the line intersects the plane.
929
+ * * `d.code` indicates where the intersection lies with respect to the polygon.
930
+ * * `d.a` is the ray intersection parameter. If `d.a` >= 0, the ray intersects the plane of the polygon.
931
+ * * `d.edgeIndex` and `d.edgeParam` specify the location of the closest point on the polygon to the intersection, within `distTol`.
932
+ */
933
+ static intersectRay3d(polygon, ray, tolerance = Geometry.smallMetricDistance, result) {
934
+ if (!(polygon instanceof IndexedXYZCollection))
935
+ return this.intersectRay3d(new Point3dArrayCarrier(polygon), ray, tolerance, result);
936
+ if (!this.unitNormal(polygon, this._normal))
937
+ return PolygonLocationDetail.create(result); // invalid
938
+ this._workPlane = Plane3dByOriginAndUnitNormal.createXYZUVW(polygon.getXAtUncheckedPointIndex(0), polygon.getYAtUncheckedPointIndex(0), polygon.getZAtUncheckedPointIndex(0), this._normal.x, this._normal.y, this._normal.z, this._workPlane);
939
+ const intersectionPoint = Point3d.createZero(this._workXYZ);
940
+ const rayParam = ray.intersectionWithPlane(this._workPlane, intersectionPoint);
941
+ if (undefined === rayParam)
942
+ return PolygonLocationDetail.create(result);
943
+ result = this.closestPointOnBoundary(polygon, intersectionPoint, tolerance, result);
944
+ if (result.isValid) {
945
+ result.point.setFrom(intersectionPoint);
946
+ result.a = rayParam;
947
+ const dot = result.v.dotProduct(this._normal);
948
+ if (dot === 0.0) {
949
+ // NOOP: intersectionPoint is on the polygon, so result.code already classifies it
950
+ }
951
+ else {
952
+ // intersectionPoint is not on polygon, so result.code refers to the closest point. Update it to refer to intersectionPoint.
953
+ if (PolygonLocation.OnPolygonVertex === result.code)
954
+ result.code = (dot > 0.0) ? PolygonLocation.InsidePolygonProjectsToVertex : PolygonLocation.OutsidePolygonProjectsToVertex;
955
+ else if (PolygonLocation.OnPolygonEdgeInterior === result.code)
956
+ result.code = (dot > 0.0) ? PolygonLocation.InsidePolygonProjectsToEdgeInterior : PolygonLocation.OutsidePolygonProjectsToEdgeInterior;
957
+ }
958
+ }
959
+ return result;
960
+ }
961
+ /** Compute the intersection of a line (parameterized as a line segment) with the plane of this polygon.
962
+ * @param polygon points of the polygon, closure point optional
963
+ * @param point0 start point of segment on line to intersect
964
+ * @param point1 end point of segment on line to intersect
965
+ * @param tolerance optional distance tolerance to determine point-vertex and point-edge coincidence.
966
+ * @param result optional pre-allocated object to fill and return
967
+ * @returns details d of the line-plane intersection `d.point`:
968
+ * * `d.isValid()` returns true if and only if the line intersects the plane.
969
+ * * `d.code` indicates where the intersection lies with respect to the polygon.
970
+ * * `d.a` is the segment intersection parameter. If `d.a` is in [0,1], the segment intersects the plane of the polygon.
971
+ * * `d.edgeIndex` and `d.edgeParam` specify the location of the closest point on the polygon to the intersection, within `distTol`.
972
+ * @see intersectRay3d
973
+ */
974
+ static intersectSegment(polygon, point0, point1, tolerance = Geometry.smallMetricDistance, result) {
975
+ this._workRay = Ray3d.createStartEnd(point0, point1, this._workRay);
976
+ return this.intersectRay3d(polygon, this._workRay, tolerance, result);
977
+ }
978
+ /** Compute edge data for the barycentric coordinate computation, ignoring all z-coordinates.
979
+ * @param polygon points of the polygon (without closure point)
980
+ * @param edgeStartVertexIndex index of start vertex of the edge (unchecked)
981
+ * @param point point to project to the edge
982
+ * @param edgeOutwardUnitNormal pre-allocated vector to be populated on return with the unit perpendicular to the edge, facing outward, in xy-plane
983
+ * @param tolerance used to clamp outputs
984
+ * @param result optional pre-allocated result
985
+ * @returns x: signed projection distance of `point` to the edge, y: edge parameter of the projection
986
+ */
987
+ static computeEdgeDataXY(polygon, edgeStartVertexIndex, point, edgeOutwardUnitNormal, tolerance = Geometry.smallMetricDistance, result) {
988
+ const i0 = edgeStartVertexIndex % polygon.length;
989
+ const i1 = (i0 + 1) % polygon.length;
990
+ polygon.vectorIndexIndex(i0, i1, edgeOutwardUnitNormal).unitPerpendicularXY(edgeOutwardUnitNormal).negate(edgeOutwardUnitNormal); // z is zero
991
+ const hypDeltaX = polygon.getXAtUncheckedPointIndex(i0) - point.x;
992
+ const hypDeltaY = polygon.getYAtUncheckedPointIndex(i0) - point.y;
993
+ let projDist = Geometry.dotProductXYXY(hypDeltaX, hypDeltaY, edgeOutwardUnitNormal.x, edgeOutwardUnitNormal.y);
994
+ const edgeDist = Geometry.crossProductXYXY(hypDeltaX, hypDeltaY, edgeOutwardUnitNormal.x, edgeOutwardUnitNormal.y);
995
+ const edgeLength = Geometry.distanceXYXY(polygon.getXAtUncheckedPointIndex(i0), polygon.getYAtUncheckedPointIndex(i0), polygon.getXAtUncheckedPointIndex(i1), polygon.getYAtUncheckedPointIndex(i1));
996
+ let edgeParam = Geometry.safeDivideFraction(edgeDist, edgeLength, 0.0);
997
+ if (Geometry.isSameCoordinate(0.0, projDist, tolerance))
998
+ projDist = 0.0;
999
+ if (Geometry.isSameCoordinate(0.0, edgeParam, tolerance))
1000
+ edgeParam = 0.0;
1001
+ else if (Geometry.isSameCoordinate(1.0, edgeParam, tolerance))
1002
+ edgeParam = 1.0;
1003
+ return Point2d.create(projDist, edgeParam, result);
1004
+ }
1005
+ /** Compute the barycentric coordinates for a point on either of a pair of adjacent edges of a convex polygon.
1006
+ * @param polygon points of the polygon, assumed to be convex. Assumed to have no closure point.
1007
+ * @param iPrev start index of previous edge
1008
+ * @param prevNormal outward unit normal of previous edge
1009
+ * @param prevProj x = signed distance from point to previous edge; y = edge parameter of this projection in [0,1]
1010
+ * @param i start index of current edge
1011
+ * @param normal outward unit normal of current edge
1012
+ * @param proj x = signed distance from point to current edge; y = edge parameter of this projection in [0,1]
1013
+ * @param coords pre-allocated barycentric coordinate array to return, assumed to have length at least `polygon.length`
1014
+ * @returns barycentric coordinates, or undefined if not on either edge
1015
+ */
1016
+ static convexBarycentricCoordinatesOnEdge(polygon, iPrev, prevNormal, prevProj, i, normal, proj, coords) {
1017
+ // ignore degenerate edges
1018
+ const pointIsOnPrevEdge = !prevNormal.isZero && (0.0 === prevProj.x) && Geometry.isIn01(prevProj.y);
1019
+ const pointIsOnEdge = !normal.isZero && (0.0 === proj.x) && Geometry.isIn01(proj.y);
1020
+ if (pointIsOnPrevEdge && pointIsOnEdge) { // the point is at vertex i
1021
+ coords.fill(0);
1022
+ coords[i] = 1.0;
1023
+ return coords;
1024
+ }
1025
+ const n = polygon.length;
1026
+ if (pointIsOnPrevEdge) { // the point is on the previous edge
1027
+ coords.fill(0);
1028
+ const i0 = iPrev;
1029
+ const i1 = i;
1030
+ const edgeParam = prevProj.y;
1031
+ coords[i0] = 1.0 - edgeParam;
1032
+ coords[i1] = edgeParam;
1033
+ return coords;
1034
+ }
1035
+ if (pointIsOnEdge) { // the point is on the edge starting at the i_th vertex
1036
+ coords.fill(0);
1037
+ const i0 = i;
1038
+ const i1 = (i + 1) % n;
1039
+ const edgeParam = proj.y;
1040
+ coords[i0] = 1.0 - edgeParam;
1041
+ coords[i1] = edgeParam;
1042
+ return coords;
1043
+ }
1044
+ return undefined; // not on edge
1045
+ }
1046
+ // cspell:word CAGD
1047
+ /** Compute the barycentric coordinates for a point inside a convex polygon.
1048
+ * @param polygon points of the polygon, assumed to be convex. Closure point optional.
1049
+ * @param point point assumed to be inside or on polygon
1050
+ * @param tolerance distance tolerance for point to be considered on a polygon edge
1051
+ * @return barycentric coordinates of the interior point, or undefined if invalid polygon or exterior point. Length is same as `polygon.length`.
1052
+ * @see BarycentricTriangle.pointToFraction
1053
+ */
1054
+ static convexBarycentricCoordinates(polygon, point, tolerance = Geometry.smallMetricDistance) {
1055
+ // cf. "Barycentric Coordinates for Convex Sets", by Warren et al., CAGD (2003)
1056
+ if (Array.isArray(polygon))
1057
+ return this.convexBarycentricCoordinates(new Point3dArrayCarrier(polygon), point);
1058
+ let n = polygon.length;
1059
+ while (n > 1 && polygon.getPoint3dAtUncheckedPointIndex(0).isExactEqual(polygon.getPoint3dAtUncheckedPointIndex(n - 1)))
1060
+ --n; // ignore closure point(s)
1061
+ if (n < 3 || !PolygonOps.unitNormal(polygon, this._normal))
1062
+ return undefined;
1063
+ const localToWorld = this._workMatrix3d = Matrix3d.createRigidHeadsUp(this._normal, AxisOrder.ZXY, this._workMatrix3d);
1064
+ const polygonXY = new GrowableXYZArray(n);
1065
+ for (let i = 0; i < n; ++i)
1066
+ polygonXY.push(localToWorld.multiplyInverseXYZAsPoint3d(polygon.getXAtUncheckedPointIndex(i), polygon.getYAtUncheckedPointIndex(i), polygon.getZAtUncheckedPointIndex(i), this._workXYZ));
1067
+ const pointXY = this._workXYZ = localToWorld.multiplyInverseXYZAsPoint3d(point.x, point.y, point.z, this._workXYZ);
1068
+ // now we know polygon orientation is ccw, its last edge has positive length, and we can ignore z-coords
1069
+ let iPrev = n - 1;
1070
+ const outwardUnitNormalOfLastEdge = this._vector0;
1071
+ const projToLastEdge = this._workXY0 = this.computeEdgeDataXY(polygonXY, iPrev, pointXY, outwardUnitNormalOfLastEdge, tolerance, this._workXY0);
1072
+ // we can compare to exact zero because computeEdgeDataXY has chopped small distances to zero
1073
+ if (projToLastEdge.x < 0.0)
1074
+ return undefined; // point is outside polygon, or polygon is nonconvex
1075
+ const outwardUnitNormalOfPrevEdge = Vector3d.createFrom(outwardUnitNormalOfLastEdge, this._vector1);
1076
+ const projToPrevEdge = this._workXY1 = Point2d.createFrom(projToLastEdge, this._workXY1);
1077
+ const coords = Array(polygon.length).fill(0); // use original length
1078
+ const largestResult = (tolerance > 0.0) ? 1.0 / (tolerance * tolerance) : Geometry.largeCoordinateResult;
1079
+ let coordSum = 0.0;
1080
+ for (let i = 0; i < n; ++i) {
1081
+ const outwardUnitNormalOfEdge = Vector3d.createFrom(outwardUnitNormalOfLastEdge, this._vector2);
1082
+ const projToEdge = this._workXY2 = (i < n - 1) ? this.computeEdgeDataXY(polygonXY, i, pointXY, outwardUnitNormalOfEdge, tolerance, this._workXY2) : Point2d.createFrom(projToLastEdge, this._workXY2);
1083
+ if (projToEdge.x < 0.0)
1084
+ return undefined; // point is outside polygon, or polygon is nonconvex
1085
+ if (undefined !== this.convexBarycentricCoordinatesOnEdge(polygonXY, iPrev, outwardUnitNormalOfPrevEdge, projToPrevEdge, i, outwardUnitNormalOfEdge, projToEdge, coords))
1086
+ return coords; // point is on vertex or edge; we are done
1087
+ if (outwardUnitNormalOfEdge.x === 0.0 && outwardUnitNormalOfEdge.y === 0.0)
1088
+ continue; // edge is degenerate; coords[i] = 0; keep previous edge data
1089
+ if (0.0 === projToPrevEdge.x || 0.0 === projToEdge.x)
1090
+ continue; // point is on subsequent colinear edge (ASSUMING interior point, convex polygon!); coords[i] = 0; keep previous edge data
1091
+ const areaOfNormalParallelogram = Math.abs(outwardUnitNormalOfPrevEdge.crossProductXY(outwardUnitNormalOfEdge));
1092
+ const coord = Geometry.conditionalDivideCoordinate(areaOfNormalParallelogram, projToPrevEdge.x * projToEdge.x, largestResult);
1093
+ if (undefined === coord) {
1094
+ assert(!"unexpectedly small projection distance to an edge");
1095
+ return undefined; // shouldn't happen due to chopping in computeEdgeDataXY: area/(dist*dist) <= 1/tol^2 = largestResult
1096
+ }
1097
+ coords[i] = coord;
1098
+ coordSum += coord;
1099
+ outwardUnitNormalOfPrevEdge.setFrom(outwardUnitNormalOfEdge);
1100
+ projToPrevEdge.setFrom(projToEdge);
1101
+ iPrev = i;
1102
+ }
1103
+ const scale = Geometry.conditionalDivideCoordinate(1.0, coordSum);
1104
+ if (undefined === scale) {
1105
+ assert(!"unexpected zero barycentric coordinate sum");
1106
+ return undefined;
1107
+ }
1108
+ for (let i = 0; i < n; ++i)
1109
+ coords[i] *= scale; // normalized
1110
+ return coords;
1111
+ }
715
1112
  }
716
1113
  /** These values are the integrated area moment products [xx,xy,xz, x]
717
1114
  * for a right triangle in the first quadrant at the origin -- (0,0),(1,0),(0,1)