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