blob: d5ecff38ae8a643ed80e5302292f5bd102b54690 [file] [log] [blame]
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +01001// *********** HERE STARTS circle-mode.js *************
2
Javier López-Contreras052503f2018-12-26 12:34:42 +01003window.addEventListener("load", initCircleMode);
4
5circleMode = false;
6
7function initCircleMode() {
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +01008 document.querySelector("#circle-mode").addEventListener('click', function() {
Javier López-Contreras052503f2018-12-26 12:34:42 +01009 if(circleMode) {
10 circleMode = false;
11 document.querySelector("#circle-mode i").innerText = "trip_origin";
12
13 s.graph.nodes().forEach(function(n) {
14 n.x = n.originalX;
15 n.y = n.originalY;
16 n.size = 10;
17 });
18
19 s.refresh();
20
21 }
22 else {
23 circleMode = true;
24 document.querySelector("#circle-mode i").innerText = "shuffle";
25
26 s.graph.nodes().forEach(function(n) {
27 n.x = n.circleX;
28 n.y = n.circleY;
29 });
30
31 s.refresh();
32 }
33 });
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +010034}
35
36function isInRect (x, y, rect) {
37 if (x < -10000 || x > 10000) return true;
38 if (y < -10000 || y > 10000) return true;
39
40 var ans = true;
41 var c = crossProd (rect[0], rect[1], x, y);
42
43 for(var i=1; i<4; i++) {
44 var temp = crossProd (rect[i], rect[(i+1)%4], x, y);
45 if (c*temp < 0) ans = false;
46 }
47 return ans;
48}
49
50function crossProd(r1, r2, x, y) {
51 return r1[0]*r2[1] + r2[0]*y + x*r1[1] - r1[0]*y - r2[0]*r1[1] - x*r2[1];
Javier López-Contreras052503f2018-12-26 12:34:42 +010052}