Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dy committed Dec 23, 2023
1 parent b79bfaf commit 91d2c32
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.2.3",
"array-bounds": "^1.0.1",
"bubleify": "^2.0.0",
"chttps": "^1.0.6",
"fps-indicator": "^1.3.0",
"gl": "^4.1.1",
"gl": "^6.0.2",
"image-equal": "^4.3.1",
"image-pixels": "^2.2.0",
"next-pow-2": "^1.0.0",
Expand Down
48 changes: 24 additions & 24 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,50 @@ const eq = require('image-equal')
const seed = require('seed-random')
const regl = require('regl')({
gl: require('gl')(200, 200),
attributes: {preserveDrawingBuffer: true},
attributes: { preserveDrawingBuffer: true },
extensions: ['OES_element_index_uint']
})


t('colors/shapes', async t => {
//create square test sdf image
let w = 200, h = 200
let dist = new Array(w*h)
let dist = new Array(w * h)
for (let i = 0; i < w; i++) {
for (let j = 0; j < h; j++) {
if (i > j) {
if (i < h - j) {
dist[j*w + i] = j/(h/2)
dist[j * w + i] = j / (h / 2)
}
else {
dist[j*w + i] = 1 - (i-w/2)/(w/2)
dist[j * w + i] = 1 - (i - w / 2) / (w / 2)
}
}
else {
if (i < h - j) {
dist[j*w + i] = i/(w/2)
dist[j * w + i] = i / (w / 2)
}
else {
dist[j*w + i] = 1 - (j-h/2)/(h/2)
dist[j * w + i] = 1 - (j - h / 2) / (h / 2)
}
}
}
}

var scatter = createScatter(regl)
scatter.update({
positions: [0,0, 1,1, 2,2, 3,3, 4,4, 5,5, 6,6, 7,7],
positions: [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7],
size: 12,
color: ['red', 'green', 'blue', 'black', 'red', 'black', 'red', 'gray'],
marker: [null, null, null, null, dist, dist, dist, dist],
range: [-2,-2,10,10],
range: [-2, -2, 10, 10],
snap: false
})
scatter.draw()

t.ok(eq(await load('./test/img/mixed-markers-colors.png'), scatter.gl, .05))

regl.clear({color: [0,0,0,0]})
regl.clear({ color: [0, 0, 0, 0] })

t.end()
})
Expand All @@ -60,25 +60,25 @@ t('1e6 points', async t => {
var N = 1e6
var positions = new Float64Array(2 * N)

for(var i=0; i<2*N; ++i) {
positions[i] = random()
for (var i = 0; i < 2 * N; ++i) {
positions[i] = random()
}

var scatter = createScatter(regl)
console.time('update')
scatter.update({
positions: positions,
size: 4,
color: [0,0,0,.1],
range: [-.1,-.1,1.1,1.1]
color: [0, 0, 0, .1],
range: [-.1, -.1, 1.1, 1.1]
})
console.timeEnd('update')
console.time('draw')
scatter.draw()
console.timeEnd('draw')

t.ok(eq(scatter.gl, await load('./test/img/1e6.png'), .1))
regl.clear({color: [0,0,0,0]})
regl.clear({ color: [0, 0, 0, 0] })

t.end()
})
Expand All @@ -92,13 +92,13 @@ t('Color palette interference (#3232)', async t => {

var scatter = createScatter(regl)

passes[1].range = [0,0,300,300]
passes[1].range = [0, 0, 300, 300]

scatter.update(passes)
scatter.render()
t.ok(eq(scatter, await load('./test/img/3232.png'), {threshold: .1}))
t.ok(eq(scatter, await load('./test/img/3232.png'), { threshold: .1 }))

regl.clear({color: [0,0,0,0]})
regl.clear({ color: [0, 0, 0, 0] })
t.end()
})

Expand All @@ -120,9 +120,9 @@ t('missing points simple', async t => {
}])
scatter.render()

t.ok(eq(scatter, await load('./test/img/missing-points-simple.png'), {threshold: .1}))
t.ok(eq(scatter, await load('./test/img/missing-points-simple.png'), { threshold: .1 }))

regl.clear({color: [0,0,0,0]})
regl.clear({ color: [0, 0, 0, 0] })
t.end()
})

Expand All @@ -139,13 +139,13 @@ t('missing points #2334', async t => {
positions: data,
size: 3,
snap: true,
range: [0,-10,50,10]
range: [0, -10, 50, 10]
}])
scatter.render()

t.ok(eq(scatter, await load('./test/img/missing-points-2334.png'), {threshold: .1}))
t.ok(eq(scatter, await load('./test/img/missing-points-2334.png'), { threshold: .115 }))

regl.clear({color: [0,0,0,0]})
regl.clear({ color: [0, 0, 0, 0] })
t.end()
})

Expand All @@ -158,7 +158,7 @@ t('large values precision M1 mac (plotly/plotly.js Issue #6820)', async t => {
var x_base = 1e9
// 1e17 is large enough that we're going to have precision issues on any platform.
var y_base = 1e17 + 555
for(var i=0; i<2*N; i += 2) {
for (var i = 0; i < 2 * N; i += 2) {
positions[i] = x_base + i
positions[i + 1] = y_base + i
}
Expand All @@ -176,7 +176,7 @@ t('large values precision M1 mac (plotly/plotly.js Issue #6820)', async t => {

t.ok(eq(scatter.gl, await load('./test/img/large_values_precision_M1_mac.png'), .1))

regl.clear({color: [0,0,0,0]})
regl.clear({ color: [0, 0, 0, 0] })
t.end()
})

Expand Down

0 comments on commit 91d2c32

Please sign in to comment.