Javier López-Contreras | 6d1d72d | 2018-12-27 23:17:18 +0100 | [diff] [blame] | 1 | // *********** HERE STARTS circle-mode.js *************
|
| 2 |
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 3 | window.addEventListener("load", initCircleMode);
|
| 4 |
|
| 5 | circleMode = false;
|
| 6 |
|
| 7 | function initCircleMode() {
|
Javier López-Contreras | 6d1d72d | 2018-12-27 23:17:18 +0100 | [diff] [blame] | 8 | document.querySelector("#circle-mode").addEventListener('click', function() {
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 9 | 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-Contreras | 6d1d72d | 2018-12-27 23:17:18 +0100 | [diff] [blame] | 34 | }
|
| 35 |
|
| 36 | function 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 |
|
| 50 | function 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-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 52 | } |