-
Notifications
You must be signed in to change notification settings - Fork 0
/
workerInstance.js
130 lines (92 loc) · 3.13 KB
/
workerInstance.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
if('function' === typeof importScripts) {
this.importScripts('intervalArithmetic.js');
this.localUint = null;
this.config = null;
}
this.onmessage = function(message) {
if(message.data.array) {
this.localUint = message.data.array;
// console.log("worker: poraka sodrzhi uint");
}
if(!this.localUint || this.localUint.length == 0) {
// console.log("worker: poraka bez uint")
}
this.config = message.data.config
workerPanWorker()
}
var startTime = 0;
function drawImplicitSeq(start, end, array) {
let implicit = globalImplicit
let xInterval = this.config.xInterval;
let yInterval = this.config.yInterval;
let scale = this.config.scale
let windowWidth = this.config.width
let a,b;
for(let i=start.lo; i<=start.hi; i++) {
for(let j=end.lo; j<=end.hi; j++) {
a = new Interval(i/scale+xInterval, (i+1)/scale+xInterval);
b = new Interval(j/scale+yInterval, (j+1)/scale+yInterval);
let result = implicit(a,b.flip())
array[4*(i + windowWidth*j)+0] = 0;
array[4*(i + windowWidth*j)+1] = 0;
array[4*(i + windowWidth*j)+2] = 0;
array[4*(i + windowWidth*j)+3] = 0;
if(result.lo > 0 || result.hi < 0)
continue;
array[4*(i + windowWidth*j)+0] = 255;
array[4*(i + windowWidth*j)+3] = 255;
}
}
}
var globalImplicit = (x,y) => x.subtract(new Interval(2))//x.sin().subtract(y.cos()).subtract(new Interval(0.2))
function workerPanWorker() {
// if(!globalMemoryImageTestThing)
// testUint()
let width = this.config.width, height = this.config.height, amount = this.config.amount;
let uint = this.localUint;
if(uint.length == 0) {
return;
}
translateH(uint, amount[0])
translateV(uint, amount[1])
// worker.postMessage({start: {lo: width+amount, hi: width}, end: {lo: 0, hi: height}, array: uint}, [uint.buffer])
if(amount[0] < 0) {
drawImplicitSeq(new Interval(width+amount[0], width), new Interval(0,height), uint)
}
else if(amount[0] > 0) {
drawImplicitSeq(new Interval(0, amount[0]), new Interval(0,height), uint)
}
if(amount[1] < 0) {
drawImplicitSeq(new Interval(0,width), new Interval(height+amount[1], height), uint)
}
else if(amount[1] > 0) {
drawImplicitSeq(new Interval(0,width), new Interval(0, amount[1]), uint)
}
// uint.fill(150, 0, width*height*4)
// let image = new ImageData(uint, Application.config.windowWidth, Application.config.windowHeight);
// console.log("worker: prakjam kon main so uint")
this.postMessage({array: this.localUint}, [this.localUint.buffer])
}
function translateH(array, amount) {
if(amount < 0) {
array.copyWithin(0,-4*amount)
// drawImplicitSeq(new Interval(width+amount*2, width), new Interval(0,height), array)
}
else if(amount > 0) {
array.copyWithin(4*amount)
// drawImplicitSeq(new Interval(0, amount*2), new Interval(0,height), array)
}
return array;
}
function translateV(array, amount) {
let width = this.config.width
if(amount < 0) {
array.copyWithin(0,-width*4*amount)
// drawImplicitSeq(new Interval(0,width), new Interval(height+amount*2, height), array)
}
else if(amount > 0) {
array.copyWithin(width*4*amount)
// drawImplicitSeq(new Interval(0,width), new Interval(0, amount*2), array)
}
return array;
}