-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCurves.js
114 lines (99 loc) · 2.98 KB
/
Curves.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
/*global Curve*/
"use strict";
function Curves() {
this.curves = [];
this.connected = {};
this.rawfrom = {};
}
Curves.prototype.reposition = function (from, bubbles) {
var i = null,
con = this.connected[from],
to = null;
from = bubbles.getNamed(from);
for (i in con) {
if (con.hasOwnProperty(i)) {
to = bubbles.getNamed(i);
con[i].recompute(from.getCurveStart(), to.getCurveStart());
}
}
};
Curves.prototype.masterFrom = function (bubbleIndex, mastered) {
var i,
list = this.rawfrom[bubbleIndex];
if (list === undefined) {
return;
}
for (i = 0; i < list.length; i += 1) {
this.connected[bubbleIndex][list[i]].intoMastered(mastered);
}
};
Curves.prototype.append = function (curve, from, to) {
var retEarly = false,
index = 0;
if (from === to) {
return;
}
if (this.connected[from] === undefined) {
this.connected[from] = {};
}
if (this.connected[from][to] !== undefined) {
if (this.rawfrom[from] !== undefined) {
index = this.rawfrom[from].indexOf(to);
console.log("fromto index: ", index);
if (index !== -1) {
this.rawfrom[from].splice(index, 1);
console.log("removed rawfrom from-to: curves[" + index + "]");
}
}
index = this.curves.indexOf(this.connected[from][to]);
if (index !== -1) {
this.curves.splice(index, 1);
console.log("removed curve from-to: curves[" + index + "]");
}
delete this.connected[from][to];
retEarly = true;
}
if (this.connected[to] === undefined) {
this.connected[to] = {};
}
if (this.connected[to][from] !== undefined) {
if (this.rawfrom[to] !== undefined) {
index = this.rawfrom[to].indexOf(from);
console.log("fromto index: ", index);
if (index !== -1) {
this.rawfrom[to].splice(index, 1);
console.log("removed rawfrom from-to: curves[" + index + "]");
}
}
index = this.curves.indexOf(this.connected[to][from]);
if (index !== -1) {
this.curves.splice(index, 1);
console.log("removed curve to-from: curves[" + index + "]");
}
delete this.connected[to][from];
retEarly = true;
}
if (retEarly) {
console.log("Ret early");
return;
}
if (this.rawfrom[from] === undefined) {
this.rawfrom[from] = [];
}
this.curves.push(curve);
this.connected[from][to] = curve;
this.connected[to][from] = curve;
this.rawfrom[from].push(to);
};
Curves.prototype.getForwards = function (from) {
if (this.rawfrom[from] !== undefined) {
return this.rawfrom[from];
}
return [];
};
Curves.prototype.draw = function (context) {
var i = null;
for (i = 0; i < this.curves.length; i += 1) {
this.curves[i].draw(context);
}
};