Skip to content

Commit 88c86ef

Browse files
authored
Merge pull request #4 from gl-vis/no-cwise
drop cwise
2 parents c8c130f + a18f9ba commit 88c86ef

File tree

2 files changed

+27
-33
lines changed

2 files changed

+27
-33
lines changed

package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
},
99
"dependencies": {
1010
"bit-twiddle": "^1.0.2",
11-
"cwise": "^1.0.10",
1211
"gl-fbo": "^2.0.5",
1312
"ndarray": "^1.0.18",
1413
"typedarray-pool": "^1.1.0"
@@ -36,8 +35,5 @@
3635
"bugs": {
3736
"url": "https://github.com/gl-vis/gl-select-static/issues"
3837
},
39-
"homepage": "https://github.com/gl-vis/gl-select-static",
40-
"browserify": {
41-
"transform": "cwise"
42-
}
38+
"homepage": "https://github.com/gl-vis/gl-select-static"
4339
}

select.js

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,37 @@ module.exports = createSelectBuffer
55
var createFBO = require('gl-fbo')
66
var pool = require('typedarray-pool')
77
var ndarray = require('ndarray')
8-
var cwise = require('cwise')
98
var nextPow2 = require('bit-twiddle').nextPow2
109

11-
var selectRange = cwise({
12-
args: [
13-
'array',
14-
{'offset': [0,0,1], 'array':0},
15-
{'offset': [0,0,2], 'array':0},
16-
{'offset': [0,0,3], 'array':0},
17-
'scalar',
18-
'scalar',
19-
'index'],
20-
pre: function() {
21-
this.closestD2 = 1e8
22-
this.closestX = -1
23-
this.closestY = -1
24-
},
25-
body: function(r, g, b, a, x, y, idx) {
26-
if(r < 255 || g < 255 || b < 255 || a < 255) {
27-
var dx = x - idx[0]
28-
var dy = y - idx[1]
29-
var d2 = dx*dx + dy*dy
30-
if(d2 < this.closestD2) {
31-
this.closestD2 = d2
32-
this.closestX = idx[0]
33-
this.closestY = idx[1]
10+
var selectRange = function(arr, x, y) {
11+
var closestD2 = 1e8
12+
var closestX = -1
13+
var closestY = -1
14+
15+
var ni = arr.shape[0]
16+
var nj = arr.shape[1]
17+
for(var i = 0; i < ni; i++) {
18+
for(var j = 0; j < nj; j++) {
19+
var r = arr.get(i, j, 0)
20+
var g = arr.get(i, j, 1)
21+
var b = arr.get(i, j, 2)
22+
var a = arr.get(i, j, 3)
23+
24+
if(r < 255 || g < 255 || b < 255 || a < 255) {
25+
var dx = x - i
26+
var dy = y - j
27+
var d2 = dx*dx + dy*dy
28+
if(d2 < closestD2) {
29+
closestD2 = d2
30+
closestX = i
31+
closestY = j
32+
}
3433
}
3534
}
36-
},
37-
post: function() {
38-
return [this.closestX, this.closestY, this.closestD2]
3935
}
40-
})
36+
37+
return [closestX, closestY, closestD2]
38+
}
4139

4240
function SelectResult(x, y, id, value, distance) {
4341
this.coord = [x, y]

0 commit comments

Comments
 (0)