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
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
import { Cartesian3 } from "../../Source/Cesium.js";
import { JulianDate } from "../../Source/Cesium.js";
import { ReferenceFrame } from "../../Source/Cesium.js";
import { ConstantPositionProperty } from "../../Source/Cesium.js";
import { PositionProperty } from "../../Source/Cesium.js";
 
describe("DataSources/ConstantPositionProperty", function () {
  var time = JulianDate.now();
 
  it("Constructor sets expected defaults", function () {
    var property = new ConstantPositionProperty();
    expect(property.referenceFrame).toBe(ReferenceFrame.FIXED);
 
    property = new ConstantPositionProperty(
      new Cartesian3(1, 2, 3),
      ReferenceFrame.INERTIAL
    );
    expect(property.referenceFrame).toBe(ReferenceFrame.INERTIAL);
  });
 
  it("getValue works without a result parameter", function () {
    var value = new Cartesian3(1, 2, 3);
    var property = new ConstantPositionProperty(value);
 
    var result = property.getValue(time);
    expect(result).not.toBe(value);
    expect(result).toEqual(value);
  });
 
  it("getValue works with a result parameter", function () {
    var value = new Cartesian3(1, 2, 3);
    var property = new ConstantPositionProperty(value);
 
    var expected = new Cartesian3();
    var result = property.getValue(time, expected);
    expect(result).toBe(expected);
    expect(expected).toEqual(value);
  });
 
  it("getValue returns in fixed frame", function () {
    var valueInertial = new Cartesian3(1, 2, 3);
    var valueFixed = PositionProperty.convertToReferenceFrame(
      time,
      valueInertial,
      ReferenceFrame.INERTIAL,
      ReferenceFrame.FIXED
    );
    var property = new ConstantPositionProperty(
      valueInertial,
      ReferenceFrame.INERTIAL
    );
 
    var result = property.getValue(time);
    expect(result).toEqual(valueFixed);
  });
 
  it("getValue works with undefined fixed value", function () {
    var property = new ConstantPositionProperty(undefined);
    expect(property.getValue(time)).toBeUndefined();
  });
 
  it("getValue work swith undefined inertial value", function () {
    var property = new ConstantPositionProperty(
      undefined,
      ReferenceFrame.INERTIAL
    );
    expect(property.getValue(time)).toBeUndefined();
  });
 
  it("getValueInReferenceFrame works without a result parameter", function () {
    var value = new Cartesian3(1, 2, 3);
    var property = new ConstantPositionProperty(value);
 
    var result = property.getValueInReferenceFrame(
      time,
      ReferenceFrame.INERTIAL
    );
    expect(result).not.toBe(value);
    expect(result).toEqual(
      PositionProperty.convertToReferenceFrame(
        time,
        value,
        ReferenceFrame.FIXED,
        ReferenceFrame.INERTIAL
      )
    );
  });
 
  it("getValueInReferenceFrame works with a result parameter", function () {
    var value = new Cartesian3(1, 2, 3);
    var property = new ConstantPositionProperty(value, ReferenceFrame.INERTIAL);
 
    var expected = new Cartesian3();
    var result = property.getValueInReferenceFrame(
      time,
      ReferenceFrame.FIXED,
      expected
    );
    expect(result).toBe(expected);
    expect(expected).toEqual(
      PositionProperty.convertToReferenceFrame(
        time,
        value,
        ReferenceFrame.INERTIAL,
        ReferenceFrame.FIXED
      )
    );
  });
 
  it("setValue raises definitionChanged event", function () {
    var property = new ConstantPositionProperty();
    var listener = jasmine.createSpy("listener");
    property.definitionChanged.addEventListener(listener);
    property.setValue(new Cartesian3(1, 2, 3));
    expect(listener).toHaveBeenCalledWith(property);
  });
 
  it("setValue does not raise definitionChanged event with equal data", function () {
    var property = new ConstantPositionProperty(new Cartesian3(0, 0, 0));
    var listener = jasmine.createSpy("listener");
    property.definitionChanged.addEventListener(listener);
    property.setValue(new Cartesian3(0, 0, 0));
    expect(listener.calls.count()).toBe(0);
  });
 
  it("setValue raises definitionChanged when referenceFrame changes", function () {
    var property = new ConstantPositionProperty(
      new Cartesian3(0, 0, 0),
      ReferenceFrame.FIXED
    );
    var listener = jasmine.createSpy("listener");
    property.definitionChanged.addEventListener(listener);
    property.setValue(new Cartesian3(0, 0, 0), ReferenceFrame.INERTIAL);
    expect(listener).toHaveBeenCalledWith(property);
  });
 
  it("equals works", function () {
    var left = new ConstantPositionProperty(
      new Cartesian3(1, 2, 3),
      ReferenceFrame.INERTIAL
    );
    var right = new ConstantPositionProperty(
      new Cartesian3(1, 2, 3),
      ReferenceFrame.INERTIAL
    );
 
    expect(left.equals(right)).toEqual(true);
 
    right = new ConstantPositionProperty(
      new Cartesian3(1, 2, 3),
      ReferenceFrame.FIXED
    );
    expect(left.equals(right)).toEqual(false);
 
    right = new ConstantPositionProperty(
      new Cartesian3(1, 2, 4),
      ReferenceFrame.INERTIAL
    );
    expect(left.equals(right)).toEqual(false);
  });
 
  it("getValue throws without time parameter", function () {
    var property = new ConstantPositionProperty(new Cartesian3(1, 2, 3));
    expect(function () {
      property.getValue(undefined);
    }).toThrowDeveloperError();
  });
 
  it("getValueInReferenceFrame throws with no referenceFrame parameter", function () {
    var property = new ConstantPositionProperty(new Cartesian3(1, 2, 3));
    expect(function () {
      property.getValueInReferenceFrame(time, undefined);
    }).toThrowDeveloperError();
  });
});