forked from CesiumGS/cesium
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreateGeometryUpdaterSpecs.js
403 lines (347 loc) · 18.1 KB
/
createGeometryUpdaterSpecs.js
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
import { Color } from '../Source/Cesium.js';
import { ColorGeometryInstanceAttribute } from '../Source/Cesium.js';
import { DistanceDisplayCondition } from '../Source/Cesium.js';
import { DistanceDisplayConditionGeometryInstanceAttribute } from '../Source/Cesium.js';
import { JulianDate } from '../Source/Cesium.js';
import { ShowGeometryInstanceAttribute } from '../Source/Cesium.js';
import { TimeInterval } from '../Source/Cesium.js';
import { ColorMaterialProperty } from '../Source/Cesium.js';
import { ConstantProperty } from '../Source/Cesium.js';
import { EllipsoidGeometryUpdater } from '../Source/Cesium.js';
import { Entity } from '../Source/Cesium.js';
import { GridMaterialProperty } from '../Source/Cesium.js';
import { SampledProperty } from '../Source/Cesium.js';
import { TimeIntervalCollectionProperty } from '../Source/Cesium.js';
import { ShadowMode } from '../Source/Cesium.js';
function createGeometryUpdaterSpecs(Updater, geometryPropertyName, createEntity, getScene) {
var time = JulianDate.now();
it('Constructor sets expected defaults', function() {
var entity = createEntity();
var updater = new Updater(entity, getScene());
expect(updater.isDestroyed()).toBe(false);
expect(updater.entity).toBe(entity);
expect(updater.isClosed).toBe(updater._getIsClosed(updater._options));
expect(updater.fillEnabled).toBe(true);
expect(updater.fillMaterialProperty).toBeInstanceOf(ColorMaterialProperty);
expect(updater.outlineEnabled).toBe(false);
expect(updater.hasConstantFill).toBe(true);
expect(updater.hasConstantOutline).toBe(true);
expect(updater.outlineColorProperty).toBe(undefined);
expect(updater.outlineWidth).toBe(1.0);
expect(updater.shadowsProperty.getValue()).toBe(ShadowMode.DISABLED);
expect(updater.distanceDisplayConditionProperty.getValue()).toEqual(new DistanceDisplayCondition());
expect(updater.isDynamic).toBe(false);
expect(updater.onTerrain).toBe(false);
expect(updater.isOutlineVisible(time)).toBe(false);
expect(updater.isFilled(time)).toBe(true);
updater.destroy();
expect(updater.isDestroyed()).toBe(true);
});
it('No geometry created when entity geometry property is undefined ', function() {
var entity = new Entity();
var updater = new Updater(entity, getScene());
expect(updater.fillEnabled).toBe(false);
expect(updater.outlineEnabled).toBe(false);
expect(updater.isDynamic).toBe(false);
});
it('No geometry available when not filled or outline.', function() {
var entity = createEntity();
entity[geometryPropertyName].fill = new ConstantProperty(false);
entity[geometryPropertyName].outline = new ConstantProperty(false);
var updater = new Updater(entity, getScene());
expect(updater.fillEnabled).toBe(false);
expect(updater.outlineEnabled).toBe(false);
expect(updater.isDynamic).toBe(false);
});
it('Values correct when using default graphics', function() {
var entity = createEntity();
var updater = new Updater(entity, getScene());
expect(updater.isClosed).toBe(updater._getIsClosed(updater._options));
expect(updater.fillEnabled).toBe(true);
expect(updater.fillMaterialProperty).toEqual(new ColorMaterialProperty(Color.WHITE));
expect(updater.outlineEnabled).toBe(false);
expect(updater.hasConstantFill).toBe(true);
expect(updater.hasConstantOutline).toBe(true);
expect(updater.outlineColorProperty).toBe(undefined);
expect(updater.outlineWidth).toBe(1.0);
expect(updater.shadowsProperty).toEqual(new ConstantProperty(ShadowMode.DISABLED));
expect(updater.distanceDisplayConditionProperty).toEqual(new ConstantProperty(new DistanceDisplayCondition()));
expect(updater.isDynamic).toBe(false);
});
it('material is correctly exposed.', function() {
var entity = createEntity();
entity[geometryPropertyName].material = new GridMaterialProperty(Color.BLUE);
var updater = new Updater(entity, getScene());
expect(updater.fillMaterialProperty).toBe(entity[geometryPropertyName].material);
});
it('A time-varying outlineWidth causes geometry to be dynamic', function() {
var entity = createEntity();
entity[geometryPropertyName].outlineWidth = new SampledProperty(Number);
entity[geometryPropertyName].outlineWidth.addSample(time, 1);
var updater = new Updater(entity, getScene());
expect(updater.isDynamic).toBe(true);
});
it('Correctly exposes outlineWidth', function() {
var entity = createEntity();
entity[geometryPropertyName].outlineWidth = new ConstantProperty(8);
var updater = new Updater(entity, getScene());
expect(updater.outlineWidth).toBe(8);
});
it('Attributes have expected values at creation time', function() {
var time1 = new JulianDate(0, 0);
var time2 = new JulianDate(10, 0);
var time3 = new JulianDate(20, 0);
var fill = new TimeIntervalCollectionProperty();
fill.intervals.addInterval(new TimeInterval({
start : time1,
stop : time2,
data : false
}));
fill.intervals.addInterval(new TimeInterval({
start : time2,
stop : time3,
isStartIncluded : false,
data : true
}));
var colorMaterial = new ColorMaterialProperty();
colorMaterial.color = new SampledProperty(Color);
colorMaterial.color.addSample(time, Color.YELLOW);
colorMaterial.color.addSample(time2, Color.BLUE);
colorMaterial.color.addSample(time3, Color.RED);
var outline = new TimeIntervalCollectionProperty();
outline.intervals.addInterval(new TimeInterval({
start : time1,
stop : time2,
data : false
}));
outline.intervals.addInterval(new TimeInterval({
start : time2,
stop : time3,
isStartIncluded : false,
data : true
}));
var outlineColor = new SampledProperty(Color);
outlineColor.addSample(time, Color.BLUE);
outlineColor.addSample(time2, Color.RED);
outlineColor.addSample(time3, Color.YELLOW);
var entity = createEntity();
entity[geometryPropertyName].fill = fill;
entity[geometryPropertyName].material = colorMaterial;
entity[geometryPropertyName].outline = outline;
entity[geometryPropertyName].outlineColor = outlineColor;
var updater = new Updater(entity, getScene());
var instance = updater.createFillGeometryInstance(time2);
var attributes = instance.attributes;
expect(attributes.color.value).toEqual(ColorGeometryInstanceAttribute.toValue(colorMaterial.color.getValue(time2)));
expect(attributes.show.value).toEqual(ShowGeometryInstanceAttribute.toValue(fill.getValue(time2)));
instance = updater.createOutlineGeometryInstance(time2);
attributes = instance.attributes;
expect(attributes.color.value).toEqual(ColorGeometryInstanceAttribute.toValue(outlineColor.getValue(time2)));
expect(attributes.show.value).toEqual(ShowGeometryInstanceAttribute.toValue(outline.getValue(time2)));
});
it('createFillGeometryInstance obeys Entity.show is false.', function() {
var entity = createEntity();
entity.show = false;
entity[geometryPropertyName].fill = true;
var updater = new Updater(entity, getScene());
var instance = updater.createFillGeometryInstance(new JulianDate());
var attributes = instance.attributes;
expect(attributes.show.value).toEqual(ShowGeometryInstanceAttribute.toValue(false));
});
it('createOutlineGeometryInstance obeys Entity.show is false.', function() {
var entity = createEntity();
entity.show = false;
entity[geometryPropertyName].outline = true;
var updater = new Updater(entity, getScene());
var instance = updater.createFillGeometryInstance(new JulianDate());
var attributes = instance.attributes;
expect(attributes.show.value).toEqual(ShowGeometryInstanceAttribute.toValue(false));
});
it('createFillGeometryInstance throws if object is not filled', function() {
if (Updater === EllipsoidGeometryUpdater) {
// ellipsoid doesn't throw developer error because it always creates both fill and outline when dynamic
return;
}
var entity = new Entity();
var updater = new Updater(entity, getScene());
expect(function() {
return updater.createFillGeometryInstance(time);
}).toThrowDeveloperError();
});
it('createFillGeometryInstance throws if no time provided', function() {
var entity = createEntity();
var updater = new Updater(entity, getScene());
expect(function() {
return updater.createFillGeometryInstance(undefined);
}).toThrowDeveloperError();
});
it('createOutlineGeometryInstance throws if object is not outlined', function() {
if (Updater === EllipsoidGeometryUpdater) {
// ellipsoid doesn't throw developer error because it always creates both fill and outline when dynamic
return;
}
var entity = new Entity();
var updater = new Updater(entity, getScene());
expect(function() {
return updater.createOutlineGeometryInstance(time);
}).toThrowDeveloperError();
});
it('createOutlineGeometryInstance throws if no time provided', function() {
var entity = createEntity();
entity[geometryPropertyName].outline = new ConstantProperty(true);
var updater = new Updater(entity, getScene());
expect(function() {
return updater.createOutlineGeometryInstance(undefined);
}).toThrowDeveloperError();
});
function validateGeometryInstanceAttributes(options) {
var entity = createEntity();
var geometryProperty = entity[geometryPropertyName];
geometryProperty.show = true;
geometryProperty.fill = true;
geometryProperty.material = options.material;
geometryProperty.outline = true;
geometryProperty.outlineColor = new ConstantProperty(options.outlineColor);
geometryProperty.distanceDisplayCondition = options.distanceDisplayCondition;
var updater = new Updater(entity, getScene());
var instance;
var attributes;
instance = updater.createFillGeometryInstance(time);
attributes = instance.attributes;
if (options.material instanceof ColorMaterialProperty) {
expect(attributes.color.value).toEqual(ColorGeometryInstanceAttribute.toValue(options.material.color.getValue(time)));
} else {
expect(attributes.color).toBeUndefined();
}
expect(attributes.show.value).toEqual(ShowGeometryInstanceAttribute.toValue(true));
if (options.distanceDisplayCondition) {
expect(attributes.distanceDisplayCondition.value).toEqual(DistanceDisplayConditionGeometryInstanceAttribute.toValue(options.distanceDisplayCondition));
}
instance = updater.createOutlineGeometryInstance(time);
attributes = instance.attributes;
expect(attributes.color.value).toEqual(ColorGeometryInstanceAttribute.toValue(options.outlineColor));
expect(attributes.show.value).toEqual(ShowGeometryInstanceAttribute.toValue(true));
if (options.distanceDisplayCondition) {
expect(attributes.distanceDisplayCondition.value).toEqual(DistanceDisplayConditionGeometryInstanceAttribute.toValue(options.distanceDisplayCondition));
}
}
it('Creates expected per-color geometry', function() {
validateGeometryInstanceAttributes({
material : new ColorMaterialProperty(Color.RED),
outlineColor : Color.BLUE
});
});
it('Creates expected per-material geometry', function() {
validateGeometryInstanceAttributes({
material : new GridMaterialProperty(),
outlineColor : Color.GREEN
});
});
it('Creates expected distance display condition geometry', function() {
validateGeometryInstanceAttributes({
material : new ColorMaterialProperty(Color.BLUE),
outlineColor : Color.RED,
distanceDisplayCondition : new DistanceDisplayCondition(10.0, 100.0)
});
});
it('Attributes have expected values at creation time', function() {
var time1 = new JulianDate(0, 0);
var time2 = new JulianDate(10, 0);
var time3 = new JulianDate(20, 0);
var fill = new TimeIntervalCollectionProperty();
fill.intervals.addInterval(new TimeInterval({
start : time1,
stop : time2,
data : false
}));
fill.intervals.addInterval(new TimeInterval({
start : time2,
stop : time3,
isStartIncluded : false,
data : true
}));
var colorMaterial = new ColorMaterialProperty();
colorMaterial.color = new SampledProperty(Color);
colorMaterial.color.addSample(time, Color.YELLOW);
colorMaterial.color.addSample(time2, Color.BLUE);
colorMaterial.color.addSample(time3, Color.RED);
var outline = new TimeIntervalCollectionProperty();
outline.intervals.addInterval(new TimeInterval({
start : time1,
stop : time2,
data : false
}));
outline.intervals.addInterval(new TimeInterval({
start : time2,
stop : time3,
isStartIncluded : false,
data : true
}));
var outlineColor = new SampledProperty(Color);
outlineColor.addSample(time, Color.BLUE);
outlineColor.addSample(time2, Color.RED);
outlineColor.addSample(time3, Color.YELLOW);
var entity = createEntity();
var geoemtry = entity[geometryPropertyName];
geoemtry.fill = fill;
geoemtry.material = colorMaterial;
geoemtry.outline = outline;
geoemtry.outlineColor = outlineColor;
var updater = new Updater(entity, getScene());
var instance = updater.createFillGeometryInstance(time2);
var attributes = instance.attributes;
expect(attributes.color.value).toEqual(ColorGeometryInstanceAttribute.toValue(colorMaterial.color.getValue(time2)));
expect(attributes.show.value).toEqual(ShowGeometryInstanceAttribute.toValue(fill.getValue(time2)));
instance = updater.createOutlineGeometryInstance(time2);
attributes = instance.attributes;
expect(attributes.color.value).toEqual(ColorGeometryInstanceAttribute.toValue(outlineColor.getValue(time2)));
expect(attributes.show.value).toEqual(ShowGeometryInstanceAttribute.toValue(outline.getValue(time2)));
});
it('Works with dynamic color with missing interval', function() {
var time1 = new JulianDate(0, 0);
var time2 = new JulianDate(10, 0);
var missingTime = new JulianDate(15, 0);
var time3 = new JulianDate(20, 0);
var time4 = new JulianDate(30, 0);
var colorMaterial = new ColorMaterialProperty();
var color = new TimeIntervalCollectionProperty();
color.intervals.addInterval(new TimeInterval({
start : time1,
stop : time2,
data : Color.BLUE
}));
color.intervals.addInterval(new TimeInterval({
start : time3,
stop : time4,
isStartIncluded : false,
data : Color.YELLOW
}));
colorMaterial.color = color;
var outlineColor = new TimeIntervalCollectionProperty();
outlineColor.intervals.addInterval(new TimeInterval({
start : time1,
stop : time2,
data : Color.RED
}));
outlineColor.intervals.addInterval(new TimeInterval({
start : time3,
stop : time4,
isStartIncluded : false,
data : Color.GREEN
}));
var entity = createEntity();
var geometry = entity[geometryPropertyName];
geometry.fill = true;
geometry.outline = true;
geometry.material = colorMaterial;
geometry.outlineColor = outlineColor;
var updater = new Updater(entity, getScene());
var instance = updater.createFillGeometryInstance(missingTime);
var attributes = instance.attributes;
expect(attributes.color.value).toEqual(ColorGeometryInstanceAttribute.toValue(Color.WHITE));
instance = updater.createOutlineGeometryInstance(missingTime);
attributes = instance.attributes;
expect(attributes.color.value).toEqual(ColorGeometryInstanceAttribute.toValue(Color.BLACK));
});
}
export default createGeometryUpdaterSpecs;