yzt
2023-05-26 2f70f6727314edd84d8ec2bfe3ce832803f1ea77
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
import { Cartesian3 } from "../../Source/Cesium.js";
import { Math as CesiumMath } from "../../Source/Cesium.js";
import { Spherical } from "../../Source/Cesium.js";
 
describe("Core/Spherical", function () {
  //Mock object to make sure methods take non-sphericals.
  function NotSpherical(clock, cone, magnitude) {
    this.clock = clock;
    this.cone = cone;
    this.magnitude = magnitude;
  }
 
  NotSpherical.areEqual = function (left, right) {
    return (
      left.clock === right.clock &&
      left.cone === right.cone &&
      left.magnitude === right.magnitude
    );
  };
 
  it("Default constructing sets properties to their expected values.", function () {
    var v = new Spherical();
    expect(v.clock).toEqual(0);
    expect(v.cone).toEqual(0);
    expect(v.magnitude).toEqual(1.0);
  });
 
  it("Construtor parameters are assigned to the appropriate properties", function () {
    var v = new Spherical(1, 2, 3);
    expect(v.clock).toEqual(1);
    expect(v.cone).toEqual(2);
    expect(v.magnitude).toEqual(3);
  });
 
  var fortyFiveDegrees = Math.PI / 4.0;
  var sixtyDegrees = Math.PI / 3.0;
  var cartesian = new Cartesian3(1.0, Math.sqrt(3.0), -2.0);
  var spherical = new Spherical(
    sixtyDegrees,
    fortyFiveDegrees + Math.PI / 2.0,
    Math.sqrt(8.0)
  );
 
  it("Can convert Cartesian3 to a new spherical instance", function () {
    expect(spherical).toEqualEpsilon(
      Spherical.fromCartesian3(cartesian),
      CesiumMath.EPSILON15
    );
  });
 
  it("Can convert Cartesian3 to an existing spherical instance", function () {
    var existing = new Spherical();
    expect(spherical).toEqualEpsilon(
      Spherical.fromCartesian3(cartesian, existing),
      CesiumMath.EPSILON15
    );
    expect(spherical).toEqualEpsilon(existing, CesiumMath.EPSILON15);
  });
 
  it("Cloning with no result parameter returns a new instance.", function () {
    var v = new Spherical(1, 2, 3);
    var clone = v.clone();
    expect(clone).not.toBe(v);
    expect(clone).toBeInstanceOf(Spherical);
    expect(clone).toEqual(v);
  });
 
  it("Cloning with result modifies existing instance and returns it.", function () {
    var v = new Spherical(1, 2, 3);
    var w = new NotSpherical();
    expect(NotSpherical.areEqual(v, w)).toEqual(false);
    var clone = v.clone(w);
    expect(clone).not.toBe(v);
    expect(clone).toBe(w);
    expect(NotSpherical.areEqual(v, w)).toEqual(true);
  });
 
  it("Normalizing with no result parameter creates new instance and sets magnitude to 1.0", function () {
    var v = new Spherical(0, 2, 3);
    var w = Spherical.normalize(v);
    expect(w).not.toEqual(v);
    expect(w.clock).toEqual(0);
    expect(w.cone).toEqual(2);
    expect(w.magnitude).toEqual(1);
  });
 
  it("Normalizing with result parameter modifies instance and sets magnitude to 1.0", function () {
    var v = new Spherical(0, 2, 3);
    var w = new NotSpherical();
    var q = Spherical.normalize(v, w);
    expect(q).not.toEqual(v);
    expect(q).toBe(w);
    expect(q.clock).toEqual(0);
    expect(q.cone).toEqual(2);
    expect(q.magnitude).toEqual(1);
  });
 
  it("Normalizing with this as result parameter modifies instance and sets magnitude to 1.0", function () {
    var v = new Spherical(0, 2, 3);
    var q = Spherical.normalize(v, v);
    expect(q).toBe(v);
    expect(q.clock).toEqual(0);
    expect(q.cone).toEqual(2);
    expect(q.magnitude).toEqual(1);
  });
 
  it("equalsEpsilon returns true for expected values.", function () {
    expect(new Spherical(1, 2, 1)).toEqualEpsilon(new NotSpherical(1, 2, 1), 0);
    expect(new Spherical(1, 2, 1)).toEqualEpsilon(new NotSpherical(1, 2, 2), 1);
  });
 
  it("equalsEpsilon returns false for expected values.", function () {
    expect(new Spherical(1, 2, 1)).not.toEqualEpsilon(
      new NotSpherical(1, 2, 3),
      1
    );
  });
 
  it("toString returns the expected format.", function () {
    var v = new Spherical(1, 2, 3);
    expect(v.toString()).toEqual("(1, 2, 3)");
  });
});