Skip to content

Commit 9133a03

Browse files
committed
Fix clustering loss on wide ranges
1 parent f367976 commit 9133a03

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ function Scatter (regl, options) {
372372
let batch = []
373373
let {lod, x, id} = ids
374374

375-
let pixelSize = (range[2] - range[0]) / group.viewport.width
375+
let pixelSize = Math.min((range[2] - range[0]) / group.viewport.width, , (range[3] - range[1]) / group.viewport.height)
376376

377377
for (let scaleNum = lod.length; scaleNum--;) {
378378
let level = lod[scaleNum]

test.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function show (arr) {
7676

7777

7878

79-
let N = 1e6
79+
let N = 10001
8080
let ratio = window.innerWidth / window.innerHeight
8181
let range = [-10 * ratio, -10, 10 * ratio, 10]
8282
let colors = palettes[Math.floor(Math.random() * palettes.length)]
@@ -96,17 +96,17 @@ scatter(Array(passes).fill(null).map((x, i) => {
9696
// positions: [0,0, .1,.1, .2,.2, .3,.3, .4,.4, .5,.5, .6,.6, .7,.7, .8,.8, .9,.9, 1,1],
9797
// positions: [0,0, 1,1, -1,-1, 1,-1, -1,1, 0,1, 0,-1, 1,0, -1,0],
9898

99-
// size: Array(pos.length).fill(100).map(x => Math.random() * 5 + 5),
100-
size: 10,
101-
// color: Array(pos.length).fill(0).map(() => colors[Math.floor(Math.random() * colors.length)]),
102-
color: 'rgba(0, 0, 0, .5)',
99+
size: Array(pos.length).fill(100).map(x => Math.random() * 5 + 5),
100+
// size: 10,
101+
color: Array(pos.length).fill(0).map(() => colors[Math.floor(Math.random() * colors.length)]),
102+
// color: 'rgba(0, 0, 0, .5)',
103103

104104
// marker: markers[i],
105105
// marker: Array(pos.length).fill(0).map(() => markers[Math.floor(Math.random() * markers.length)]),
106106

107107
range: range,
108-
borderSize: 1,
109-
borderColor: [[.5,.5,.5,1]],
108+
// borderSize: 1,
109+
// borderColor: [[.5,.5,.5,1]],
110110
snap: true,
111111
precise: true,
112112

@@ -165,6 +165,12 @@ function generate(N) {
165165
positions[i] = random()
166166
}
167167

168+
169+
// for (var i = 0; i < N; i++) {
170+
// positions[i * 2] = i;
171+
// positions[i * 2 + 1] = Math.random();
172+
// }
173+
168174
return positions
169175
}
170176

0 commit comments

Comments
 (0)