Skip to content

Commit d957ea8

Browse files
committed
BufferPolygonCollectionSpec should use valid-ish geometry
1 parent d135ca7 commit d957ea8

File tree

1 file changed

+54
-34
lines changed

1 file changed

+54
-34
lines changed

packages/engine/Specs/Scene/BufferPolygonCollectionSpec.js

Lines changed: 54 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ describe("BufferPolygonCollection", () => {
2121
const polygon = new BufferPolygon();
2222

2323
const positions1 = new Float64Array([10, 11, 12, 13, 14, 15, 16, 17, 18]);
24-
const positions2 = new Float64Array([20, 21, 22, 23, 24, 25]);
25-
const positions3 = new Float64Array([30, 31, 32, 33, 34, 35, 36, 37, 38]);
24+
const positions2 = new Float64Array([20, 21, 22, 23, 24, 25, 26, 27, 28]);
25+
const positions3 = new Float64Array([
26+
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
27+
]);
2628

2729
collection.add({ positions: positions1 }, polygon);
2830
collection.add({ positions: positions2 }, polygon);
@@ -33,38 +35,39 @@ describe("BufferPolygonCollection", () => {
3335
expect(polygon.getPositions(new Float64Array(9))).toEqual(positions1);
3436

3537
collection.get(1, polygon);
36-
expect(polygon.vertexCount, 2);
37-
expect(polygon.getPositions(new Float64Array(6))).toEqual(positions2);
38+
expect(polygon.vertexCount, 3);
39+
expect(polygon.getPositions(new Float64Array(9))).toEqual(positions2);
3840

3941
collection.get(2, polygon);
40-
expect(polygon.vertexCount, 3);
41-
expect(polygon.getPositions(new Float64Array(9))).toEqual(positions3);
42+
expect(polygon.vertexCount, 4);
43+
expect(polygon.getPositions(new Float64Array(12))).toEqual(positions3);
4244
});
4345

4446
it("holes", () => {
4547
const collection = new BufferPolygonCollection({
46-
maxPositionCount: 8,
47-
holeCountMax: 3,
48+
vertexCountMax: 12,
49+
holeCountMax: 1,
4850
});
4951
const polygon = new BufferPolygon();
5052

51-
const positions1 = new Float64Array([10, 11, 12, 13, 14, 15, 16, 17, 18]);
52-
const positions2 = new Float64Array([20, 21, 22, 23, 24, 25]);
53-
const positions3 = new Float64Array([30, 31, 32, 33, 34, 35, 36, 37, 38]);
53+
const positions1 = createBoxPositions(1);
54+
const positions2 = createBoxPositions(2);
55+
const positions3 = new Float64Array([
56+
...createBoxPositions(2), // outer loop
57+
...createBoxPositions(1), // hole
58+
]);
5459

55-
const holes2 = new Uint32Array([12, 24]);
56-
const holes3 = new Uint32Array([16]);
60+
const holes3 = new Uint32Array([3]);
5761

5862
collection.add({ positions: positions1 }, polygon);
59-
collection.add({ positions: positions2, holes: holes2 }, polygon);
63+
collection.add({ positions: positions2 }, polygon);
6064
collection.add({ positions: positions3, holes: holes3 }, polygon);
6165

6266
collection.get(0, polygon);
6367
expect(polygon.holeCount, 0);
6468

6569
collection.get(1, polygon);
66-
expect(polygon.holeCount, 2);
67-
expect(polygon.getHoles(new Uint32Array(2))).toEqual(holes2);
70+
expect(polygon.holeCount, 0);
6871

6972
collection.get(2, polygon);
7073
expect(polygon.holeCount, 1);
@@ -73,7 +76,7 @@ describe("BufferPolygonCollection", () => {
7376

7477
it("triangles", () => {
7578
const collection = new BufferPolygonCollection({
76-
maxPositionCount: (24 + 30 + 15) / 3,
79+
vertexCountMax: (24 + 30 + 15) / 3,
7780
holeCountMax: 0,
7881
triangleCountMax: 4,
7982
});
@@ -156,21 +159,23 @@ describe("BufferPolygonCollection", () => {
156159

157160
const src = new BufferPolygonCollection({
158161
primitiveCountMax: 2,
159-
vertexCountMax: 8,
160-
holeCountMax: 2,
162+
vertexCountMax: 6,
163+
holeCountMax: 0,
161164
triangleCountMax: 4,
162165
});
163166

164-
const positions1 = new Float64Array([10, 11, 12, 13, 14, 15, 16, 17, 18]);
165-
const positions2 = new Float64Array([20, 21, 22, 23, 24, 25]);
166-
const positions3 = new Float64Array([30, 31, 32, 33, 34, 35, 36, 37, 38]);
167+
const positions1 = createBoxPositions(3);
168+
const positions2 = createBoxPositions(2.5);
169+
const positions3 = new Float64Array([
170+
...createBoxPositions(3),
171+
...createBoxPositions(0.5),
172+
]);
167173

168-
const holes2 = new Uint32Array([12, 24]);
169-
const holes3 = new Uint32Array([16]);
174+
const holes3 = new Uint32Array([3]);
170175

171-
const triangles1 = new Uint32Array([0, 1, 2, 3, 4, 5, 6, 7, 8]);
172-
const triangles2 = new Uint32Array([0, 1, 2]);
173-
const triangles3 = new Uint32Array([6, 7, 8, 0, 1, 2, 3, 4, 5]);
176+
const triangles1 = new Uint32Array([0, 1, 2, 2, 1, 3]);
177+
const triangles2 = new Uint32Array([2, 1, 3, 0, 1, 2]);
178+
const triangles3 = new Uint32Array([0, 1, 2, 2, 1, 3]); // hack: doesn't consider the hole.
174179

175180
src.add(
176181
{ positions: positions1, triangles: triangles1, color: Color.RED },
@@ -180,7 +185,6 @@ describe("BufferPolygonCollection", () => {
180185
src.add(
181186
{
182187
positions: positions2,
183-
holes: holes2,
184188
triangles: triangles2,
185189
color: Color.GREEN,
186190
},
@@ -189,9 +193,9 @@ describe("BufferPolygonCollection", () => {
189193

190194
const dst = new BufferPolygonCollection({
191195
primitiveCountMax: 3,
192-
vertexCountMax: 11,
193-
holeCountMax: 3,
194-
triangleCountMax: 7,
196+
vertexCountMax: 12,
197+
holeCountMax: 1,
198+
triangleCountMax: 6,
195199
});
196200

197201
BufferPolygonCollection.clone(src, dst);
@@ -210,29 +214,32 @@ describe("BufferPolygonCollection", () => {
210214
);
211215

212216
expect(dst.primitiveCount).toBe(3);
213-
expect(dst.holeCount).toBe(3);
214-
expect(dst.triangleCount).toBe(7);
217+
expect(dst.holeCount).toBe(1);
218+
expect(dst.triangleCount).toBe(6);
215219

216220
dst.get(0, polygon);
217221
expect(polygon.getColor(color)).toEqual(Color.RED);
218222
expect(polygon.getPositions(new Float64Array(positions1.length))).toEqual(
219223
positions1,
220224
);
221225
expect(polygon.holeCount).toBe(0);
226+
expect(polygon.triangleCount).toBe(2);
222227

223228
dst.get(1, polygon);
224229
expect(polygon.getColor(color)).toEqual(Color.GREEN);
225230
expect(polygon.getPositions(new Float64Array(positions2.length))).toEqual(
226231
positions2,
227232
);
228-
expect(polygon.holeCount).toBe(2);
233+
expect(polygon.holeCount).toBe(0);
234+
expect(polygon.triangleCount).toBe(2);
229235

230236
dst.get(2, polygon);
231237
expect(polygon.getColor(color)).toEqual(Color.BLUE);
232238
expect(polygon.getPositions(new Float64Array(positions3.length))).toEqual(
233239
positions3,
234240
);
235241
expect(polygon.holeCount).toBe(1);
242+
expect(polygon.triangleCount).toBe(2);
236243
});
237244

238245
it("sort", () => {
@@ -285,3 +292,16 @@ describe("BufferPolygonCollection", () => {
285292
);
286293
});
287294
});
295+
296+
/**
297+
* @param {number} scale
298+
* @returns {Float64Array}
299+
*/
300+
function createBoxPositions(scale) {
301+
// prettier-ignore
302+
return new Float64Array([
303+
scale, -scale, 0,
304+
-scale, -scale, 0,
305+
-scale, scale, 0,
306+
]);
307+
}

0 commit comments

Comments
 (0)