yzt
2023-05-05 4c558c77a6a9d23f057f094c4dc3e315eabef497
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
import { Cartesian3 } from "../../Source/Cesium.js";
import { EncodedCartesian3 } from "../../Source/Cesium.js";
 
describe("Core/EncodedCartesian3", function () {
  it("construct with default values", function () {
    var encoded = new EncodedCartesian3();
    expect(encoded.high).toEqual(Cartesian3.ZERO);
    expect(encoded.low).toEqual(Cartesian3.ZERO);
  });
 
  it("endcode encodes a positive value", function () {
    var encoded = EncodedCartesian3.encode(-10000000.0);
    expect(encoded.high + encoded.low).toEqual(-10000000.0);
  });
 
  it("endcode encodes a negative value", function () {
    var encoded = EncodedCartesian3.encode(10000000.0);
    expect(encoded.high + encoded.low).toEqual(10000000.0);
  });
 
  it("endcode encodes with a result parameter", function () {
    var result = {
      high: 0.0,
      low: 0.0,
    };
    var returnedResult = EncodedCartesian3.encode(0.0, result);
    expect(result).toBe(returnedResult);
    expect(returnedResult.high + returnedResult.low).toEqual(0.0);
  });
 
  it("fromCartesian encodes a cartesian", function () {
    var c = new Cartesian3(-10000000.0, 0.0, 10000000.0);
    var encoded = EncodedCartesian3.fromCartesian(c);
 
    // Look mom, no epsilon check.
    expect(encoded.high.x + encoded.low.x).toEqual(-10000000.0);
    expect(encoded.high.y + encoded.low.y).toEqual(0.0);
    expect(encoded.high.z + encoded.low.z).toEqual(10000000.0);
  });
 
  it("fromCartesian encodes a cartesian with a result parameter", function () {
    var p = new Cartesian3(-10000000.0, 0.0, 10000000.0);
    var encoded = EncodedCartesian3.fromCartesian(p);
 
    var positions = new Float32Array(6);
    EncodedCartesian3.writeElements(p, positions, 0);
 
    expect(encoded.high.x).toEqual(positions[0]);
    expect(encoded.high.y).toEqual(positions[1]);
    expect(encoded.high.z).toEqual(positions[2]);
    expect(encoded.low.x).toEqual(positions[3]);
    expect(encoded.low.y).toEqual(positions[4]);
    expect(encoded.low.z).toEqual(positions[5]);
  });
 
  it("writeElements encodes a cartesian", function () {
    var c = new Cartesian3(-10000000.0, 0.0, 10000000.0);
    var encoded = new EncodedCartesian3();
    var encoded2 = EncodedCartesian3.fromCartesian(c, encoded);
 
    expect(encoded2).toBe(encoded);
    expect(encoded.high.x + encoded.low.x).toEqual(-10000000.0);
    expect(encoded.high.y + encoded.low.y).toEqual(0.0);
    expect(encoded.high.z + encoded.low.z).toEqual(10000000.0);
  });
 
  it("encode throws without a value", function () {
    expect(function () {
      EncodedCartesian3.encode();
    }).toThrowDeveloperError();
  });
 
  it("fromCartesian throws without a cartesian", function () {
    expect(function () {
      EncodedCartesian3.fromCartesian();
    }).toThrowDeveloperError();
  });
 
  it("writeElements throws without a cartesian", function () {
    expect(function () {
      EncodedCartesian3.writeElements();
    }).toThrowDeveloperError();
  });
 
  it("writeElements throws without a cartesianArray", function () {
    expect(function () {
      EncodedCartesian3.writeElements(new Cartesian3());
    }).toThrowDeveloperError();
  });
 
  it("writeElements throws without an index", function () {
    expect(function () {
      EncodedCartesian3.writeElements(new Cartesian3(), new Float32Array(6));
    }).toThrowDeveloperError();
  });
 
  it("writeElements throws with a negative index", function () {
    expect(function () {
      EncodedCartesian3.writeElements(
        new Cartesian3(),
        new Float32Array(6),
        -1
      );
    }).toThrowDeveloperError();
  });
});