// ==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