@itwin/core-geometry 5.1.0-dev.3 → 5.1.0-dev.5
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.
- package/lib/cjs/curve/RegionMomentsXY.d.ts +14 -21
- package/lib/cjs/curve/RegionMomentsXY.d.ts.map +1 -1
- package/lib/cjs/curve/RegionMomentsXY.js +23 -25
- package/lib/cjs/curve/RegionMomentsXY.js.map +1 -1
- package/lib/cjs/curve/RegionOps.d.ts +27 -10
- package/lib/cjs/curve/RegionOps.d.ts.map +1 -1
- package/lib/cjs/curve/RegionOps.js +58 -13
- package/lib/cjs/curve/RegionOps.js.map +1 -1
- package/lib/cjs/geometry3d/Point3dVector3d.d.ts.map +1 -1
- package/lib/cjs/geometry3d/Point3dVector3d.js +3 -3
- package/lib/cjs/geometry3d/Point3dVector3d.js.map +1 -1
- package/lib/cjs/geometry3d/PolygonOps.d.ts +8 -7
- package/lib/cjs/geometry3d/PolygonOps.d.ts.map +1 -1
- package/lib/cjs/geometry3d/PolygonOps.js +19 -15
- package/lib/cjs/geometry3d/PolygonOps.js.map +1 -1
- package/lib/cjs/geometry4d/Matrix4d.d.ts +7 -7
- package/lib/cjs/geometry4d/Matrix4d.d.ts.map +1 -1
- package/lib/cjs/geometry4d/Matrix4d.js +9 -9
- package/lib/cjs/geometry4d/Matrix4d.js.map +1 -1
- package/lib/cjs/geometry4d/MomentData.d.ts +32 -34
- package/lib/cjs/geometry4d/MomentData.d.ts.map +1 -1
- package/lib/cjs/geometry4d/MomentData.js +56 -57
- package/lib/cjs/geometry4d/MomentData.js.map +1 -1
- package/lib/esm/curve/RegionMomentsXY.d.ts +14 -21
- package/lib/esm/curve/RegionMomentsXY.d.ts.map +1 -1
- package/lib/esm/curve/RegionMomentsXY.js +23 -25
- package/lib/esm/curve/RegionMomentsXY.js.map +1 -1
- package/lib/esm/curve/RegionOps.d.ts +27 -10
- package/lib/esm/curve/RegionOps.d.ts.map +1 -1
- package/lib/esm/curve/RegionOps.js +59 -14
- package/lib/esm/curve/RegionOps.js.map +1 -1
- package/lib/esm/geometry3d/Point3dVector3d.d.ts.map +1 -1
- package/lib/esm/geometry3d/Point3dVector3d.js +3 -3
- package/lib/esm/geometry3d/Point3dVector3d.js.map +1 -1
- package/lib/esm/geometry3d/PolygonOps.d.ts +8 -7
- package/lib/esm/geometry3d/PolygonOps.d.ts.map +1 -1
- package/lib/esm/geometry3d/PolygonOps.js +19 -15
- package/lib/esm/geometry3d/PolygonOps.js.map +1 -1
- package/lib/esm/geometry4d/Matrix4d.d.ts +7 -7
- package/lib/esm/geometry4d/Matrix4d.d.ts.map +1 -1
- package/lib/esm/geometry4d/Matrix4d.js +9 -9
- package/lib/esm/geometry4d/Matrix4d.js.map +1 -1
- package/lib/esm/geometry4d/MomentData.d.ts +32 -34
- package/lib/esm/geometry4d/MomentData.d.ts.map +1 -1
- package/lib/esm/geometry4d/MomentData.js +56 -57
- package/lib/esm/geometry4d/MomentData.js.map +1 -1
- package/package.json +3 -3
|
@@ -506,26 +506,28 @@ class PolygonOps {
|
|
|
506
506
|
return s;
|
|
507
507
|
}
|
|
508
508
|
/**
|
|
509
|
-
* Return a Ray3d with
|
|
510
|
-
* * `origin`
|
|
511
|
-
* * `direction` is
|
|
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
|
-
|
|
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
|
|
548
|
+
const normal = Point3dVector3d_1.Vector3d.createZero(result?.direction);
|
|
547
549
|
let signedTriangleArea;
|
|
548
|
-
// This will work with or without closure edge.
|
|
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
|
-
|
|
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 *
|
|
560
|
+
const area = 0.5 * normal.magnitude();
|
|
559
561
|
const inverseArea = Geometry_1.Geometry.conditionalDivideFraction(1, area);
|
|
560
562
|
if (inverseArea !== undefined) {
|
|
561
|
-
const
|
|
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
|
}
|