yzt
2023-09-27 726603df43447f8cfedfeaae4267209adbd01699
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import { AxisAlignedBoundingBox } from "../../Source/Cesium.js";
import { Cartesian3 } from "../../Source/Cesium.js";
import { Intersect } from "../../Source/Cesium.js";
import { Plane } from "../../Source/Cesium.js";
 
describe("Core/AxisAlignedBoundingBox", function () {
  var positions = [
    new Cartesian3(3, -1, -3),
    new Cartesian3(2, -2, -2),
    new Cartesian3(1, -3, -1),
    new Cartesian3(0, 0, 0),
    new Cartesian3(-1, 1, 1),
    new Cartesian3(-2, 2, 2),
    new Cartesian3(-3, 3, 3),
  ];
 
  var positionsMinimum = new Cartesian3(-3, -3, -3);
  var positionsMaximum = new Cartesian3(3, 3, 3);
  var positionsCenter = new Cartesian3(0, 0, 0);
 
  it("constructor sets expected default values", function () {
    var box = new AxisAlignedBoundingBox();
    expect(box.minimum).toEqual(Cartesian3.ZERO);
    expect(box.maximum).toEqual(Cartesian3.ZERO);
    expect(box.center).toEqual(Cartesian3.ZERO);
  });
 
  it("constructor sets expected parameter values", function () {
    var minimum = new Cartesian3(1, 2, 3);
    var maximum = new Cartesian3(4, 5, 6);
    var center = new Cartesian3(2.5, 3.5, 4.5);
    var box = new AxisAlignedBoundingBox(minimum, maximum, center);
    expect(box.minimum).toEqual(minimum);
    expect(box.maximum).toEqual(maximum);
    expect(box.center).toEqual(center);
  });
 
  it("constructor computes center if not supplied", function () {
    var minimum = new Cartesian3(1, 2, 3);
    var maximum = new Cartesian3(4, 5, 6);
    var expectedCenter = new Cartesian3(2.5, 3.5, 4.5);
    var box = new AxisAlignedBoundingBox(minimum, maximum);
    expect(box.minimum).toEqual(minimum);
    expect(box.maximum).toEqual(maximum);
    expect(box.center).toEqual(expectedCenter);
  });
 
  it("fromPoints constructs empty box with undefined positions", function () {
    var box = AxisAlignedBoundingBox.fromPoints(undefined);
    expect(box.minimum).toEqual(Cartesian3.ZERO);
    expect(box.maximum).toEqual(Cartesian3.ZERO);
    expect(box.center).toEqual(Cartesian3.ZERO);
  });
 
  it("fromPoints constructs empty box with empty positions", function () {
    var box = AxisAlignedBoundingBox.fromPoints([]);
    expect(box.minimum).toEqual(Cartesian3.ZERO);
    expect(box.maximum).toEqual(Cartesian3.ZERO);
    expect(box.center).toEqual(Cartesian3.ZERO);
  });
 
  it("fromPoints computes the correct values", function () {
    var box = AxisAlignedBoundingBox.fromPoints(positions);
    expect(box.minimum).toEqual(positionsMinimum);
    expect(box.maximum).toEqual(positionsMaximum);
    expect(box.center).toEqual(positionsCenter);
  });
 
  it("clone without a result parameter", function () {
    var box = new AxisAlignedBoundingBox(Cartesian3.UNIT_Y, Cartesian3.UNIT_X);
    var result = box.clone();
    expect(box).not.toBe(result);
    expect(box).toEqual(result);
  });
 
  it("clone without a result parameter with box of offset center", function () {
    var box = new AxisAlignedBoundingBox(
      Cartesian3.UNIT_Y,
      Cartesian3.UNIT_X,
      Cartesian3.UNIT_Z
    );
    var result = box.clone();
    expect(box).not.toBe(result);
    expect(box).toEqual(result);
  });
 
  it("clone with a result parameter", function () {
    var box = new AxisAlignedBoundingBox(Cartesian3.UNIT_Y, Cartesian3.UNIT_X);
    var result = new AxisAlignedBoundingBox(Cartesian3.ZERO, Cartesian3.UNIT_Z);
    var returnedResult = box.clone(result);
    expect(result).toBe(returnedResult);
    expect(box).not.toBe(result);
    expect(box).toEqual(result);
  });
 
  it('clone works with "this" result parameter', function () {
    var box = new AxisAlignedBoundingBox(Cartesian3.UNIT_Y, Cartesian3.UNIT_X);
    var returnedResult = box.clone(box);
    expect(box).toBe(returnedResult);
    expect(box.minimum).toEqual(Cartesian3.UNIT_Y);
    expect(box.maximum).toEqual(Cartesian3.UNIT_X);
  });
 
  it("equals works in all cases", function () {
    var box = new AxisAlignedBoundingBox(
      Cartesian3.UNIT_X,
      Cartesian3.UNIT_Y,
      Cartesian3.UNIT_Z
    );
    var bogie = new Cartesian3(2, 3, 4);
    expect(
      box.equals(
        new AxisAlignedBoundingBox(
          Cartesian3.UNIT_X,
          Cartesian3.UNIT_Y,
          Cartesian3.UNIT_Z
        )
      )
    ).toEqual(true);
    expect(
      box.equals(
        new AxisAlignedBoundingBox(bogie, Cartesian3.UNIT_Y, Cartesian3.UNIT_Y)
      )
    ).toEqual(false);
    expect(
      box.equals(
        new AxisAlignedBoundingBox(Cartesian3.UNIT_X, bogie, Cartesian3.UNIT_Z)
      )
    ).toEqual(false);
    expect(
      box.equals(
        new AxisAlignedBoundingBox(Cartesian3.UNIT_X, Cartesian3.UNIT_Y, bogie)
      )
    ).toEqual(false);
    expect(box.equals(undefined)).toEqual(false);
  });
 
  it("computes the bounding box for a single position", function () {
    var box = AxisAlignedBoundingBox.fromPoints([positions[0]]);
    expect(box.minimum).toEqual(positions[0]);
    expect(box.maximum).toEqual(positions[0]);
    expect(box.center).toEqual(positions[0]);
  });
 
  it("intersectPlane works with box on the positive side of a plane", function () {
    var box = new AxisAlignedBoundingBox(
      Cartesian3.negate(Cartesian3.UNIT_X, new Cartesian3()),
      Cartesian3.ZERO
    );
    var normal = Cartesian3.negate(Cartesian3.UNIT_X, new Cartesian3());
    var position = Cartesian3.UNIT_X;
    var plane = new Plane(normal, -Cartesian3.dot(normal, position));
    expect(box.intersectPlane(plane)).toEqual(Intersect.INSIDE);
  });
 
  it("intersectPlane works with box on the negative side of a plane", function () {
    var box = new AxisAlignedBoundingBox(
      Cartesian3.negate(Cartesian3.UNIT_X, new Cartesian3()),
      Cartesian3.ZERO
    );
    var normal = Cartesian3.UNIT_X;
    var position = Cartesian3.UNIT_X;
    var plane = new Plane(normal, -Cartesian3.dot(normal, position));
    expect(box.intersectPlane(plane)).toEqual(Intersect.OUTSIDE);
  });
 
  it("intersectPlane works with box intersecting a plane", function () {
    var box = new AxisAlignedBoundingBox(
      Cartesian3.ZERO,
      Cartesian3.multiplyByScalar(Cartesian3.UNIT_X, 2.0, new Cartesian3())
    );
    var normal = Cartesian3.UNIT_X;
    var position = Cartesian3.UNIT_X;
    var plane = new Plane(normal, -Cartesian3.dot(normal, position));
    expect(box.intersectPlane(plane)).toEqual(Intersect.INTERSECTING);
  });
 
  it("clone returns undefined with no parameter", function () {
    expect(AxisAlignedBoundingBox.clone()).toBeUndefined();
  });
 
  it("intersectPlane throws without a box", function () {
    var plane = new Plane(Cartesian3.UNIT_X, 0.0);
    expect(function () {
      AxisAlignedBoundingBox.intersectPlane(undefined, plane);
    }).toThrowDeveloperError();
  });
 
  it("intersectPlane throws without a plane", function () {
    var box = new AxisAlignedBoundingBox();
    expect(function () {
      AxisAlignedBoundingBox.intersectPlane(box, undefined);
    }).toThrowDeveloperError();
  });
});