15832144755
2022-01-06 7b4c8991dca9cf2a809a95e239d144697d3afb56
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
import { Cartesian3 } from "../../Source/Cesium.js";
import { Color } from "../../Source/Cesium.js";
import { Intersect } from "../../Source/Cesium.js";
import { Math as CesiumMath } from "../../Source/Cesium.js";
import { Plane } from "../../Source/Cesium.js";
import { TileBoundingSphere } from "../../Source/Cesium.js";
import createFrameState from "../createFrameState.js";
 
describe("Scene/TileBoundingSphere", function () {
  var tileBoundingSphere = new TileBoundingSphere(
    new Cartesian3(0.0, 0.0, 0.0),
    1.0
  );
  var frameState = createFrameState();
 
  it("can be instantiated with center and radius", function () {
    var center = new Cartesian3(0.0, 0.0, 0.0);
    var radius = 1.0;
    var tbs = new TileBoundingSphere(center, radius);
    expect(tbs).toBeDefined();
    expect(tbs.boundingVolume).toBeDefined();
    expect(tbs.boundingSphere).toBeDefined();
    expect(tbs.center).toEqual(center);
    expect(tbs.radius).toEqual(radius);
  });
 
  it("createDebugVolume throws when color is undefined", function () {
    expect(function () {
      return tileBoundingSphere.createDebugVolume();
    }).toThrowDeveloperError();
  });
 
  it("can create a debug volume", function () {
    var debugVolume = tileBoundingSphere.createDebugVolume(Color.BLUE);
    expect(debugVolume).toBeDefined();
  });
 
  it("distanceToCamera throws when frameState is undefined", function () {
    expect(function () {
      return tileBoundingSphere.distanceToCamera();
    }).toThrowDeveloperError();
  });
 
  it("distance to camera is 0 when camera is inside bounding sphere", function () {
    frameState.camera.position = new Cartesian3(0.0, 0.0, 0.0);
    expect(tileBoundingSphere.distanceToCamera(frameState)).toEqual(0.0);
  });
 
  it("distance to camera is correct when camera is outside bounding region", function () {
    frameState.camera.position = new Cartesian3(0.0, 2.0, 0.0);
    expect(tileBoundingSphere.distanceToCamera(frameState)).toEqual(1.0);
  });
 
  it("intersectPlane throws when plane is undefined", function () {
    expect(function () {
      return tileBoundingSphere.intersectPlane();
    }).toThrowDeveloperError();
  });
 
  it("intersects plane", function () {
    var normal = new Cartesian3(0.0, 0.0, 1.0);
    var plane = new Plane(normal, CesiumMath.EPSILON6);
    expect(tileBoundingSphere.intersectPlane(plane)).toEqual(
      Intersect.INTERSECTING
    );
  });
});