@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.
- 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
|
@@ -499,26 +499,28 @@ export class PolygonOps {
|
|
|
499
499
|
return s;
|
|
500
500
|
}
|
|
501
501
|
/**
|
|
502
|
-
* Return a Ray3d with
|
|
503
|
-
* * `origin`
|
|
504
|
-
* * `direction` is
|
|
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
|
-
|
|
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
|
|
541
|
+
const normal = Vector3d.createZero(result?.direction);
|
|
540
542
|
let signedTriangleArea;
|
|
541
|
-
// This will work with or without closure edge.
|
|
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
|
-
|
|
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 *
|
|
553
|
+
const area = 0.5 * normal.magnitude();
|
|
552
554
|
const inverseArea = Geometry.conditionalDivideFraction(1, area);
|
|
553
555
|
if (inverseArea !== undefined) {
|
|
554
|
-
const
|
|
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
|
}
|