@vertexvis/geometry 0.13.2-canary.2 → 0.13.2-canary.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.
@@ -0,0 +1,14 @@
1
+ import * as BoundingBox from './boundingBox';
2
+ import * as Vector3 from './vector3';
3
+ /**
4
+ * A `BoundingSphere` describes a bounding volume as a sphere.
5
+ */
6
+ export interface BoundingSphere {
7
+ center: Vector3.Vector3;
8
+ radius: number;
9
+ epsilon: number;
10
+ }
11
+ /**
12
+ * Returns a `BoundingSphere` that encompasses the provided `BoundingBox`.
13
+ */
14
+ export declare const create: (boundingBox: BoundingBox.BoundingBox) => BoundingSphere;
@@ -33,7 +33,7 @@ function lerp$2(a, b, t) {
33
33
  /**
34
34
  * Returns a new `Point` with the given horizontal and vertical position.
35
35
  */
36
- function create$b(x, y) {
36
+ function create$c(x, y) {
37
37
  if (x === void 0) { x = 0; }
38
38
  if (y === void 0) { y = 0; }
39
39
  return { x: x, y: y };
@@ -44,7 +44,7 @@ function create$b(x, y) {
44
44
  function polar(length, radians) {
45
45
  var x = Math.cos(radians) * length;
46
46
  var y = Math.sin(radians) * length;
47
- return create$b(x, y);
47
+ return create$c(x, y);
48
48
  }
49
49
  /**
50
50
  * Returns the distance between two points.
@@ -90,7 +90,7 @@ function lerp$1(a, b, t) {
90
90
  * Returns a new `Point` where `x` and `y` are inverted.
91
91
  */
92
92
  function negate$1(pt) {
93
- return create$b(-pt.x, -pt.y);
93
+ return create$c(-pt.x, -pt.y);
94
94
  }
95
95
  /**
96
96
  * Returns a new `Point` where `x` and `y` are multiplied by the given scale
@@ -112,17 +112,17 @@ function fromJson$4(json) {
112
112
  var obj = JSON.parse(json);
113
113
  if (Array.isArray(obj)) {
114
114
  var x = obj[0], y = obj[1];
115
- return create$b(x, y);
115
+ return create$c(x, y);
116
116
  }
117
117
  else {
118
118
  var x = obj.x, y = obj.y;
119
- return create$b(x, y);
119
+ return create$c(x, y);
120
120
  }
121
121
  }
122
122
 
123
123
  var point = /*#__PURE__*/Object.freeze({
124
124
  __proto__: null,
125
- create: create$b,
125
+ create: create$c,
126
126
  polar: polar,
127
127
  distance: distance$2,
128
128
  subtract: subtract$1,
@@ -447,7 +447,7 @@ function makeOrthographic(left, right, bottom, top, near, far) {
447
447
  var d = 1.0 / (far - near);
448
448
  var x = (right + left) * w;
449
449
  var y = (top + bottom) * h;
450
- var z = (far + near) / d;
450
+ var z = (far + near) * d;
451
451
  /* eslint-disable prettier/prettier */
452
452
  return [
453
453
  2 * w, 0, 0, -x,
@@ -730,7 +730,7 @@ var matrix4 = /*#__PURE__*/Object.freeze({
730
730
  isType: isType$2
731
731
  });
732
732
 
733
- function create$a() {
733
+ function create$b() {
734
734
  var _a, _b, _c, _d, _e, _f;
735
735
  var args = [];
736
736
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -794,11 +794,11 @@ function fromJson$3(json) {
794
794
  var obj = JSON.parse(json);
795
795
  if (Array.isArray(obj)) {
796
796
  var x = obj[0], y = obj[1], z = obj[2];
797
- return create$a(x, y, z);
797
+ return create$b(x, y, z);
798
798
  }
799
799
  else {
800
800
  var x = obj.x, y = obj.y, z = obj.z;
801
- return create$a(x, y, z);
801
+ return create$b(x, y, z);
802
802
  }
803
803
  }
804
804
  /**
@@ -813,7 +813,7 @@ function fromArray(nums, offset) {
813
813
  var x = nums[offset];
814
814
  var y = nums[offset + 1];
815
815
  var z = nums[offset + 2];
816
- return create$a(x, y, z);
816
+ return create$b(x, y, z);
817
817
  }
818
818
  /**
819
819
  * Converts a Vector3 to an array where the values of the vector will be
@@ -830,43 +830,43 @@ function toArray(_a) {
830
830
  * Returns a directional vector on the positive x axis, Vector3(1, 0, 0).
831
831
  */
832
832
  function right() {
833
- return create$a(1, 0, 0);
833
+ return create$b(1, 0, 0);
834
834
  }
835
835
  /**
836
836
  * Returns a directional vector on the positive y axis, Vector3(0, 1, 0).
837
837
  */
838
838
  function up() {
839
- return create$a(0, 1, 0);
839
+ return create$b(0, 1, 0);
840
840
  }
841
841
  /**
842
842
  * Returns a directional vector on the positive z axis, Vector3(0, 0, -1).
843
843
  */
844
844
  function forward() {
845
- return create$a(0, 0, -1);
845
+ return create$b(0, 0, -1);
846
846
  }
847
847
  /**
848
848
  * Returns a directional vector on the negative x axis, Vector3(-1, 0, 0).
849
849
  */
850
850
  function left() {
851
- return create$a(-1, 0, 0);
851
+ return create$b(-1, 0, 0);
852
852
  }
853
853
  /**
854
854
  * Returns a directional vector on the negative y axis, Vector3(0, -1, 0).
855
855
  */
856
856
  function down() {
857
- return create$a(0, -1, 0);
857
+ return create$b(0, -1, 0);
858
858
  }
859
859
  /**
860
860
  * Returns a directional vector on the negative z axis, Vector3(0, 0, 1).
861
861
  */
862
862
  function back() {
863
- return create$a(0, 0, 1);
863
+ return create$b(0, 0, 1);
864
864
  }
865
865
  /**
866
866
  * Returns a vector at the origin, Vector3(0, 0, 0).
867
867
  */
868
868
  function origin() {
869
- return create$a(0, 0, 0);
869
+ return create$b(0, 0, 0);
870
870
  }
871
871
  /**
872
872
  * Returns a vector with that will have a magnitude of 1.
@@ -1049,13 +1049,13 @@ function isEqual$2(a, b) {
1049
1049
  * Returns a vector that contains the largest components of `a` and `b`.
1050
1050
  */
1051
1051
  function max(a, b) {
1052
- return create$a(Math.max(a.x, b.x), Math.max(a.y, b.y), Math.max(a.z, b.z));
1052
+ return create$b(Math.max(a.x, b.x), Math.max(a.y, b.y), Math.max(a.z, b.z));
1053
1053
  }
1054
1054
  /**
1055
1055
  * Returns a vector that contains the smallest components of `a` and `b`.
1056
1056
  */
1057
1057
  function min(a, b) {
1058
- return create$a(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.min(a.z, b.z));
1058
+ return create$b(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.min(a.z, b.z));
1059
1059
  }
1060
1060
  /**
1061
1061
  * Returns a vector that each of its component negated.
@@ -1093,7 +1093,7 @@ function transformNdcToWorldSpace(ndc, worldMatrix, projectionMatrixInverse) {
1093
1093
 
1094
1094
  var vector3 = /*#__PURE__*/Object.freeze({
1095
1095
  __proto__: null,
1096
- create: create$a,
1096
+ create: create$b,
1097
1097
  isValid: isValid,
1098
1098
  fromMatrixScale: fromMatrixScale,
1099
1099
  fromMatrixPosition: fromMatrixPosition,
@@ -1133,7 +1133,7 @@ var vector3 = /*#__PURE__*/Object.freeze({
1133
1133
  /**
1134
1134
  * Returns a `BoundingBox` with the given min and max points.
1135
1135
  */
1136
- var create$9 = function (min, max) {
1136
+ var create$a = function (min, max) {
1137
1137
  return { min: min, max: max };
1138
1138
  };
1139
1139
  /**
@@ -1141,7 +1141,7 @@ var create$9 = function (min, max) {
1141
1141
  * are contained by the bounding box.
1142
1142
  */
1143
1143
  var fromVectors = function (vectors) {
1144
- return union.apply(void 0, vectors.map(function (v) { return create$9(v, v); }));
1144
+ return union.apply(void 0, vectors.map(function (v) { return create$a(v, v); }));
1145
1145
  };
1146
1146
  /**
1147
1147
  * Returns the center point of the given `BoundingBox`.
@@ -1156,19 +1156,36 @@ function union(box) {
1156
1156
  }
1157
1157
  var boxes = tslib.__spreadArray([box], rest, true);
1158
1158
  return boxes.reduce(function (a, b) {
1159
- return create$9(min(a.min, b.min), max(a.max, b.max));
1159
+ return create$a(min(a.min, b.min), max(a.max, b.max));
1160
1160
  });
1161
1161
  }
1162
1162
  /* eslint-enable padding-line-between-statements */
1163
1163
 
1164
1164
  var boundingBox = /*#__PURE__*/Object.freeze({
1165
1165
  __proto__: null,
1166
- create: create$9,
1166
+ create: create$a,
1167
1167
  fromVectors: fromVectors,
1168
1168
  center: center$3,
1169
1169
  union: union
1170
1170
  });
1171
1171
 
1172
+ /**
1173
+ * Returns a `BoundingSphere` that encompasses the provided `BoundingBox`.
1174
+ */
1175
+ var create$9 = function (boundingBox$1) {
1176
+ var boundingBoxCenter = center$3(boundingBox$1);
1177
+ var centerToBoundingPlane = subtract(boundingBox$1.max, boundingBoxCenter);
1178
+ var radius = magnitude(centerToBoundingPlane);
1179
+ var length = Math.max(radius, magnitude(boundingBoxCenter));
1180
+ var epsilon = length === 0 ? 1.0 : length * 1e-6;
1181
+ return { center: boundingBoxCenter, radius: radius, epsilon: epsilon };
1182
+ };
1183
+
1184
+ var boundingSphere = /*#__PURE__*/Object.freeze({
1185
+ __proto__: null,
1186
+ create: create$9
1187
+ });
1188
+
1172
1189
  /**
1173
1190
  * Returns a new `Rectangle` with the given position and size.
1174
1191
  */
@@ -1290,13 +1307,13 @@ function center$2(rect) {
1290
1307
  * Returns the top-left position of the rectangle, as a point.
1291
1308
  */
1292
1309
  function topLeft(rect) {
1293
- return create$b(rect.x, rect.y);
1310
+ return create$c(rect.x, rect.y);
1294
1311
  }
1295
1312
  /**
1296
1313
  * Returns the bottom-right position of the rectangle, as a point.
1297
1314
  */
1298
1315
  function bottomRight(rect) {
1299
- return create$b(rect.x + rect.width, rect.y + rect.height);
1316
+ return create$c(rect.x + rect.width, rect.y + rect.height);
1300
1317
  }
1301
1318
  /**
1302
1319
  * Returns `true` if the given rectangle has a portrait aspect ratio.
@@ -1501,7 +1518,7 @@ var fitToRatio = function (ratio, dimensions) {
1501
1518
  * Converts a dimension to a rectangle, with an optional position.
1502
1519
  */
1503
1520
  function toRectangle(dimensions, position) {
1504
- if (position === void 0) { position = create$b(); }
1521
+ if (position === void 0) { position = create$c(); }
1505
1522
  return fromPointAndDimensions(position, dimensions);
1506
1523
  }
1507
1524
 
@@ -1803,7 +1820,7 @@ var translate = function (dx, dy, matrix) {
1803
1820
  var transformPoint = function (matrix, pt) {
1804
1821
  var x = matrix.a * pt.x + matrix.c * pt.y + matrix.tx;
1805
1822
  var y = matrix.b * pt.x + matrix.d * pt.y + matrix.ty;
1806
- return create$b(x, y);
1823
+ return create$c(x, y);
1807
1824
  };
1808
1825
 
1809
1826
  var matrix = /*#__PURE__*/Object.freeze({
@@ -2197,6 +2214,7 @@ var ray = /*#__PURE__*/Object.freeze({
2197
2214
 
2198
2215
  exports.Angle = angle;
2199
2216
  exports.BoundingBox = boundingBox;
2217
+ exports.BoundingSphere = boundingSphere;
2200
2218
  exports.Dimensions = dimensions;
2201
2219
  exports.Euler = euler;
2202
2220
  exports.Line3 = line3;