@itwin/core-geometry 5.0.0-dev.82 → 5.0.0-dev.83

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 (61) hide show
  1. package/lib/cjs/Geometry.d.ts +2 -4
  2. package/lib/cjs/Geometry.d.ts.map +1 -1
  3. package/lib/cjs/Geometry.js +2 -4
  4. package/lib/cjs/Geometry.js.map +1 -1
  5. package/lib/cjs/geometry3d/AngleSweep.d.ts +1 -1
  6. package/lib/cjs/geometry3d/AngleSweep.d.ts.map +1 -1
  7. package/lib/cjs/geometry3d/AngleSweep.js +1 -1
  8. package/lib/cjs/geometry3d/AngleSweep.js.map +1 -1
  9. package/lib/cjs/geometry3d/Point3dVector3d.d.ts +1 -4
  10. package/lib/cjs/geometry3d/Point3dVector3d.d.ts.map +1 -1
  11. package/lib/cjs/geometry3d/Point3dVector3d.js +4 -4
  12. package/lib/cjs/geometry3d/Point3dVector3d.js.map +1 -1
  13. package/lib/cjs/geometry3d/PointHelpers.d.ts +1 -1
  14. package/lib/cjs/geometry3d/PointHelpers.d.ts.map +1 -1
  15. package/lib/cjs/geometry3d/PointHelpers.js.map +1 -1
  16. package/lib/cjs/geometry3d/Transform.d.ts +1 -1
  17. package/lib/cjs/geometry3d/Transform.js +1 -1
  18. package/lib/cjs/geometry3d/Transform.js.map +1 -1
  19. package/lib/cjs/serialization/IModelJsonSchema.d.ts +54 -41
  20. package/lib/cjs/serialization/IModelJsonSchema.d.ts.map +1 -1
  21. package/lib/cjs/serialization/IModelJsonSchema.js +83 -69
  22. package/lib/cjs/serialization/IModelJsonSchema.js.map +1 -1
  23. package/lib/cjs/solid/Cone.d.ts +39 -14
  24. package/lib/cjs/solid/Cone.d.ts.map +1 -1
  25. package/lib/cjs/solid/Cone.js +50 -18
  26. package/lib/cjs/solid/Cone.js.map +1 -1
  27. package/lib/cjs/solid/Sphere.d.ts +34 -17
  28. package/lib/cjs/solid/Sphere.d.ts.map +1 -1
  29. package/lib/cjs/solid/Sphere.js +47 -22
  30. package/lib/cjs/solid/Sphere.js.map +1 -1
  31. package/lib/esm/Geometry.d.ts +2 -4
  32. package/lib/esm/Geometry.d.ts.map +1 -1
  33. package/lib/esm/Geometry.js +2 -4
  34. package/lib/esm/Geometry.js.map +1 -1
  35. package/lib/esm/geometry3d/AngleSweep.d.ts +1 -1
  36. package/lib/esm/geometry3d/AngleSweep.d.ts.map +1 -1
  37. package/lib/esm/geometry3d/AngleSweep.js +1 -1
  38. package/lib/esm/geometry3d/AngleSweep.js.map +1 -1
  39. package/lib/esm/geometry3d/Point3dVector3d.d.ts +1 -4
  40. package/lib/esm/geometry3d/Point3dVector3d.d.ts.map +1 -1
  41. package/lib/esm/geometry3d/Point3dVector3d.js +4 -4
  42. package/lib/esm/geometry3d/Point3dVector3d.js.map +1 -1
  43. package/lib/esm/geometry3d/PointHelpers.d.ts +1 -1
  44. package/lib/esm/geometry3d/PointHelpers.d.ts.map +1 -1
  45. package/lib/esm/geometry3d/PointHelpers.js.map +1 -1
  46. package/lib/esm/geometry3d/Transform.d.ts +1 -1
  47. package/lib/esm/geometry3d/Transform.js +1 -1
  48. package/lib/esm/geometry3d/Transform.js.map +1 -1
  49. package/lib/esm/serialization/IModelJsonSchema.d.ts +54 -41
  50. package/lib/esm/serialization/IModelJsonSchema.d.ts.map +1 -1
  51. package/lib/esm/serialization/IModelJsonSchema.js +83 -69
  52. package/lib/esm/serialization/IModelJsonSchema.js.map +1 -1
  53. package/lib/esm/solid/Cone.d.ts +39 -14
  54. package/lib/esm/solid/Cone.d.ts.map +1 -1
  55. package/lib/esm/solid/Cone.js +51 -19
  56. package/lib/esm/solid/Cone.js.map +1 -1
  57. package/lib/esm/solid/Sphere.d.ts +34 -17
  58. package/lib/esm/solid/Sphere.d.ts.map +1 -1
  59. package/lib/esm/solid/Sphere.js +48 -23
  60. package/lib/esm/solid/Sphere.js.map +1 -1
  61. package/package.json +3 -3
@@ -191,10 +191,19 @@ export var IModelJson;
191
191
  return defaultValue;
192
192
  }
193
193
  static parseAxesFromVectors(json, axisOrder, createDefaultIdentity) {
194
- if (Array.isArray(json) && json.length === 2) {
195
- const xVector = Vector3d.fromJSON(json[0]);
196
- const yVector = Vector3d.fromJSON(json[1]);
197
- const matrix = Matrix3d.createRigidFromColumns(xVector, yVector, axisOrder);
194
+ if (Array.isArray(json)) {
195
+ let matrix;
196
+ if (json.length === 2) { // square and normalize
197
+ const xVector = Vector3d.fromJSON(json[0]);
198
+ const yVector = Vector3d.fromJSON(json[1]);
199
+ matrix = Matrix3d.createRigidFromColumns(xVector, yVector, axisOrder);
200
+ }
201
+ else if (json.length === 3) { // preserve axes
202
+ const xVector = Vector3d.fromJSON(json[0]);
203
+ const yVector = Vector3d.fromJSON(json[1]);
204
+ const zVector = Vector3d.fromJSON(json[2]);
205
+ matrix = Matrix3d.createColumnsInAxisOrder(axisOrder, xVector, yVector, zVector);
206
+ }
198
207
  if (matrix)
199
208
  return matrix;
200
209
  }
@@ -204,23 +213,23 @@ export var IModelJson;
204
213
  }
205
214
  /**
206
215
  * Look for orientation data and convert to Matrix3d.
207
- * * Search order is:
208
- * * * yawPitchRollAngles
209
- * * * xyVectors
210
- * * * zxVectors
216
+ * * Search order and interpretation:
217
+ * * * xyzVectors - general matrix, axes preserved
218
+ * * * yawPitchRollAngles - right-handed rotation via axial rotations
219
+ * * * xyVectors - right-handed rotation, xy-plane specified, axes squared and normalized
220
+ * * * zxVectors - right-handed rotation, zx-plane specified, axes squared and normalized
211
221
  * @param json [in] json source data
212
222
  * @param createDefaultIdentity [in] If true and no orientation is present, return an identity matrix. If false and no orientation is present, return undefined.
213
223
  */
214
224
  static parseOrientation(json, createDefaultIdentity) {
215
- if (json.yawPitchRollAngles) {
225
+ if (json.xyzVectors)
226
+ return Reader.parseAxesFromVectors(json.xyzVectors, AxisOrder.XYZ, createDefaultIdentity);
227
+ if (json.yawPitchRollAngles)
216
228
  return Reader.parseYawPitchRollAnglesToMatrix3d(json.yawPitchRollAngles);
217
- }
218
- else if (json.xyVectors) {
229
+ if (json.xyVectors)
219
230
  return Reader.parseAxesFromVectors(json.xyVectors, AxisOrder.XYZ, createDefaultIdentity);
220
- }
221
- else if (json.zxVectors) {
231
+ if (json.zxVectors)
222
232
  return Reader.parseAxesFromVectors(json.zxVectors, AxisOrder.ZXY, createDefaultIdentity);
223
- }
224
233
  if (createDefaultIdentity)
225
234
  return Matrix3d.createIdentity();
226
235
  return undefined;
@@ -464,11 +473,8 @@ export var IModelJson;
464
473
  const radius = Reader.parseNumberProperty(json, "radius");
465
474
  const startRadius = Reader.parseNumberProperty(json, "startRadius", radius);
466
475
  const endRadius = Reader.parseNumberProperty(json, "endRadius", startRadius);
467
- const capped = Reader.parseBooleanProperty(json, "capped", false);
468
- if (start
469
- && end
470
- && startRadius !== undefined
471
- && endRadius !== undefined) {
476
+ const capped = Reader.parseBooleanProperty(json, "capped");
477
+ if (start && end && startRadius !== undefined && endRadius !== undefined) {
472
478
  if (axes === undefined) {
473
479
  const axisVector = Vector3d.createStartEnd(start, end);
474
480
  const frame = Matrix3d.createRigidHeadsUp(axisVector, AxisOrder.ZXY);
@@ -476,9 +482,7 @@ export var IModelJson;
476
482
  const vectorY = frame.columnY();
477
483
  return Cone.createBaseAndTarget(start, end, vectorX, vectorY, startRadius, endRadius, capped);
478
484
  }
479
- else {
480
- return Cone.createBaseAndTarget(start, end, axes.columnX(), axes.columnY(), startRadius, endRadius, capped);
481
- }
485
+ return Cone.createBaseAndTarget(start, end, axes.columnX(), axes.columnY(), startRadius, endRadius, capped);
482
486
  }
483
487
  return undefined;
484
488
  }
@@ -564,23 +568,15 @@ export var IModelJson;
564
568
  /** Parse `SphereProps` to `Sphere` instance. */
565
569
  static parseSphere(json) {
566
570
  const center = Reader.parsePoint3dProperty(json, "center");
567
- // optional unqualified radius . . .
568
571
  const radius = Reader.parseNumberProperty(json, "radius");
569
- // optional specific X
570
572
  const radiusX = Reader.parseNumberProperty(json, "radiusX", radius);
571
- // missing Y and Z both pick up radiusX (which may have already been defaulted from unqualified radius)
572
573
  const radiusY = Reader.parseNumberProperty(json, "radiusY", radiusX);
573
- const radiusZ = Reader.parseNumberProperty(json, "radiusZ", radiusX);
574
- const latitudeStartEnd = Reader.parseAngleSweepProps(json, "latitudeStartEnd"); // this may be undefined!!
575
- const axes = Reader.parseOrientation(json, true);
576
- const capped = Reader.parseBooleanProperty(json, "capped", false);
577
- if (center !== undefined
578
- && radiusX !== undefined
579
- && radiusY !== undefined
580
- && radiusZ !== undefined
581
- && capped !== undefined) {
574
+ const radiusZ = Reader.parseNumberProperty(json, "radiusZ", radiusY);
575
+ const latitudeStartEnd = Reader.parseAngleSweepProps(json, "latitudeStartEnd");
576
+ const axes = Reader.parseOrientation(json, false);
577
+ const capped = Reader.parseBooleanProperty(json, "capped");
578
+ if (center && radiusX && radiusY && radiusZ)
582
579
  return Sphere.createFromAxesAndScales(center, axes, radiusX, radiusY, radiusZ, latitudeStartEnd, capped);
583
- }
584
580
  return undefined;
585
581
  }
586
582
  /** Parse RuledSweepProps to RuledSweep instance. */
@@ -705,11 +701,6 @@ export var IModelJson;
705
701
  }
706
702
  }
707
703
  IModelJson.Reader = Reader;
708
- // ISSUE: include 3d in names?
709
- // ISSUE: would like shorter term than lineSegment
710
- // ISSUE: is arc clear?
711
- // ISSUE: label center, vectorX, vector90 on arc?
712
- // ISSUE: sweep data on arc -- serialize as AngleSweep?
713
704
  /**
714
705
  * Class to deserialize json objects into GeometryQuery objects
715
706
  * @public
@@ -858,63 +849,86 @@ export var IModelJson;
858
849
  const centerB = data.getCenterB();
859
850
  const vectorX = data.getVectorX();
860
851
  const vectorY = data.getVectorY();
852
+ const xMag = vectorX.magnitude();
853
+ const yMag = vectorY.magnitude();
854
+ const xySameLength = Geometry.isSameCoordinate(xMag, yMag);
861
855
  const axisVector = Vector3d.createStartEnd(centerA, centerB);
856
+ // special case of cylinder
862
857
  if (Geometry.isSameCoordinate(radiusA, radiusB)
863
858
  && vectorX.isPerpendicularTo(axisVector)
864
859
  && vectorY.isPerpendicularTo(axisVector)
865
- && Geometry.isSameCoordinate(vectorX.magnitude(), 1.0)
866
- && Geometry.isSameCoordinate(vectorY.magnitude(), 1.0)) {
860
+ && xySameLength
861
+ && Geometry.isSameCoordinate(xMag, 1.0)) {
867
862
  return {
868
863
  cylinder: {
869
864
  capped: data.capped,
870
- start: data.getCenterA().toJSON(),
871
- end: data.getCenterB().toJSON(),
865
+ start: centerA.toJSON(),
866
+ end: centerB.toJSON(),
872
867
  radius: radiusA,
873
868
  },
874
869
  };
875
870
  }
871
+ const coneProps = {
872
+ capped: data.capped,
873
+ start: centerA.toJSON(),
874
+ end: centerB.toJSON(),
875
+ };
876
+ if (Geometry.isSameCoordinate(radiusA, radiusB)) {
877
+ coneProps.radius = radiusA;
878
+ }
876
879
  else {
877
- const coneProps = {
878
- capped: data.capped,
879
- start: data.getCenterA().toJSON(),
880
- end: data.getCenterB().toJSON(),
881
- startRadius: data.getRadiusA(),
882
- endRadius: data.getRadiusB(),
883
- };
884
- Writer.insertOrientationFromXYVectors(coneProps, vectorX, vectorY, false);
885
- return { cone: coneProps };
880
+ coneProps.startRadius = radiusA;
881
+ coneProps.endRadius = radiusB;
886
882
  }
883
+ // always specify an orthogonal frame for backwards compatibility
884
+ Writer.insertOrientationFromXYVectors(coneProps, vectorX, vectorY, false);
885
+ // specify a general matrix if elliptical sections
886
+ const ellipticalSections = !xySameLength || !vectorX.isPerpendicularTo(vectorY, true);
887
+ if (ellipticalSections)
888
+ coneProps.xyzVectors = [vectorX.toJSON(), vectorY.toJSON(), axisVector.toJSON()];
889
+ return { cone: coneProps };
887
890
  }
888
891
  /** Convert strongly typed instance to tagged json */
889
892
  handleSphere(data) {
890
893
  const xData = data.cloneVectorX().normalizeWithLength();
891
894
  const yData = data.cloneVectorY().normalizeWithLength();
892
895
  const zData = data.cloneVectorZ().normalizeWithLength();
896
+ if (!xData.v || !yData.v || !zData.v)
897
+ return undefined;
898
+ const rigid = Matrix3d.createIdentity();
899
+ const skew = Matrix3d.createIdentity();
900
+ if (!data.cloneLocalToWorld().matrix.factorRigidSkew(rigid, skew))
901
+ return undefined;
902
+ const value = { center: data.cloneCenter().toJSON() };
903
+ // always specify an orthogonal frame if !identity for backwards compatibility
904
+ if (!rigid.isIdentity)
905
+ value.zxVectors = [zData.v.toJSON(), xData.v.toJSON()];
906
+ // specify a general matrix if skew/mirror local frame
907
+ if (!skew.isDiagonal || skew.determinant() < 0.0)
908
+ value.xyzVectors = [xData.v.toJSON(), yData.v.toJSON(), zData.v.toJSON()];
893
909
  const latitudeSweep = data.cloneLatitudeSweep();
910
+ const fullSweep = latitudeSweep.isFullLatitudeSweep;
911
+ if (data.capped && !fullSweep)
912
+ value.capped = data.capped;
913
+ if (!fullSweep)
914
+ value.latitudeStartEnd = latitudeSweep.toJSON();
894
915
  const rX = xData.mag;
895
916
  const rY = yData.mag;
896
917
  const rZ = zData.mag;
897
- if (xData.v && zData.v) {
898
- const value = {
899
- center: data.cloneCenter().toJSON(),
900
- };
901
- if (!(data.getConstructiveFrame()).matrix.isIdentity)
902
- value.zxVectors = [zData.v.toJSON(), xData.v.toJSON()];
903
- const fullSweep = latitudeSweep.isFullLatitudeSweep;
904
- if (data.capped && !fullSweep)
905
- value.capped = data.capped;
906
- if (Geometry.isSameCoordinate(rX, rY) && Geometry.isSameCoordinate(rX, rZ))
918
+ if (Geometry.isSameCoordinate(rX, rY)) {
919
+ if (Geometry.isSameCoordinate(rX, rZ))
907
920
  value.radius = rX;
908
- else {
921
+ else { // radiusY will pick up radiusX
909
922
  value.radiusX = rX;
910
- value.radiusY = rY;
911
923
  value.radiusZ = rZ;
912
924
  }
913
- if (!fullSweep)
914
- value.latitudeStartEnd = latitudeSweep.toJSON();
915
- return { sphere: value };
916
925
  }
917
- return undefined;
926
+ else {
927
+ value.radiusX = rX;
928
+ value.radiusY = rY;
929
+ value.radiusZ = rZ;
930
+ }
931
+ return { sphere: value };
918
932
  }
919
933
  /** Convert strongly typed instance to tagged json */
920
934
  handleTorusPipe(data) {