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
import { Cartesian2 } from "../../Source/Cesium.js";
import { Color } from "../../Source/Cesium.js";
import { JulianDate } from "../../Source/Cesium.js";
import { TimeInterval } from "../../Source/Cesium.js";
import { CheckerboardMaterialProperty } from "../../Source/Cesium.js";
import { ConstantProperty } from "../../Source/Cesium.js";
import { TimeIntervalCollectionProperty } from "../../Source/Cesium.js";
import testDefinitionChanged from "../testDefinitionChanged.js";
 
describe("DataSources/CheckerboardMaterialProperty", function () {
  it("constructor provides the expected defaults", function () {
    var property = new CheckerboardMaterialProperty();
    expect(property.getType()).toEqual("Checkerboard");
    expect(property.isConstant).toBe(true);
    expect(property.evenColor).toBeUndefined();
    expect(property.oddColor).toBeUndefined();
    expect(property.repeat).toBeUndefined();
 
    var result = property.getValue();
    expect(result.lightColor).toEqual(Color.WHITE);
    expect(result.darkColor).toEqual(Color.BLACK);
    expect(result.repeat).toEqual(new Cartesian2(2.0, 2.0));
  });
 
  it("constructor sets options and allows raw assignment", function () {
    var options = {
      evenColor: Color.RED,
      oddColor: Color.BLUE,
      repeat: new Cartesian2(1, 2),
    };
 
    var property = new CheckerboardMaterialProperty(options);
    expect(property.evenColor).toBeInstanceOf(ConstantProperty);
    expect(property.oddColor).toBeInstanceOf(ConstantProperty);
    expect(property.repeat).toBeInstanceOf(ConstantProperty);
 
    expect(property.evenColor.getValue()).toEqual(options.evenColor);
    expect(property.oddColor.getValue()).toEqual(options.oddColor);
    expect(property.repeat.getValue()).toEqual(options.repeat);
  });
 
  it("works with constant values", function () {
    var property = new CheckerboardMaterialProperty();
    property.evenColor = new ConstantProperty(Color.RED);
    property.oddColor = new ConstantProperty(Color.BLUE);
    property.repeat = new ConstantProperty(new Cartesian2(5, 5));
 
    var result = property.getValue(JulianDate.now());
    expect(result.lightColor).toEqual(Color.RED);
    expect(result.darkColor).toEqual(Color.BLUE);
    expect(result.repeat).toEqual(new Cartesian2(5, 5));
  });
 
  it("works with dynamic values", function () {
    var property = new CheckerboardMaterialProperty();
    property.evenColor = new TimeIntervalCollectionProperty();
    property.oddColor = new TimeIntervalCollectionProperty();
    property.repeat = new TimeIntervalCollectionProperty();
 
    var start = new JulianDate(1, 0);
    var stop = new JulianDate(2, 0);
    property.evenColor.intervals.addInterval(
      new TimeInterval({
        start: start,
        stop: stop,
        data: Color.RED,
      })
    );
    property.oddColor.intervals.addInterval(
      new TimeInterval({
        start: start,
        stop: stop,
        data: Color.BLUE,
      })
    );
    property.repeat.intervals.addInterval(
      new TimeInterval({
        start: start,
        stop: stop,
        data: new Cartesian2(5, 5),
      })
    );
 
    expect(property.isConstant).toBe(false);
 
    var result = property.getValue(start);
    expect(result.lightColor).toEqual(Color.RED);
    expect(result.darkColor).toEqual(Color.BLUE);
    expect(result.repeat).toEqual(new Cartesian2(5, 5));
  });
 
  it("works with a result parameter", function () {
    var property = new CheckerboardMaterialProperty();
    property.evenColor = new ConstantProperty(Color.RED);
    property.oddColor = new ConstantProperty(Color.BLUE);
    property.repeat = new ConstantProperty(new Cartesian2(5, 5));
 
    var result = {
      lightColor: Color.YELLOW.clone(),
      darkColor: Color.YELLOW.clone(),
      repeat: new Cartesian2(1, 1),
    };
    var returnedResult = property.getValue(JulianDate.now(), result);
    expect(returnedResult).toBe(result);
    expect(result.lightColor).toEqual(Color.RED);
    expect(result.darkColor).toEqual(Color.BLUE);
    expect(result.repeat).toEqual(new Cartesian2(5, 5));
  });
 
  it("equals works", function () {
    var left = new CheckerboardMaterialProperty();
    left.evenColor = new ConstantProperty(Color.RED);
    left.oddColor = new ConstantProperty(Color.BLUE);
    left.repeat = new ConstantProperty(new Cartesian2(5, 5));
 
    var right = new CheckerboardMaterialProperty();
    right.evenColor = new ConstantProperty(Color.RED);
    right.oddColor = new ConstantProperty(Color.BLUE);
    right.repeat = new ConstantProperty(new Cartesian2(5, 5));
 
    expect(left.equals(right)).toEqual(true);
 
    right.evenColor = new ConstantProperty(Color.BLACK);
    expect(left.equals(right)).toEqual(false);
 
    right.evenColor = new ConstantProperty(Color.RED);
    right.oddColor = new ConstantProperty(Color.BLACK);
    expect(left.equals(right)).toEqual(false);
 
    right.oddColor = new ConstantProperty(Color.BLUE);
    right.repeat = new ConstantProperty(new Cartesian2(5, 6));
    expect(left.equals(right)).toEqual(false);
 
    right.repeat = new ConstantProperty(new Cartesian2(5, 5));
    expect(left.equals(right)).toEqual(true);
  });
 
  it("raises definitionChanged when a property is assigned or modified", function () {
    var property = new CheckerboardMaterialProperty();
    testDefinitionChanged(property, "evenColor", Color.RED, Color.BLUE);
    testDefinitionChanged(property, "oddColor", Color.RED, Color.BLUE);
    testDefinitionChanged(
      property,
      "repeat",
      new Cartesian2(5, 5),
      new Cartesian2(7, 7)
    );
  });
});