@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.
- package/dist/boundingSphere.d.ts +14 -0
- package/dist/bundle.cjs.js +80 -28
- package/dist/bundle.cjs.js.map +1 -1
- package/dist/bundle.esm.js +80 -29
- package/dist/bundle.esm.js.map +1 -1
- package/dist/cdn/__tests__/boundingSphere.test.d.ts +1 -0
- package/dist/cdn/boundingSphere.d.ts +14 -0
- package/dist/cdn/bundle.esm.js +80 -29
- package/dist/cdn/bundle.esm.js.map +1 -1
- package/dist/cdn/bundle.esm.min.js +1 -1
- package/dist/cdn/bundle.esm.min.js.map +1 -1
- package/dist/cdn/index.d.ts +2 -1
- package/dist/cdn/matrix4.d.ts +18 -0
- package/dist/index.d.ts +2 -1
- package/dist/matrix4.d.ts +18 -0
- package/package.json +3 -3
|
@@ -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;
|
package/dist/bundle.cjs.js
CHANGED
|
@@ -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$
|
|
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$
|
|
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$
|
|
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$
|
|
115
|
+
return create$c(x, y);
|
|
116
116
|
}
|
|
117
117
|
else {
|
|
118
118
|
var x = obj.x, y = obj.y;
|
|
119
|
-
return create$
|
|
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$
|
|
125
|
+
create: create$c,
|
|
126
126
|
polar: polar,
|
|
127
127
|
distance: distance$2,
|
|
128
128
|
subtract: subtract$1,
|
|
@@ -424,6 +424,39 @@ function makePerspective(near, far, fovY, aspect) {
|
|
|
424
424
|
var bottom = -ymax;
|
|
425
425
|
return makeFrustum(left, right, top, bottom, near, far);
|
|
426
426
|
}
|
|
427
|
+
/**
|
|
428
|
+
* Creates an orthographic projection matrix.
|
|
429
|
+
*
|
|
430
|
+
* Related to: gluOrtho. The viewing volume is cube-shaped and defined by
|
|
431
|
+
* the six parameters. The left and right values represent the coordinates of
|
|
432
|
+
* the vertical clipping planes, top and bottom values represent the coordinates
|
|
433
|
+
* of the horizontal clipping planes, and near and far values represent the
|
|
434
|
+
* coordinates of the depth clipping planes.
|
|
435
|
+
*
|
|
436
|
+
* @param left The coordinate of the left horizontal clipping plane.
|
|
437
|
+
* @param right The coordinate of the right horizontal clipping plane.
|
|
438
|
+
* @param bottom The coordinate of the bottom vertical clipping plane.
|
|
439
|
+
* @param top The coordinate of the top vertical clipping plane.
|
|
440
|
+
* @param near The coordinate of the near depth clipping plane.
|
|
441
|
+
* @param far The coordinate of the far depth clipping plane.
|
|
442
|
+
* @returns A matrix.
|
|
443
|
+
*/
|
|
444
|
+
function makeOrthographic(left, right, bottom, top, near, far) {
|
|
445
|
+
var w = 1.0 / (right - left);
|
|
446
|
+
var h = 1.0 / (top - bottom);
|
|
447
|
+
var d = 1.0 / (far - near);
|
|
448
|
+
var x = (right + left) * w;
|
|
449
|
+
var y = (top + bottom) * h;
|
|
450
|
+
var z = (far + near) * d;
|
|
451
|
+
/* eslint-disable prettier/prettier */
|
|
452
|
+
return [
|
|
453
|
+
2 * w, 0, 0, -x,
|
|
454
|
+
0, 2 * h, 0, -y,
|
|
455
|
+
0, 0, -2 * d, -z,
|
|
456
|
+
0, 0, 0, 1
|
|
457
|
+
];
|
|
458
|
+
/* eslint-enable prettier/prettier */
|
|
459
|
+
}
|
|
427
460
|
/**
|
|
428
461
|
* Matrix becomes a combination of an inverse translation and rotation.
|
|
429
462
|
*
|
|
@@ -684,6 +717,7 @@ var matrix4 = /*#__PURE__*/Object.freeze({
|
|
|
684
717
|
makeRotationAxis: makeRotationAxis,
|
|
685
718
|
makeFrustum: makeFrustum,
|
|
686
719
|
makePerspective: makePerspective,
|
|
720
|
+
makeOrthographic: makeOrthographic,
|
|
687
721
|
makeLookAtView: makeLookAtView,
|
|
688
722
|
makeLookAt: makeLookAt,
|
|
689
723
|
invert: invert,
|
|
@@ -696,7 +730,7 @@ var matrix4 = /*#__PURE__*/Object.freeze({
|
|
|
696
730
|
isType: isType$2
|
|
697
731
|
});
|
|
698
732
|
|
|
699
|
-
function create$
|
|
733
|
+
function create$b() {
|
|
700
734
|
var _a, _b, _c, _d, _e, _f;
|
|
701
735
|
var args = [];
|
|
702
736
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -760,11 +794,11 @@ function fromJson$3(json) {
|
|
|
760
794
|
var obj = JSON.parse(json);
|
|
761
795
|
if (Array.isArray(obj)) {
|
|
762
796
|
var x = obj[0], y = obj[1], z = obj[2];
|
|
763
|
-
return create$
|
|
797
|
+
return create$b(x, y, z);
|
|
764
798
|
}
|
|
765
799
|
else {
|
|
766
800
|
var x = obj.x, y = obj.y, z = obj.z;
|
|
767
|
-
return create$
|
|
801
|
+
return create$b(x, y, z);
|
|
768
802
|
}
|
|
769
803
|
}
|
|
770
804
|
/**
|
|
@@ -779,7 +813,7 @@ function fromArray(nums, offset) {
|
|
|
779
813
|
var x = nums[offset];
|
|
780
814
|
var y = nums[offset + 1];
|
|
781
815
|
var z = nums[offset + 2];
|
|
782
|
-
return create$
|
|
816
|
+
return create$b(x, y, z);
|
|
783
817
|
}
|
|
784
818
|
/**
|
|
785
819
|
* Converts a Vector3 to an array where the values of the vector will be
|
|
@@ -796,43 +830,43 @@ function toArray(_a) {
|
|
|
796
830
|
* Returns a directional vector on the positive x axis, Vector3(1, 0, 0).
|
|
797
831
|
*/
|
|
798
832
|
function right() {
|
|
799
|
-
return create$
|
|
833
|
+
return create$b(1, 0, 0);
|
|
800
834
|
}
|
|
801
835
|
/**
|
|
802
836
|
* Returns a directional vector on the positive y axis, Vector3(0, 1, 0).
|
|
803
837
|
*/
|
|
804
838
|
function up() {
|
|
805
|
-
return create$
|
|
839
|
+
return create$b(0, 1, 0);
|
|
806
840
|
}
|
|
807
841
|
/**
|
|
808
842
|
* Returns a directional vector on the positive z axis, Vector3(0, 0, -1).
|
|
809
843
|
*/
|
|
810
844
|
function forward() {
|
|
811
|
-
return create$
|
|
845
|
+
return create$b(0, 0, -1);
|
|
812
846
|
}
|
|
813
847
|
/**
|
|
814
848
|
* Returns a directional vector on the negative x axis, Vector3(-1, 0, 0).
|
|
815
849
|
*/
|
|
816
850
|
function left() {
|
|
817
|
-
return create$
|
|
851
|
+
return create$b(-1, 0, 0);
|
|
818
852
|
}
|
|
819
853
|
/**
|
|
820
854
|
* Returns a directional vector on the negative y axis, Vector3(0, -1, 0).
|
|
821
855
|
*/
|
|
822
856
|
function down() {
|
|
823
|
-
return create$
|
|
857
|
+
return create$b(0, -1, 0);
|
|
824
858
|
}
|
|
825
859
|
/**
|
|
826
860
|
* Returns a directional vector on the negative z axis, Vector3(0, 0, 1).
|
|
827
861
|
*/
|
|
828
862
|
function back() {
|
|
829
|
-
return create$
|
|
863
|
+
return create$b(0, 0, 1);
|
|
830
864
|
}
|
|
831
865
|
/**
|
|
832
866
|
* Returns a vector at the origin, Vector3(0, 0, 0).
|
|
833
867
|
*/
|
|
834
868
|
function origin() {
|
|
835
|
-
return create$
|
|
869
|
+
return create$b(0, 0, 0);
|
|
836
870
|
}
|
|
837
871
|
/**
|
|
838
872
|
* Returns a vector with that will have a magnitude of 1.
|
|
@@ -1015,13 +1049,13 @@ function isEqual$2(a, b) {
|
|
|
1015
1049
|
* Returns a vector that contains the largest components of `a` and `b`.
|
|
1016
1050
|
*/
|
|
1017
1051
|
function max(a, b) {
|
|
1018
|
-
return create$
|
|
1052
|
+
return create$b(Math.max(a.x, b.x), Math.max(a.y, b.y), Math.max(a.z, b.z));
|
|
1019
1053
|
}
|
|
1020
1054
|
/**
|
|
1021
1055
|
* Returns a vector that contains the smallest components of `a` and `b`.
|
|
1022
1056
|
*/
|
|
1023
1057
|
function min(a, b) {
|
|
1024
|
-
return create$
|
|
1058
|
+
return create$b(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.min(a.z, b.z));
|
|
1025
1059
|
}
|
|
1026
1060
|
/**
|
|
1027
1061
|
* Returns a vector that each of its component negated.
|
|
@@ -1059,7 +1093,7 @@ function transformNdcToWorldSpace(ndc, worldMatrix, projectionMatrixInverse) {
|
|
|
1059
1093
|
|
|
1060
1094
|
var vector3 = /*#__PURE__*/Object.freeze({
|
|
1061
1095
|
__proto__: null,
|
|
1062
|
-
create: create$
|
|
1096
|
+
create: create$b,
|
|
1063
1097
|
isValid: isValid,
|
|
1064
1098
|
fromMatrixScale: fromMatrixScale,
|
|
1065
1099
|
fromMatrixPosition: fromMatrixPosition,
|
|
@@ -1099,7 +1133,7 @@ var vector3 = /*#__PURE__*/Object.freeze({
|
|
|
1099
1133
|
/**
|
|
1100
1134
|
* Returns a `BoundingBox` with the given min and max points.
|
|
1101
1135
|
*/
|
|
1102
|
-
var create$
|
|
1136
|
+
var create$a = function (min, max) {
|
|
1103
1137
|
return { min: min, max: max };
|
|
1104
1138
|
};
|
|
1105
1139
|
/**
|
|
@@ -1107,7 +1141,7 @@ var create$9 = function (min, max) {
|
|
|
1107
1141
|
* are contained by the bounding box.
|
|
1108
1142
|
*/
|
|
1109
1143
|
var fromVectors = function (vectors) {
|
|
1110
|
-
return union.apply(void 0, vectors.map(function (v) { return create$
|
|
1144
|
+
return union.apply(void 0, vectors.map(function (v) { return create$a(v, v); }));
|
|
1111
1145
|
};
|
|
1112
1146
|
/**
|
|
1113
1147
|
* Returns the center point of the given `BoundingBox`.
|
|
@@ -1122,19 +1156,36 @@ function union(box) {
|
|
|
1122
1156
|
}
|
|
1123
1157
|
var boxes = tslib.__spreadArray([box], rest, true);
|
|
1124
1158
|
return boxes.reduce(function (a, b) {
|
|
1125
|
-
return create$
|
|
1159
|
+
return create$a(min(a.min, b.min), max(a.max, b.max));
|
|
1126
1160
|
});
|
|
1127
1161
|
}
|
|
1128
1162
|
/* eslint-enable padding-line-between-statements */
|
|
1129
1163
|
|
|
1130
1164
|
var boundingBox = /*#__PURE__*/Object.freeze({
|
|
1131
1165
|
__proto__: null,
|
|
1132
|
-
create: create$
|
|
1166
|
+
create: create$a,
|
|
1133
1167
|
fromVectors: fromVectors,
|
|
1134
1168
|
center: center$3,
|
|
1135
1169
|
union: union
|
|
1136
1170
|
});
|
|
1137
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
|
+
|
|
1138
1189
|
/**
|
|
1139
1190
|
* Returns a new `Rectangle` with the given position and size.
|
|
1140
1191
|
*/
|
|
@@ -1256,13 +1307,13 @@ function center$2(rect) {
|
|
|
1256
1307
|
* Returns the top-left position of the rectangle, as a point.
|
|
1257
1308
|
*/
|
|
1258
1309
|
function topLeft(rect) {
|
|
1259
|
-
return create$
|
|
1310
|
+
return create$c(rect.x, rect.y);
|
|
1260
1311
|
}
|
|
1261
1312
|
/**
|
|
1262
1313
|
* Returns the bottom-right position of the rectangle, as a point.
|
|
1263
1314
|
*/
|
|
1264
1315
|
function bottomRight(rect) {
|
|
1265
|
-
return create$
|
|
1316
|
+
return create$c(rect.x + rect.width, rect.y + rect.height);
|
|
1266
1317
|
}
|
|
1267
1318
|
/**
|
|
1268
1319
|
* Returns `true` if the given rectangle has a portrait aspect ratio.
|
|
@@ -1467,7 +1518,7 @@ var fitToRatio = function (ratio, dimensions) {
|
|
|
1467
1518
|
* Converts a dimension to a rectangle, with an optional position.
|
|
1468
1519
|
*/
|
|
1469
1520
|
function toRectangle(dimensions, position) {
|
|
1470
|
-
if (position === void 0) { position = create$
|
|
1521
|
+
if (position === void 0) { position = create$c(); }
|
|
1471
1522
|
return fromPointAndDimensions(position, dimensions);
|
|
1472
1523
|
}
|
|
1473
1524
|
|
|
@@ -1769,7 +1820,7 @@ var translate = function (dx, dy, matrix) {
|
|
|
1769
1820
|
var transformPoint = function (matrix, pt) {
|
|
1770
1821
|
var x = matrix.a * pt.x + matrix.c * pt.y + matrix.tx;
|
|
1771
1822
|
var y = matrix.b * pt.x + matrix.d * pt.y + matrix.ty;
|
|
1772
|
-
return create$
|
|
1823
|
+
return create$c(x, y);
|
|
1773
1824
|
};
|
|
1774
1825
|
|
|
1775
1826
|
var matrix = /*#__PURE__*/Object.freeze({
|
|
@@ -2163,6 +2214,7 @@ var ray = /*#__PURE__*/Object.freeze({
|
|
|
2163
2214
|
|
|
2164
2215
|
exports.Angle = angle;
|
|
2165
2216
|
exports.BoundingBox = boundingBox;
|
|
2217
|
+
exports.BoundingSphere = boundingSphere;
|
|
2166
2218
|
exports.Dimensions = dimensions;
|
|
2167
2219
|
exports.Euler = euler;
|
|
2168
2220
|
exports.Line3 = line3;
|