@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
@@ -499,26 +499,28 @@ export class PolygonOps {
499
499
  return s;
500
500
  }
501
501
  /**
502
- * Return a Ray3d with (assuming the polygon is planar and not self-intersecting):
503
- * * `origin` at the centroid of the (3D) polygon,
504
- * * `direction` is the unit vector perpendicular to the plane,
505
- * * `a` is the area.
506
- * @param points
502
+ * Return a [[Ray3d]] with:
503
+ * * `origin` is the centroid of the polygon,
504
+ * * `direction` is a unit vector perpendicular to the polygon plane,
505
+ * * `a` is the polygon area.
506
+ * @param points the polygon vertices in order. Points can lie in any plane. First and last point do not have to be equal.
507
+ * @param result optional pre-allocated result to populate and return.
507
508
  */
508
- static centroidAreaNormal(points) {
509
+ static centroidAreaNormal(points, result) {
509
510
  if (Array.isArray(points)) {
510
511
  const carrier = new Point3dArrayCarrier(points);
511
- return this.centroidAreaNormal(carrier);
512
+ return this.centroidAreaNormal(carrier, result);
512
513
  }
513
514
  const n = points.length;
514
515
  if (n === 3) {
515
- const normal = points.crossProductIndexIndexIndex(0, 1, 2);
516
+ const normal = points.crossProductIndexIndexIndex(0, 1, 2, result?.direction);
516
517
  const a = 0.5 * normal.magnitude();
517
- const centroid = points.getPoint3dAtCheckedPointIndex(0);
518
+ const centroid = points.getPoint3dAtCheckedPointIndex(0, result?.origin);
518
519
  points.accumulateScaledXYZ(1, 1.0, centroid);
519
520
  points.accumulateScaledXYZ(2, 1.0, centroid);
520
521
  centroid.scaleInPlace(1.0 / 3.0);
521
- const result = Ray3d.createCapture(centroid, normal);
522
+ if (!result)
523
+ result = Ray3d.createCapture(centroid, normal);
522
524
  if (result.tryNormalizeInPlaceWithAreaWeight(a))
523
525
  return result;
524
526
  return undefined;
@@ -536,22 +538,24 @@ export class PolygonOps {
536
538
  points.vectorXYAndZIndex(origin, 1, vector0);
537
539
  let cross = Vector3d.create();
538
540
  const centroidSum = Vector3d.createZero();
539
- const normalSum = Vector3d.createZero();
541
+ const normal = Vector3d.createZero(result?.direction);
540
542
  let signedTriangleArea;
541
- // This will work with or without closure edge. If closure is given, the last vector is 000.
543
+ // This will work with or without closure edge. If closure is given, the last vector is 000.
542
544
  for (let i = 2; i < n; i++) {
543
545
  points.vectorXYAndZIndex(origin, i, vector1);
544
546
  cross = vector0.crossProduct(vector1, cross);
545
547
  signedTriangleArea = areaNormal.dotProduct(cross); // well, actually twice the area.
546
- normalSum.addInPlace(cross); // this grows to twice the area
548
+ normal.addInPlace(cross); // this grows to twice the area
547
549
  const b = signedTriangleArea / 6.0;
548
550
  centroidSum.plus2Scaled(vector0, b, vector1, b, centroidSum);
549
551
  vector0.setFrom(vector1);
550
552
  }
551
- const area = 0.5 * normalSum.magnitude();
553
+ const area = 0.5 * normal.magnitude();
552
554
  const inverseArea = Geometry.conditionalDivideFraction(1, area);
553
555
  if (inverseArea !== undefined) {
554
- const result = Ray3d.createCapture(origin.plusScaled(centroidSum, inverseArea), normalSum);
556
+ const centroid = origin.plusScaled(centroidSum, inverseArea, result?.origin);
557
+ if (!result)
558
+ result = Ray3d.createCapture(centroid, normal);
555
559
  result.tryNormalizeInPlaceWithAreaWeight(area);
556
560
  return result;
557
561
  }