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 | circleMode = false;
|
| 4 |
|
| 5 | function initCircleMode() {
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 6 | document.querySelector("#circle-mode").addEventListener('click', function() {
|
| 7 | if(circleMode) {
|
| 8 | circleMode = false;
|
| 9 | document.querySelector("#circle-mode i").innerText = "trip_origin";
|
Javier López-Contreras | 052503f | 2018-12-26 12:34:42 +0100 | [diff] [blame] | 10 |
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 11 | s.graph.nodes().forEach(function(n) {
|
| 12 | n.x = n.originalX;
|
| 13 | n.y = n.originalY;
|
| 14 | n.size = 10;
|
| 15 | });
|
| 16 |
|
| 17 | s.refresh();
|
| 18 | } else {
|
| 19 | circleMode = true;
|
| 20 | document.querySelector("#circle-mode i").innerText = "scatter_plot";
|
| 21 |
|
| 22 | s.graph.nodes().forEach(function(n) {
|
| 23 | n.x = n.circleX;
|
| 24 | n.y = n.circleY;
|
| 25 | });
|
| 26 |
|
| 27 | s.refresh();
|
| 28 | }
|
| 29 | });
|
Javier López-Contreras | 6d1d72d | 2018-12-27 23:17:18 +0100 | [diff] [blame] | 30 | }
|
| 31 |
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 32 | function isInRect(x, y, rect) {
|
| 33 | if (x < -10000 || x > 10000) return true;
|
| 34 | if (y < -10000 || y > 10000) return true;
|
| 35 |
|
| 36 | var ans = true;
|
| 37 | var c = crossProd (rect[0], rect[1], x, y);
|
| 38 |
|
| 39 | for(var i = 1; i < 4; i++) {
|
| 40 | var temp = crossProd (rect[i], rect[(i+1)%4], x, y);
|
| 41 | if (c*temp < 0) ans = false;
|
| 42 | }
|
| 43 | return ans;
|
Javier López-Contreras | 6d1d72d | 2018-12-27 23:17:18 +0100 | [diff] [blame] | 44 | }
|
| 45 |
|
| 46 | function crossProd(r1, r2, x, y) {
|
avm99963 | 027b5b0 | 2018-12-28 02:31:46 +0100 | [diff] [blame] | 47 | return r1[0]*r2[1] + r2[0]*y + x*r1[1] - r1[0]*y - r2[0]*r1[1] - x*r2[1];
|
| 48 | }
|