@itwin/core-geometry 5.1.0-dev.3 → 5.1.0-dev.4

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 (47) hide show
  1. package/lib/cjs/curve/RegionMomentsXY.d.ts +14 -21
  2. package/lib/cjs/curve/RegionMomentsXY.d.ts.map +1 -1
  3. package/lib/cjs/curve/RegionMomentsXY.js +23 -25
  4. package/lib/cjs/curve/RegionMomentsXY.js.map +1 -1
  5. package/lib/cjs/curve/RegionOps.d.ts +27 -10
  6. package/lib/cjs/curve/RegionOps.d.ts.map +1 -1
  7. package/lib/cjs/curve/RegionOps.js +58 -13
  8. package/lib/cjs/curve/RegionOps.js.map +1 -1
  9. package/lib/cjs/geometry3d/Point3dVector3d.d.ts.map +1 -1
  10. package/lib/cjs/geometry3d/Point3dVector3d.js +3 -3
  11. package/lib/cjs/geometry3d/Point3dVector3d.js.map +1 -1
  12. package/lib/cjs/geometry3d/PolygonOps.d.ts +8 -7
  13. package/lib/cjs/geometry3d/PolygonOps.d.ts.map +1 -1
  14. package/lib/cjs/geometry3d/PolygonOps.js +19 -15
  15. package/lib/cjs/geometry3d/PolygonOps.js.map +1 -1
  16. package/lib/cjs/geometry4d/Matrix4d.d.ts +7 -7
  17. package/lib/cjs/geometry4d/Matrix4d.d.ts.map +1 -1
  18. package/lib/cjs/geometry4d/Matrix4d.js +9 -9
  19. package/lib/cjs/geometry4d/Matrix4d.js.map +1 -1
  20. package/lib/cjs/geometry4d/MomentData.d.ts +32 -34
  21. package/lib/cjs/geometry4d/MomentData.d.ts.map +1 -1
  22. package/lib/cjs/geometry4d/MomentData.js +56 -57
  23. package/lib/cjs/geometry4d/MomentData.js.map +1 -1
  24. package/lib/esm/curve/RegionMomentsXY.d.ts +14 -21
  25. package/lib/esm/curve/RegionMomentsXY.d.ts.map +1 -1
  26. package/lib/esm/curve/RegionMomentsXY.js +23 -25
  27. package/lib/esm/curve/RegionMomentsXY.js.map +1 -1
  28. package/lib/esm/curve/RegionOps.d.ts +27 -10
  29. package/lib/esm/curve/RegionOps.d.ts.map +1 -1
  30. package/lib/esm/curve/RegionOps.js +59 -14
  31. package/lib/esm/curve/RegionOps.js.map +1 -1
  32. package/lib/esm/geometry3d/Point3dVector3d.d.ts.map +1 -1
  33. package/lib/esm/geometry3d/Point3dVector3d.js +3 -3
  34. package/lib/esm/geometry3d/Point3dVector3d.js.map +1 -1
  35. package/lib/esm/geometry3d/PolygonOps.d.ts +8 -7
  36. package/lib/esm/geometry3d/PolygonOps.d.ts.map +1 -1
  37. package/lib/esm/geometry3d/PolygonOps.js +19 -15
  38. package/lib/esm/geometry3d/PolygonOps.js.map +1 -1
  39. package/lib/esm/geometry4d/Matrix4d.d.ts +7 -7
  40. package/lib/esm/geometry4d/Matrix4d.d.ts.map +1 -1
  41. package/lib/esm/geometry4d/Matrix4d.js +9 -9
  42. package/lib/esm/geometry4d/Matrix4d.js.map +1 -1
  43. package/lib/esm/geometry4d/MomentData.d.ts +32 -34
  44. package/lib/esm/geometry4d/MomentData.d.ts.map +1 -1
  45. package/lib/esm/geometry4d/MomentData.js +56 -57
  46. package/lib/esm/geometry4d/MomentData.js.map +1 -1
  47. package/package.json +3 -3
@@ -506,26 +506,28 @@ class PolygonOps {
506
506
  return s;
507
507
  }
508
508
  /**
509
- * Return a Ray3d with (assuming the polygon is planar and not self-intersecting):
510
- * * `origin` at the centroid of the (3D) polygon,
511
- * * `direction` is the unit vector perpendicular to the plane,
512
- * * `a` is the area.
513
- * @param points
509
+ * Return a [[Ray3d]] with:
510
+ * * `origin` is the centroid of the polygon,
511
+ * * `direction` is a unit vector perpendicular to the polygon plane,
512
+ * * `a` is the polygon area.
513
+ * @param points the polygon vertices in order. Points can lie in any plane. First and last point do not have to be equal.
514
+ * @param result optional pre-allocated result to populate and return.
514
515
  */
515
- static centroidAreaNormal(points) {
516
+ static centroidAreaNormal(points, result) {
516
517
  if (Array.isArray(points)) {
517
518
  const carrier = new Point3dArrayCarrier_1.Point3dArrayCarrier(points);
518
- return this.centroidAreaNormal(carrier);
519
+ return this.centroidAreaNormal(carrier, result);
519
520
  }
520
521
  const n = points.length;
521
522
  if (n === 3) {
522
- const normal = points.crossProductIndexIndexIndex(0, 1, 2);
523
+ const normal = points.crossProductIndexIndexIndex(0, 1, 2, result?.direction);
523
524
  const a = 0.5 * normal.magnitude();
524
- const centroid = points.getPoint3dAtCheckedPointIndex(0);
525
+ const centroid = points.getPoint3dAtCheckedPointIndex(0, result?.origin);
525
526
  points.accumulateScaledXYZ(1, 1.0, centroid);
526
527
  points.accumulateScaledXYZ(2, 1.0, centroid);
527
528
  centroid.scaleInPlace(1.0 / 3.0);
528
- const result = Ray3d_1.Ray3d.createCapture(centroid, normal);
529
+ if (!result)
530
+ result = Ray3d_1.Ray3d.createCapture(centroid, normal);
529
531
  if (result.tryNormalizeInPlaceWithAreaWeight(a))
530
532
  return result;
531
533
  return undefined;
@@ -543,22 +545,24 @@ class PolygonOps {
543
545
  points.vectorXYAndZIndex(origin, 1, vector0);
544
546
  let cross = Point3dVector3d_1.Vector3d.create();
545
547
  const centroidSum = Point3dVector3d_1.Vector3d.createZero();
546
- const normalSum = Point3dVector3d_1.Vector3d.createZero();
548
+ const normal = Point3dVector3d_1.Vector3d.createZero(result?.direction);
547
549
  let signedTriangleArea;
548
- // This will work with or without closure edge. If closure is given, the last vector is 000.
550
+ // This will work with or without closure edge. If closure is given, the last vector is 000.
549
551
  for (let i = 2; i < n; i++) {
550
552
  points.vectorXYAndZIndex(origin, i, vector1);
551
553
  cross = vector0.crossProduct(vector1, cross);
552
554
  signedTriangleArea = areaNormal.dotProduct(cross); // well, actually twice the area.
553
- normalSum.addInPlace(cross); // this grows to twice the area
555
+ normal.addInPlace(cross); // this grows to twice the area
554
556
  const b = signedTriangleArea / 6.0;
555
557
  centroidSum.plus2Scaled(vector0, b, vector1, b, centroidSum);
556
558
  vector0.setFrom(vector1);
557
559
  }
558
- const area = 0.5 * normalSum.magnitude();
560
+ const area = 0.5 * normal.magnitude();
559
561
  const inverseArea = Geometry_1.Geometry.conditionalDivideFraction(1, area);
560
562
  if (inverseArea !== undefined) {
561
- const result = Ray3d_1.Ray3d.createCapture(origin.plusScaled(centroidSum, inverseArea), normalSum);
563
+ const centroid = origin.plusScaled(centroidSum, inverseArea, result?.origin);
564
+ if (!result)
565
+ result = Ray3d_1.Ray3d.createCapture(centroid, normal);
562
566
  result.tryNormalizeInPlaceWithAreaWeight(area);
563
567
  return result;
564
568
  }