loleaflet/src/geometry/PolyUtil.js    |  141 +++++++++++++++++++++++++++++++++
 loleaflet/src/layer/tile/TileLayer.js |  143 ----------------------------------
 2 files changed, 142 insertions(+), 142 deletions(-)

New commits:
commit 8d22cb30899e747d7c6d2f5f8a4807d0c48eb927
Author: Mihai Varga <mihai.va...@collabora.com>
Date:   Thu Jul 16 17:47:40 2015 +0300

    loleaflet: moved 'rectanglesToPolygons' method to PolyUtils

diff --git a/loleaflet/src/geometry/PolyUtil.js 
b/loleaflet/src/geometry/PolyUtil.js
index f5afe08..f024159 100644
--- a/loleaflet/src/geometry/PolyUtil.js
+++ b/loleaflet/src/geometry/PolyUtil.js
@@ -51,3 +51,144 @@ L.PolyUtil.clipPolygon = function (points, bounds, round) {
 
        return points;
 };
+
+L.PolyUtil.rectanglesToPolygons = function (rectangles, docLayer) {
+       // algorithm found here 
http://stackoverflow.com/questions/13746284/merging-multiple-adjacent-rectangles-into-one-polygon
+       var eps = 20;
+       // Glue rectangles if the space between them is less then eps
+       for (var i = 0; i < rectangles.length - 1; i++) {
+               for (var j = i + 1; j < rectangles.length; j++) {
+                       for (var k = 0; k < rectangles[i].length; k++) {
+                               for (var l = 0; l < rectangles[j].length; l++) {
+                                       if (Math.abs(rectangles[i][k].x - 
rectangles[j][l].x) < eps) {
+                                               rectangles[j][l].x = 
rectangles[i][k].x;
+                                       }
+                                       if (Math.abs(rectangles[i][k].y - 
rectangles[j][l].y) < eps) {
+                                               rectangles[j][l].y = 
rectangles[i][k].y;
+                                       }
+                               }
+                       }
+               }
+       }
+
+       var points = {};
+       for (i = 0; i < rectangles.length; i++) {
+               for (j = 0; j < rectangles[i].length; j++) {
+                       if (points[rectangles[i][j]]) {
+                               delete points[rectangles[i][j]];
+                       }
+                       else {
+                               points[rectangles[i][j]] = rectangles[i][j];
+                       }
+               }
+       }
+
+       function getKeys(points) {
+               var keys = [];
+               for (var key in points) {
+                       if (points.hasOwnProperty(key)) {
+                               keys.push(key);
+                       }
+               }
+               return keys;
+       }
+
+       function xThenY(aStr, bStr) {
+               var a = aStr.match(/\d+/g);
+               a[0] = parseInt(a[0]);
+               a[1] = parseInt(a[1]);
+               var b = bStr.match(/\d+/g);
+               b[0] = parseInt(b[0]);
+               b[1] = parseInt(b[1]);
+
+               if (a[0] < b[0] || (a[0] === b[0] && a[1] < b[1])) {
+                       return -1;
+               }
+               else if (a[0] === b[0] && a[1] === b[1]) {
+                       return 0;
+               }
+               else {
+                       return 1;
+               }
+       }
+
+       function yThenX(aStr, bStr) {
+               var a = aStr.match(/\d+/g);
+               a[0] = parseInt(a[0]);
+               a[1] = parseInt(a[1]);
+               var b = bStr.match(/\d+/g);
+               b[0] = parseInt(b[0]);
+               b[1] = parseInt(b[1]);
+
+               if (a[1] < b[1] || (a[1] === b[1] && a[0] < b[0])) {
+                       return -1;
+               }
+               else if (a[0] === b[0] && a[1] === b[1]) {
+                       return 0;
+               }
+               else {
+                       return 1;
+               }
+       }
+
+       var sortX = getKeys(points).sort(xThenY);
+       var sortY = getKeys(points).sort(yThenX);
+
+       var edgesH = {};
+       var edgesV = {};
+
+       var len = getKeys(points).length;
+       i = 0;
+       while (i < len) {
+               var currY = points[sortY[i]].y;
+               while (i < len && points[sortY[i]].y === currY) {
+                       edgesH[sortY[i]] = sortY[i + 1];
+                       edgesH[sortY[i + 1]] = sortY[i];
+                       i += 2;
+               }
+       }
+
+       i = 0;
+       while (i < len) {
+               var currX = points[sortX[i]].x;
+               while (i < len && points[sortX[i]].x === currX) {
+                       edgesV[sortX[i]] = sortX[i + 1];
+                       edgesV[sortX[i + 1]] = sortX[i];
+                       i += 2;
+               }
+       }
+
+       var polygons = [];
+       var edgesHKeys = getKeys(edgesH);
+       while (edgesHKeys.length > 0) {
+               var p = [[edgesHKeys[0], 0]];
+               while (true) {
+                       var curr = p[p.length - 1][0];
+                       var e = p[p.length - 1][1];
+                       if (e === 0) {
+                               var nextVertex = edgesV[curr];
+                               delete edgesV[curr];
+                               p.push([nextVertex, 1]);
+                       }
+                       else {
+                               nextVertex = edgesH[curr];
+                               delete edgesH[curr];
+                               p.push([nextVertex, 0]);
+                       }
+                       if (p[p.length - 1][0] === p[0][0] && p[p.length - 
1][1] === p[0][1]) {
+                               p.pop();
+                               break;
+                       }
+               }
+               var polygon = [];
+               for (i = 0; i < p.length; i++) {
+                       polygon.push(docLayer._twipsToLatLng(points[p[i][0]]));
+                       delete edgesH[p[i][0]];
+                       delete edgesV[p[i][0]];
+               }
+               polygon.push(docLayer._twipsToLatLng(points[p[0][0]]));
+               edgesHKeys = getKeys(edgesH);
+               polygons.push(polygon);
+       }
+       return polygons;
+};
diff --git a/loleaflet/src/layer/tile/TileLayer.js 
b/loleaflet/src/layer/tile/TileLayer.js
index ac74511..42a59f4 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -402,7 +402,7 @@ L.TileLayer = L.GridLayer.extend({
                                        
$('#scroll-container').mCustomScrollbar('scrollTo', [center.y, center.x]);
                                }
 
-                               var polygons = 
this._rectanglesToPolygons(rectangles);
+                               var polygons = 
L.PolyUtil.rectanglesToPolygons(rectangles, this);
                                for (i = 0; i < polygons.length; i++) {
                                        var selection = new 
L.Polygon(polygons[i], {
                                                pointerEvents: 'none',
@@ -511,147 +511,6 @@ L.TileLayer = L.GridLayer.extend({
                e.tile.onload = null;
        },
 
-       _rectanglesToPolygons: function(rectangles) {
-               // algorithm found here 
http://stackoverflow.com/questions/13746284/merging-multiple-adjacent-rectangles-into-one-polygon
-               var eps = 20;
-               // Glue rectangles if the space between them is less then eps
-               for (var i = 0; i < rectangles.length - 1; i++) {
-                       for (var j = i + 1; j < rectangles.length; j++) {
-                               for (var k = 0; k < rectangles[i].length; k++) {
-                                       for (var l = 0; l < 
rectangles[j].length; l++) {
-                                               if (Math.abs(rectangles[i][k].x 
- rectangles[j][l].x) < eps) {
-                                                       rectangles[j][l].x = 
rectangles[i][k].x;
-                                               }
-                                               if (Math.abs(rectangles[i][k].y 
- rectangles[j][l].y) < eps) {
-                                                       rectangles[j][l].y = 
rectangles[i][k].y;
-                                               }
-                                       }
-                               }
-                       }
-               }
-
-               var points = {};
-               for (i = 0; i < rectangles.length; i++) {
-                       for (j = 0; j < rectangles[i].length; j++) {
-                               if (points[rectangles[i][j]]) {
-                                       delete points[rectangles[i][j]];
-                               }
-                               else {
-                                       points[rectangles[i][j]] = 
rectangles[i][j];
-                               }
-                       }
-               }
-
-               function getKeys(points) {
-                       var keys = [];
-                       for (var key in points) {
-                               if (points.hasOwnProperty(key)) {
-                                       keys.push(key);
-                               }
-                       }
-                       return keys;
-               }
-
-               function xThenY(aStr, bStr) {
-                       var a = aStr.match(/\d+/g);
-                       a[0] = parseInt(a[0]);
-                       a[1] = parseInt(a[1]);
-                       var b = bStr.match(/\d+/g);
-                       b[0] = parseInt(b[0]);
-                       b[1] = parseInt(b[1]);
-
-                       if (a[0] < b[0] || (a[0] === b[0] && a[1] < b[1])) {
-                               return -1;
-                       }
-                       else if (a[0] === b[0] && a[1] === b[1]) {
-                               return 0;
-                       }
-                       else {
-                               return 1;
-                       }
-               }
-
-               function yThenX(aStr, bStr) {
-                       var a = aStr.match(/\d+/g);
-                       a[0] = parseInt(a[0]);
-                       a[1] = parseInt(a[1]);
-                       var b = bStr.match(/\d+/g);
-                       b[0] = parseInt(b[0]);
-                       b[1] = parseInt(b[1]);
-
-                       if (a[1] < b[1] || (a[1] === b[1] && a[0] < b[0])) {
-                               return -1;
-                       }
-                       else if (a[0] === b[0] && a[1] === b[1]) {
-                               return 0;
-                       }
-                       else {
-                               return 1;
-                       }
-               }
-
-               var sortX = getKeys(points).sort(xThenY);
-               var sortY = getKeys(points).sort(yThenX);
-
-               var edgesH = {};
-               var edgesV = {};
-
-               var len = getKeys(points).length;
-               i = 0;
-               while (i < len) {
-                       var currY = points[sortY[i]].y;
-                       while (i < len && points[sortY[i]].y === currY) {
-                               edgesH[sortY[i]] = sortY[i + 1];
-                               edgesH[sortY[i + 1]] = sortY[i];
-                               i += 2;
-                       }
-               }
-
-               i = 0;
-               while (i < len) {
-                       var currX = points[sortX[i]].x;
-                       while (i < len && points[sortX[i]].x === currX) {
-                               edgesV[sortX[i]] = sortX[i + 1];
-                               edgesV[sortX[i + 1]] = sortX[i];
-                               i += 2;
-                       }
-               }
-
-               var polygons = [];
-               var edgesHKeys = getKeys(edgesH);
-               while (edgesHKeys.length > 0) {
-                       var p = [[edgesHKeys[0], 0]];
-                       while (true) {
-                               var curr = p[p.length - 1][0];
-                               var e = p[p.length - 1][1];
-                               if (e === 0) {
-                                       var nextVertex = edgesV[curr];
-                                       delete edgesV[curr];
-                                       p.push([nextVertex, 1]);
-                               }
-                               else {
-                                       nextVertex = edgesH[curr];
-                                       delete edgesH[curr];
-                                       p.push([nextVertex, 0]);
-                               }
-                               if (p[p.length - 1][0] === p[0][0] && 
p[p.length - 1][1] === p[0][1]) {
-                                       p.pop();
-                                       break;
-                               }
-                       }
-                       var polygon = [];
-                       for (i = 0; i < p.length; i++) {
-                               
polygon.push(this._twipsToLatLng(points[p[i][0]]));
-                               delete edgesH[p[i][0]];
-                               delete edgesV[p[i][0]];
-                       }
-                       polygon.push(this._twipsToLatLng(points[p[0][0]]));
-                       edgesHKeys = getKeys(edgesH);
-                       polygons.push(polygon);
-               }
-               return polygons;
-       },
-
        _clearSelections: function () {
                this._selections.clearLayers();
        },
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to