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
import { arrayFill } from "../../Source/Cesium.js";
import { CylinderGeometry } from "../../Source/Cesium.js";
import { GeometryOffsetAttribute } from "../../Source/Cesium.js";
import { VertexFormat } from "../../Source/Cesium.js";
import createPackableSpecs from "../createPackableSpecs.js";
 
describe("Core/CylinderGeometry", function () {
  it("constructor throws with no length", function () {
    expect(function () {
      return new CylinderGeometry({});
    }).toThrowDeveloperError();
  });
 
  it("constructor throws with no topRadius", function () {
    expect(function () {
      return new CylinderGeometry({
        length: 1,
      });
    }).toThrowDeveloperError();
  });
 
  it("constructor throws with no bottomRadius", function () {
    expect(function () {
      return new CylinderGeometry({
        length: 1,
        topRadius: 1,
      });
    }).toThrowDeveloperError();
  });
 
  it("constructor throws if slices is less than 3", function () {
    expect(function () {
      return new CylinderGeometry({
        length: 1,
        topRadius: 1,
        bottomRadius: 1,
        slices: 2,
      });
    }).toThrowDeveloperError();
  });
 
  it("computes positions", function () {
    var m = CylinderGeometry.createGeometry(
      new CylinderGeometry({
        vertexFormat: VertexFormat.POSITION_ONLY,
        length: 1,
        topRadius: 1,
        bottomRadius: 1,
        slices: 3,
      })
    );
 
    var numVertices = 12; // (3 top + 3 bottom) * 2 to duplicate for sides
    var numTriangles = 8; // 1 top  + 1 bottom + 2 triangles * 3 sides
    expect(m.attributes.position.values.length).toEqual(numVertices * 3);
    expect(m.indices.length).toEqual(numTriangles * 3);
  });
 
  it("computes offset attribute", function () {
    var m = CylinderGeometry.createGeometry(
      new CylinderGeometry({
        vertexFormat: VertexFormat.POSITION_ONLY,
        length: 1,
        topRadius: 1,
        bottomRadius: 1,
        slices: 3,
        offsetAttribute: GeometryOffsetAttribute.ALL,
      })
    );
 
    var numVertices = 12;
    expect(m.attributes.position.values.length).toEqual(numVertices * 3);
 
    var offset = m.attributes.applyOffset.values;
    expect(offset.length).toEqual(numVertices);
    var expected = new Array(offset.length);
    expected = arrayFill(expected, 1);
    expect(offset).toEqual(expected);
  });
 
  it("compute all vertex attributes", function () {
    var m = CylinderGeometry.createGeometry(
      new CylinderGeometry({
        vertexFormat: VertexFormat.ALL,
        length: 1,
        topRadius: 1,
        bottomRadius: 1,
        slices: 3,
      })
    );
 
    var numVertices = 12;
    var numTriangles = 8;
    expect(m.attributes.position.values.length).toEqual(numVertices * 3);
    expect(m.attributes.st.values.length).toEqual(numVertices * 2);
    expect(m.attributes.normal.values.length).toEqual(numVertices * 3);
    expect(m.attributes.tangent.values.length).toEqual(numVertices * 3);
    expect(m.attributes.bitangent.values.length).toEqual(numVertices * 3);
    expect(m.indices.length).toEqual(numTriangles * 3);
  });
 
  it("computes positions with topRadius equals 0", function () {
    var m = CylinderGeometry.createGeometry(
      new CylinderGeometry({
        vertexFormat: VertexFormat.POSITION_ONLY,
        length: 1,
        topRadius: 0,
        bottomRadius: 1,
        slices: 3,
      })
    );
 
    var numVertices = 12; //(3 top 3 bottom) duplicated
    var numTriangles = 8; //1 top 1 bottom, 2 on each of 3 sides
    expect(m.attributes.position.values.length).toEqual(numVertices * 3);
    expect(m.indices.length).toEqual(numTriangles * 3);
  });
 
  it("computes positions with bottomRadius equals 0", function () {
    var m = CylinderGeometry.createGeometry(
      new CylinderGeometry({
        vertexFormat: VertexFormat.POSITION_ONLY,
        length: 1,
        topRadius: 1,
        bottomRadius: 0,
        slices: 3,
      })
    );
 
    var numVertices = 12; //(3 top 3 bottom) duplicated
    var numTriangles = 8; //1 top 1 bottom, 2 on each of 3 sides
    expect(m.attributes.position.values.length).toEqual(numVertices * 3);
    expect(m.indices.length).toEqual(numTriangles * 3);
  });
 
  it(
    "undefined is returned if the length is less than or equal to zero or if " +
      "both radii are equal to zero or is either radii and less than zero",
    function () {
      var cylinder0 = new CylinderGeometry({
        length: 0,
        topRadius: 80000,
        bottomRadius: 200000,
      });
      var cylinder1 = new CylinderGeometry({
        length: 200000,
        topRadius: 0,
        bottomRadius: 0,
      });
      var cylinder2 = new CylinderGeometry({
        length: 200000,
        topRadius: -10,
        bottomRadius: 4,
      });
      var cylinder3 = new CylinderGeometry({
        length: -200000,
        topRadius: 100,
        bottomRadius: 100,
      });
      var cylinder4 = new CylinderGeometry({
        length: 200000,
        topRadius: 0,
        bottomRadius: -34,
      });
 
      var geometry0 = CylinderGeometry.createGeometry(cylinder0);
      var geometry1 = CylinderGeometry.createGeometry(cylinder1);
      var geometry2 = CylinderGeometry.createGeometry(cylinder2);
      var geometry3 = CylinderGeometry.createGeometry(cylinder3);
      var geometry4 = CylinderGeometry.createGeometry(cylinder4);
 
      expect(geometry0).toBeUndefined();
      expect(geometry1).toBeUndefined();
      expect(geometry2).toBeUndefined();
      expect(geometry3).toBeUndefined();
      expect(geometry4).toBeUndefined();
    }
  );
 
  var cylinder = new CylinderGeometry({
    vertexFormat: VertexFormat.POSITION_ONLY,
    length: 1,
    topRadius: 1,
    bottomRadius: 0,
    slices: 3,
  });
  var packedInstance = [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 3.0, -1.0];
  createPackableSpecs(CylinderGeometry, cylinder, packedInstance);
});