From 86d44bdd00ec1b78f29e0919d01f9b037c185e3b Mon Sep 17 00:00:00 2001 From: mcben Date: Thu, 5 Jun 2014 14:31:56 +0200 Subject: [PATCH] new plugin: cross links this plugin colors links red if they are crossing a drawnline. any yellow if they are inside a drawn polygon. (requires DrawTools) --- plugins/cross_link.user.js | 188 +++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 plugins/cross_link.user.js diff --git a/plugins/cross_link.user.js b/plugins/cross_link.user.js new file mode 100644 index 00000000..a6b304dd --- /dev/null +++ b/plugins/cross_link.user.js @@ -0,0 +1,188 @@ +// ==UserScript== +// @id iitc-plugin-cross-links@mcben +// @name IITC plugin: cross links +// @category Layer +// @version 1.0.@@DATETIMEVERSION@@ +// @namespace https://github.com/jonatkins/ingress-intel-total-conversion +// @updateURL @@UPDATEURL@@ +// @downloadURL @@DOWNLOADURL@@ +// @description [McBen] requires drawtool! coloring of link collision +// @include https://www.ingress.com/intel* +// @include http://www.ingress.com/intel* +// @match https://www.ingress.com/intel* +// @match http://www.ingress.com/intel* +// @grant none +// ==/UserScript== + +@@PLUGINSTART@@ + +// PLUGIN START //////////////////////////////////////////////////////// + +// use own namespace for plugin +window.plugin.crossLinks = function() {}; + +window.plugin.crossLinks.STYLE_LINECOLLISION = {color: '#f22', weight: 4}; +window.plugin.crossLinks.STYLE_INSIDEPOLY = {color: '#ff2', weight: 4}; + + +function relativeCCW(x1,y1,x2,y2, px, py) { + // code from java.awt + x2 -= x1; + y2 -= y1; + px -= x1; + py -= y1; + + var ccw = px * y2 - py * x2; + + if (ccw == 0.0) { + ccw = px * x2 + py * y2; + + if (ccw > 0.0) { + px -= x2; + py -= y2; + ccw = px * x2 + py * y2; + + if (ccw < 0.0) { + ccw = 0.0; + } + } + } + return (ccw < 0.0) ? -1 : ((ccw > 0.0) ? 1 : 0); + } + +function linesIntersect(x1,y1,x2,y2,x3,y3,x4,y4) { + // code from java.awt + return ( (relativeCCW(x1, y1, x2, y2, x3, y3) * relativeCCW(x1, y1, x2, y2, x4, y4) <= 0) + && (relativeCCW(x3, y3, x4, y4, x1, y1) * relativeCCW(x3, y3, x4, y4, x2, y2) <= 0)); +} + +function isCrossing(p1,p2,q1,q2) { + return linesIntersect( p1.lat,p1.lng,p2.lat,p2.lng, + q1.lat,q1.lng,q2.lat,q2.lng); +} + +window.plugin.crossLinks.testLine = function (drawline, link) { + + var linkline= L.geodesicConvertLines(link._latlngs,0); + + for (var j=0;j point.lng) != (p2.lng>point.lng)) && + (point.lat < (p2.lat - p1.lat)*(point.lng-p1.lng) / (p2.lng-p1.lng) + p1.lat)) + c = !c; + + p2 = p1; + } + return c; +} + +window.plugin.crossLinks.testPolygons = function (polygons, link) { + + var linkline= L.geodesicConvertLines(link._latlngs,0); + + for (var pidx=0;pidx