-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
325 lines (258 loc) · 8.08 KB
/
test.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
const test = require('tape')
const quad = require('./quads')
test('createQuad', t => {
test('createQuad with w h', t => {
const {mesh, cell} = quad.createQuad({w: 2, h: 6})
t.plan(2)
t.deepLooseEqual(mesh, {
positions: [[-1, 0, -3], [-1, 0, 3], [1, 0, 3], [1, 0, -3]],
normals: [[0, 1, 0], [0, 1, 0], [0, 1, 0], [0, 1, 0]],
cells: [[0, 1, 2, 3]]
}, 'A quad simplicial complex is created')
t.deepLooseEqual(cell, [0, 1, 2, 3], 'The cell is also returned.')
})
test('createQuad with positions', t => {
const {mesh, cell} = quad.createQuad({positions: [[-1, 0, -3], [-1, 0, 3], [1, 0, 3], [1, 0, -3]]})
t.plan(2)
t.deepLooseEqual(mesh, {
positions: [[-1, 0, -3], [-1, 0, 3], [1, 0, 3], [1, 0, -3]],
normals: [[0, 1, 0], [0, 1, 0], [0, 1, 0], [0, 1, 0]],
cells: [[0, 1, 2, 3]]
}, 'A quad simplicial complex is created')
t.deepLooseEqual(cell, [0, 1, 2, 3], 'The cell is also returned.')
})
test('createQuad with nothing', t => {
const {mesh, cell} = quad.createQuad()
t.plan(2)
t.deepLooseEqual(mesh, {
positions: [[-0.5, 0, -0.5], [-0.5, 0, 0.5], [0.5, 0, 0.5], [0.5, 0, -0.5]],
normals: [[0, 1, 0], [0, 1, 0], [0, 1, 0], [0, 1, 0]],
cells: [[0, 1, 2, 3]]
}, 'A quad simplicial complex is created')
t.deepLooseEqual(cell, [0, 1, 2, 3], 'The cell is also returned.')
})
test('createQuad with w h and facing a direction', t => {
const {mesh, cell} = quad.createQuad({w: 2, h: 6, facing: 'z-'})
t.plan(2)
t.deepLooseEqual(mesh, {
positions: [[1, -3, 0], [1, 3, 0], [-1, 3, 0], [-1, -3, 0]],
normals: [[0, 0, -1], [0, 0, -1], [0, 0, -1], [0, 0, -1]],
cells: [[3, 2, 1, 0]]
}, 'A quad simplicial complex is created')
t.deepLooseEqual(cell, [3, 2, 1, 0], 'The cell is also returned.')
})
test('createQuad normal facing is correct', t => {
t.plan(6)
const xp = quad.createQuad({facing: 'x+'})
t.deepLooseEqual(xp.mesh.normals[0], [1, 0, 0], 'x+ points up')
const xm = quad.createQuad({facing: 'x-'})
t.deepLooseEqual(xm.mesh.normals[0], [-1, 0, 0], 'x- points down')
const yp = quad.createQuad({facing: 'y+'})
t.deepLooseEqual(yp.mesh.normals[0], [0, 1, 0], 'y+ points up')
const ym = quad.createQuad({facing: 'y-'})
t.deepLooseEqual(ym.mesh.normals[0], [0, -1, 0], 'y- points down')
const zp = quad.createQuad({facing: 'z+'})
t.deepLooseEqual(zp.mesh.normals[0], [0, 0, 1], 'z+ points up')
const zm = quad.createQuad({facing: 'z-'})
t.deepLooseEqual(zm.mesh.normals[0], [0, 0, -1], 'z- points down')
})
t.end()
})
test.skip('averageNormalForPosition', t => {
const mesh = quad.createBox(1, 1, 1)
quad.subdivide(mesh, 1)
const index = 0
t.deepLooseEqual(
mesh.normals[index],
[ -0.5773502691896258, 0.5773502691896258, -0.5773502691896258 ],
'Normal is how it was originally computed'
)
mesh.positions[index][1] += 0.2
t.deepLooseEqual(
mesh.normals[index],
[ -0.5773502691896258, 0.5773502691896258, -0.5773502691896258 ],
'New normal was averaged by its neighbors.'
)
t.end()
})
test('clone', t => {
const mesh = quad.createBox(1, 1, 1)
const cellToPositions = i => mesh.positions[i]
t.equals(mesh.cells.length, 6, 'starts with 6 cells')
t.equals(mesh.positions.length, 8, 'starts with 8 cells')
// console.log(mesh)
quad.clone(mesh, mesh.cells[0])
t.equals(mesh.cells.length, 7, '1 cell was added')
t.equals(mesh.positions.length, 12, '4 positions was added')
t.deepLooseEqual(
mesh.cells[0].map(cellToPositions),
mesh.cells[6].map(cellToPositions),
'The newly added cell was equal to the old one.'
)
t.end()
})
test('cloneCells', t => {
const mesh = quad.createBox(1, 1, 1)
const cellToPositions = i => mesh.positions[i]
t.equals(mesh.cells.length, 6, 'starts with 6 cells')
t.equals(mesh.positions.length, 8, 'starts with 8 cells')
const twoConcurrentCells = mesh.cells.slice(1, 3)
const clonedCells = quad.getNewGeometry(mesh, 'cells', () => {
quad.cloneCells(mesh, twoConcurrentCells)
})
t.equals(mesh.cells.length, 6 + 2, '2 cells were added')
t.equals(mesh.positions.length, 8 + 6, '6 positions were added')
t.deepLooseEqual(
twoConcurrentCells.map(cellToPositions),
clonedCells.map(cellToPositions),
'The newly added cells was equal to the old one.'
)
t.end()
})
test('computeCenterPositions', t => {
const mesh = quad.createBox(1, 1, 1)
const centers = quad.computeCenterPositions(mesh)
t.deepLooseEqual(centers, [
[0, 0.5, 0],
[0, -0.5, 0],
[-0.5, 0, 0],
[0, 0, 0.5],
[0.5, 0, 0],
[0, 0, -0.5]
], 'The centers of the cells are calculated.')
t.end()
})
test('computeCellCenter', t => {
const mesh = quad.createBox(1, 1, 1)
const topQuad = mesh.cells[0]
const center = quad.computeCellCenter(mesh, topQuad)
t.deepLooseEqual(center, [0, 0.5, 0])
t.end()
})
test('computeNormals - connected', t => {
const mesh = quad.createBox(1, 1, 1)
delete mesh.normals
quad.computeNormals(mesh)
t.deepLooseEqual(mesh.normals, [
[-0.5773502691896258, -0.5773502691896258, -0.5773502691896258],
[-0.5773502691896258, -0.5773502691896258, 0.5773502691896258],
[0.5773502691896258, -0.5773502691896258, 0.5773502691896258],
[0.5773502691896258, -0.5773502691896258, -0.5773502691896258],
[-0.5773502691896258, 0.5773502691896258, -0.5773502691896258],
[-0.5773502691896258, 0.5773502691896258, 0.5773502691896258],
[0.5773502691896258, 0.5773502691896258, 0.5773502691896258],
[0.5773502691896258, 0.5773502691896258, -0.5773502691896258]
], 'Calculates normals that are the average of the surrounding cells')
t.end()
})
test('computeNormals - disjoint', t => {
const mesh = quad.createBoxDisjoint(1, 1, 1)
delete mesh.normals
quad.computeNormals(mesh)
t.deepLooseEqual(mesh.normals, [
[-1, 0, 0],
[-1, 0, 0],
[1, 0, 0],
[1, 0, 0],
[0, -1, 0],
[0, -1, 0],
[0, -1, 0],
[0, -1, 0],
[0, 0, -1],
[0, 0, 1],
[0, 0, 1],
[0, 0, -1],
[0, 1, 0],
[0, 0, -1],
[-1, 0, 0],
[0, 1, 0],
[-1, 0, 0],
[0, 0, 1],
[0, 1, 0],
[0, 0, 1],
[1, 0, 0],
[0, 1, 0],
[1, 0, 0],
[0, 0, -1]
], 'Calculates normals that are unique to the disjoint cell.')
t.end()
})
test('createBox', t => {
const mesh = quad.createBox(1, 2, 3)
t.deepLooseEqual(mesh, {
positions: [
[-0.5, -1, -1.5],
[-0.5, -1, 1.5],
[0.5, -1, 1.5],
[0.5, -1, -1.5],
[-0.5, 1, -1.5],
[-0.5, 1, 1.5],
[0.5, 1, 1.5],
[0.5, 1, -1.5]],
normals: [
[-0.5773502691896258, -0.5773502691896258, -0.5773502691896258],
[-0.5773502691896258, -0.5773502691896258, 0.5773502691896258],
[0.5773502691896258, -0.5773502691896258, 0.5773502691896258],
[0.5773502691896258, -0.5773502691896258, -0.5773502691896258],
[-0.5773502691896258, 0.5773502691896258, -0.5773502691896258],
[-0.5773502691896258, 0.5773502691896258, 0.5773502691896258],
[0.5773502691896258, 0.5773502691896258, 0.5773502691896258],
[0.5773502691896258, 0.5773502691896258, -0.5773502691896258]
],
cells: [
[4, 5, 6, 7],
[3, 2, 1, 0],
[0, 1, 5, 4],
[5, 1, 2, 6],
[7, 6, 2, 3],
[0, 4, 7, 3]
]
})
t.end()
})
test.skip('createBoxDisjoint', t => {
})
test.skip('elementsFromQuads', t => {
})
test.skip('extrude', t => {
})
test.skip('extrudeDisjoint', t => {
})
test.skip('flip', t => {
})
test.skip('getCellNormal', t => {
})
test.skip('getCellFromEdge', t => {
})
test.skip('getCellsFromPositionIndex', t => {
})
test.skip('getCenter', t => {
})
test.skip('getLoop', t => {
})
test.skip('getNewGeometry', t => {
})
test.skip('inset', t => {
})
test.skip('insetDisjoint', t => {
})
test.skip('insetLoop', t => {
})
test.skip('mergePositions', t => {
})
test.skip('mirror', t => {
})
test.skip('subdivide', t => {
})
test.skip('splitHorizontal', t => {
})
test.skip('splitHorizontalDisjoint', t => {
})
test.skip('splitLoop', t => {
})
test.skip('splitVertical', t => {
})
test.skip('splitVerticalDisjoint', t => {
})
test.skip('updateNormals', t => {
})