@vertexvis/geometry 0.13.1 → 0.13.2-canary.10

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.
@@ -29,7 +29,7 @@ function lerp$2(a, b, t) {
29
29
  /**
30
30
  * Returns a new `Point` with the given horizontal and vertical position.
31
31
  */
32
- function create$b(x, y) {
32
+ function create$c(x, y) {
33
33
  if (x === void 0) { x = 0; }
34
34
  if (y === void 0) { y = 0; }
35
35
  return { x: x, y: y };
@@ -40,7 +40,7 @@ function create$b(x, y) {
40
40
  function polar(length, radians) {
41
41
  var x = Math.cos(radians) * length;
42
42
  var y = Math.sin(radians) * length;
43
- return create$b(x, y);
43
+ return create$c(x, y);
44
44
  }
45
45
  /**
46
46
  * Returns the distance between two points.
@@ -86,7 +86,7 @@ function lerp$1(a, b, t) {
86
86
  * Returns a new `Point` where `x` and `y` are inverted.
87
87
  */
88
88
  function negate$1(pt) {
89
- return create$b(-pt.x, -pt.y);
89
+ return create$c(-pt.x, -pt.y);
90
90
  }
91
91
  /**
92
92
  * Returns a new `Point` where `x` and `y` are multiplied by the given scale
@@ -108,17 +108,17 @@ function fromJson$4(json) {
108
108
  var obj = JSON.parse(json);
109
109
  if (Array.isArray(obj)) {
110
110
  var x = obj[0], y = obj[1];
111
- return create$b(x, y);
111
+ return create$c(x, y);
112
112
  }
113
113
  else {
114
114
  var x = obj.x, y = obj.y;
115
- return create$b(x, y);
115
+ return create$c(x, y);
116
116
  }
117
117
  }
118
118
 
119
119
  var point = /*#__PURE__*/Object.freeze({
120
120
  __proto__: null,
121
- create: create$b,
121
+ create: create$c,
122
122
  polar: polar,
123
123
  distance: distance$2,
124
124
  subtract: subtract$1,
@@ -420,6 +420,39 @@ function makePerspective(near, far, fovY, aspect) {
420
420
  var bottom = -ymax;
421
421
  return makeFrustum(left, right, top, bottom, near, far);
422
422
  }
423
+ /**
424
+ * Creates an orthographic projection matrix.
425
+ *
426
+ * Related to: gluOrtho. The viewing volume is cube-shaped and defined by
427
+ * the six parameters. The left and right values represent the coordinates of
428
+ * the vertical clipping planes, top and bottom values represent the coordinates
429
+ * of the horizontal clipping planes, and near and far values represent the
430
+ * coordinates of the depth clipping planes.
431
+ *
432
+ * @param left The coordinate of the left horizontal clipping plane.
433
+ * @param right The coordinate of the right horizontal clipping plane.
434
+ * @param bottom The coordinate of the bottom vertical clipping plane.
435
+ * @param top The coordinate of the top vertical clipping plane.
436
+ * @param near The coordinate of the near depth clipping plane.
437
+ * @param far The coordinate of the far depth clipping plane.
438
+ * @returns A matrix.
439
+ */
440
+ function makeOrthographic(left, right, bottom, top, near, far) {
441
+ var w = 1.0 / (right - left);
442
+ var h = 1.0 / (top - bottom);
443
+ var d = 1.0 / (far - near);
444
+ var x = (right + left) * w;
445
+ var y = (top + bottom) * h;
446
+ var z = (far + near) * d;
447
+ /* eslint-disable prettier/prettier */
448
+ return [
449
+ 2 * w, 0, 0, -x,
450
+ 0, 2 * h, 0, -y,
451
+ 0, 0, -2 * d, -z,
452
+ 0, 0, 0, 1
453
+ ];
454
+ /* eslint-enable prettier/prettier */
455
+ }
423
456
  /**
424
457
  * Matrix becomes a combination of an inverse translation and rotation.
425
458
  *
@@ -680,6 +713,7 @@ var matrix4 = /*#__PURE__*/Object.freeze({
680
713
  makeRotationAxis: makeRotationAxis,
681
714
  makeFrustum: makeFrustum,
682
715
  makePerspective: makePerspective,
716
+ makeOrthographic: makeOrthographic,
683
717
  makeLookAtView: makeLookAtView,
684
718
  makeLookAt: makeLookAt,
685
719
  invert: invert,
@@ -692,7 +726,7 @@ var matrix4 = /*#__PURE__*/Object.freeze({
692
726
  isType: isType$2
693
727
  });
694
728
 
695
- function create$a() {
729
+ function create$b() {
696
730
  var _a, _b, _c, _d, _e, _f;
697
731
  var args = [];
698
732
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -756,11 +790,11 @@ function fromJson$3(json) {
756
790
  var obj = JSON.parse(json);
757
791
  if (Array.isArray(obj)) {
758
792
  var x = obj[0], y = obj[1], z = obj[2];
759
- return create$a(x, y, z);
793
+ return create$b(x, y, z);
760
794
  }
761
795
  else {
762
796
  var x = obj.x, y = obj.y, z = obj.z;
763
- return create$a(x, y, z);
797
+ return create$b(x, y, z);
764
798
  }
765
799
  }
766
800
  /**
@@ -775,7 +809,7 @@ function fromArray(nums, offset) {
775
809
  var x = nums[offset];
776
810
  var y = nums[offset + 1];
777
811
  var z = nums[offset + 2];
778
- return create$a(x, y, z);
812
+ return create$b(x, y, z);
779
813
  }
780
814
  /**
781
815
  * Converts a Vector3 to an array where the values of the vector will be
@@ -792,43 +826,43 @@ function toArray(_a) {
792
826
  * Returns a directional vector on the positive x axis, Vector3(1, 0, 0).
793
827
  */
794
828
  function right() {
795
- return create$a(1, 0, 0);
829
+ return create$b(1, 0, 0);
796
830
  }
797
831
  /**
798
832
  * Returns a directional vector on the positive y axis, Vector3(0, 1, 0).
799
833
  */
800
834
  function up() {
801
- return create$a(0, 1, 0);
835
+ return create$b(0, 1, 0);
802
836
  }
803
837
  /**
804
838
  * Returns a directional vector on the positive z axis, Vector3(0, 0, -1).
805
839
  */
806
840
  function forward() {
807
- return create$a(0, 0, -1);
841
+ return create$b(0, 0, -1);
808
842
  }
809
843
  /**
810
844
  * Returns a directional vector on the negative x axis, Vector3(-1, 0, 0).
811
845
  */
812
846
  function left() {
813
- return create$a(-1, 0, 0);
847
+ return create$b(-1, 0, 0);
814
848
  }
815
849
  /**
816
850
  * Returns a directional vector on the negative y axis, Vector3(0, -1, 0).
817
851
  */
818
852
  function down() {
819
- return create$a(0, -1, 0);
853
+ return create$b(0, -1, 0);
820
854
  }
821
855
  /**
822
856
  * Returns a directional vector on the negative z axis, Vector3(0, 0, 1).
823
857
  */
824
858
  function back() {
825
- return create$a(0, 0, 1);
859
+ return create$b(0, 0, 1);
826
860
  }
827
861
  /**
828
862
  * Returns a vector at the origin, Vector3(0, 0, 0).
829
863
  */
830
864
  function origin() {
831
- return create$a(0, 0, 0);
865
+ return create$b(0, 0, 0);
832
866
  }
833
867
  /**
834
868
  * Returns a vector with that will have a magnitude of 1.
@@ -1011,13 +1045,13 @@ function isEqual$2(a, b) {
1011
1045
  * Returns a vector that contains the largest components of `a` and `b`.
1012
1046
  */
1013
1047
  function max(a, b) {
1014
- return create$a(Math.max(a.x, b.x), Math.max(a.y, b.y), Math.max(a.z, b.z));
1048
+ return create$b(Math.max(a.x, b.x), Math.max(a.y, b.y), Math.max(a.z, b.z));
1015
1049
  }
1016
1050
  /**
1017
1051
  * Returns a vector that contains the smallest components of `a` and `b`.
1018
1052
  */
1019
1053
  function min(a, b) {
1020
- return create$a(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.min(a.z, b.z));
1054
+ return create$b(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.min(a.z, b.z));
1021
1055
  }
1022
1056
  /**
1023
1057
  * Returns a vector that each of its component negated.
@@ -1055,7 +1089,7 @@ function transformNdcToWorldSpace(ndc, worldMatrix, projectionMatrixInverse) {
1055
1089
 
1056
1090
  var vector3 = /*#__PURE__*/Object.freeze({
1057
1091
  __proto__: null,
1058
- create: create$a,
1092
+ create: create$b,
1059
1093
  isValid: isValid,
1060
1094
  fromMatrixScale: fromMatrixScale,
1061
1095
  fromMatrixPosition: fromMatrixPosition,
@@ -1095,7 +1129,7 @@ var vector3 = /*#__PURE__*/Object.freeze({
1095
1129
  /**
1096
1130
  * Returns a `BoundingBox` with the given min and max points.
1097
1131
  */
1098
- var create$9 = function (min, max) {
1132
+ var create$a = function (min, max) {
1099
1133
  return { min: min, max: max };
1100
1134
  };
1101
1135
  /**
@@ -1103,7 +1137,7 @@ var create$9 = function (min, max) {
1103
1137
  * are contained by the bounding box.
1104
1138
  */
1105
1139
  var fromVectors = function (vectors) {
1106
- return union.apply(void 0, vectors.map(function (v) { return create$9(v, v); }));
1140
+ return union.apply(void 0, vectors.map(function (v) { return create$a(v, v); }));
1107
1141
  };
1108
1142
  /**
1109
1143
  * Returns the center point of the given `BoundingBox`.
@@ -1118,19 +1152,36 @@ function union(box) {
1118
1152
  }
1119
1153
  var boxes = __spreadArray([box], rest, true);
1120
1154
  return boxes.reduce(function (a, b) {
1121
- return create$9(min(a.min, b.min), max(a.max, b.max));
1155
+ return create$a(min(a.min, b.min), max(a.max, b.max));
1122
1156
  });
1123
1157
  }
1124
1158
  /* eslint-enable padding-line-between-statements */
1125
1159
 
1126
1160
  var boundingBox = /*#__PURE__*/Object.freeze({
1127
1161
  __proto__: null,
1128
- create: create$9,
1162
+ create: create$a,
1129
1163
  fromVectors: fromVectors,
1130
1164
  center: center$3,
1131
1165
  union: union
1132
1166
  });
1133
1167
 
1168
+ /**
1169
+ * Returns a `BoundingSphere` that encompasses the provided `BoundingBox`.
1170
+ */
1171
+ var create$9 = function (boundingBox$1) {
1172
+ var boundingBoxCenter = center$3(boundingBox$1);
1173
+ var centerToBoundingPlane = subtract(boundingBox$1.max, boundingBoxCenter);
1174
+ var radius = magnitude(centerToBoundingPlane);
1175
+ var length = Math.max(radius, magnitude(boundingBoxCenter));
1176
+ var epsilon = length === 0 ? 1.0 : length * 1e-6;
1177
+ return { center: boundingBoxCenter, radius: radius, epsilon: epsilon };
1178
+ };
1179
+
1180
+ var boundingSphere = /*#__PURE__*/Object.freeze({
1181
+ __proto__: null,
1182
+ create: create$9
1183
+ });
1184
+
1134
1185
  /**
1135
1186
  * Returns a new `Rectangle` with the given position and size.
1136
1187
  */
@@ -1252,13 +1303,13 @@ function center$2(rect) {
1252
1303
  * Returns the top-left position of the rectangle, as a point.
1253
1304
  */
1254
1305
  function topLeft(rect) {
1255
- return create$b(rect.x, rect.y);
1306
+ return create$c(rect.x, rect.y);
1256
1307
  }
1257
1308
  /**
1258
1309
  * Returns the bottom-right position of the rectangle, as a point.
1259
1310
  */
1260
1311
  function bottomRight(rect) {
1261
- return create$b(rect.x + rect.width, rect.y + rect.height);
1312
+ return create$c(rect.x + rect.width, rect.y + rect.height);
1262
1313
  }
1263
1314
  /**
1264
1315
  * Returns `true` if the given rectangle has a portrait aspect ratio.
@@ -1463,7 +1514,7 @@ var fitToRatio = function (ratio, dimensions) {
1463
1514
  * Converts a dimension to a rectangle, with an optional position.
1464
1515
  */
1465
1516
  function toRectangle(dimensions, position) {
1466
- if (position === void 0) { position = create$b(); }
1517
+ if (position === void 0) { position = create$c(); }
1467
1518
  return fromPointAndDimensions(position, dimensions);
1468
1519
  }
1469
1520
 
@@ -1765,7 +1816,7 @@ var translate = function (dx, dy, matrix) {
1765
1816
  var transformPoint = function (matrix, pt) {
1766
1817
  var x = matrix.a * pt.x + matrix.c * pt.y + matrix.tx;
1767
1818
  var y = matrix.b * pt.x + matrix.d * pt.y + matrix.ty;
1768
- return create$b(x, y);
1819
+ return create$c(x, y);
1769
1820
  };
1770
1821
 
1771
1822
  var matrix = /*#__PURE__*/Object.freeze({
@@ -2157,5 +2208,5 @@ var ray = /*#__PURE__*/Object.freeze({
2157
2208
  intersectPlane: intersectPlane
2158
2209
  });
2159
2210
 
2160
- export { angle as Angle, boundingBox as BoundingBox, dimensions as Dimensions, euler as Euler, line3 as Line3, matrix as Matrix, matrix2 as Matrix2, matrix4 as Matrix4, plane as Plane, point as Point, quaternion as Quaternion, ray as Ray, rectangle as Rectangle, vector3 as Vector3, clamp, lerp$2 as lerp };
2211
+ export { angle as Angle, boundingBox as BoundingBox, boundingSphere as BoundingSphere, dimensions as Dimensions, euler as Euler, line3 as Line3, matrix as Matrix, matrix2 as Matrix2, matrix4 as Matrix4, plane as Plane, point as Point, quaternion as Quaternion, ray as Ray, rectangle as Rectangle, vector3 as Vector3, clamp, lerp$2 as lerp };
2161
2212
  //# sourceMappingURL=bundle.esm.js.map