-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathorient.js
More file actions
45 lines (38 loc) · 1.11 KB
/
Copy pathorient.js
File metadata and controls
45 lines (38 loc) · 1.11 KB
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
"use strict"
var fs = require("fs")
var ndarray = require("ndarray")
var imshow = require("ndarray-imshow")
var savePixels = require("save-pixels")
var robustLeftRight = require("robust-orientation")
var NX = 512
var NY = 512
function naiveLeftRight(a, b, c) {
var abx = c[0] - a[0]
var aby = c[1] - a[1]
var acx = b[0] - a[0]
var acy = b[1] - a[1]
return abx * acy - aby * acx
}
function plotPredicate(pred) {
var img = ndarray(new Uint8Array(NX*NY*3), [NX,NY,3])
for(var i=0; i<NX; ++i) {
for(var j=0; j<NY; ++j) {
var px = 0.5 + i * Math.pow(2, -53)
var py = 0.5 + j * Math.pow(2, -53)
var o = pred([px, py], [12, 12], [24, 24])
if(o < 0) {
img.set(i,j,2,255)
} else if(o > 0) {
img.set(i,j,0,255)
} else {
img.set(i,j,1,255)
}
}
}
//imshow(img)
return savePixels(img, "png")
}
console.log("naive predicate")
plotPredicate(naiveLeftRight).pipe(fs.createWriteStream(__dirname + "/../images/naive-lr.png"))
console.log("robust predicate")
plotPredicate(robustLeftRight).pipe(fs.createWriteStream(__dirname + "/../images/robust-lr.png"))