loleaflet/src/geometry/Bounds.js          |   20 ++++++++++++++++
 loleaflet/src/geometry/Point.js           |   15 ++++++++++++
 loleaflet/src/layer/tile/CalcTileLayer.js |    4 +--
 loleaflet/src/layer/tile/TileLayer.js     |   37 ------------------------------
 4 files changed, 38 insertions(+), 38 deletions(-)

New commits:
commit ed812c066a8ab529e7ec54a4c8430f910ecd07d6
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Fri Jun 5 17:41:11 2020 +0530
Commit:     Dennis Francis <dennis.fran...@collabora.com>
CommitDate: Mon Jul 6 18:57:16 2020 +0200

    introduce L.Point.parse() and L.Bounds.parse() functions
    
    and reuse them where we need to parse points/rectangles strings from
    core and avoid writing the same parsing code everywhere.
    
    Change-Id: I029ba97eaa1062eef404eeb8f35d1c6897315d80
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/98149
    Tested-by: Jenkins
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Dennis Francis <dennis.fran...@collabora.com>

diff --git a/loleaflet/src/geometry/Bounds.js b/loleaflet/src/geometry/Bounds.js
index b671c0ad5..1c10ea6d4 100644
--- a/loleaflet/src/geometry/Bounds.js
+++ b/loleaflet/src/geometry/Bounds.js
@@ -13,6 +13,26 @@ L.Bounds = function (a, b) { //(Point, Point) or Point[]
        }
 };
 
+L.Bounds.parse = function (rectString) { // (string) -> Bounds
+
+       if (typeof rectString !== 'string') {
+               console.error('invalid rectangle string');
+               return undefined;
+       }
+
+       var rectParts = rectString.match(/\d+/g);
+       if (rectParts === null || rectParts.length < 4) {
+               console.error('incomplete rectangle');
+               return undefined;
+       }
+
+       var refPoint1 = new L.Point(parseInt(rectParts[0]), 
parseInt(rectParts[1]));
+       var offset = new L.Point(parseInt(rectParts[2]), 
parseInt(rectParts[3]));
+       var refPoint2 = refPoint1.add(offset);
+
+       return new L.Bounds(refPoint1, refPoint2);
+};
+
 L.Bounds.prototype = {
        // extend the bounds to contain the given point
        extend: function (point) { // (Point)
diff --git a/loleaflet/src/geometry/Point.js b/loleaflet/src/geometry/Point.js
index 47d8fe433..37acfb20c 100644
--- a/loleaflet/src/geometry/Point.js
+++ b/loleaflet/src/geometry/Point.js
@@ -8,6 +8,21 @@ L.Point = function (x, y, round) {
        this.y = (round ? Math.round(y) : y);
 };
 
+L.Point.parse = function (pointString) { // (string) -> Point
+       if (typeof pointString !== 'string') {
+               console.error('invalid point string');
+               return undefined;
+       }
+
+       var pointParts = pointString.match(/\d+/g);
+       if (pointParts === null || pointParts.length < 2) {
+               console.error('incomplete point');
+               return undefined;
+       }
+
+       return new L.Point(parseInt(pointParts[0]), parseInt(pointParts[1]));
+};
+
 L.Point.prototype = {
 
        clone: function () {
diff --git a/loleaflet/src/layer/tile/CalcTileLayer.js 
b/loleaflet/src/layer/tile/CalcTileLayer.js
index ce5707c32..93a633eb2 100644
--- a/loleaflet/src/layer/tile/CalcTileLayer.js
+++ b/loleaflet/src/layer/tile/CalcTileLayer.js
@@ -792,8 +792,8 @@ L.CalcTileLayer = L.TileLayer.extend({
                        return undefined;
                }
 
-               var relrect = this._parseRectangle(msgObj.relrect);
-               var refpoint = this._parsePoint(msgObj.refpoint);
+               var relrect = L.Bounds.parse(msgObj.relrect);
+               var refpoint = L.Point.parse(msgObj.refpoint);
                refpoint = 
this.sheetGeometry.getTileTwipsPointFromPrint(refpoint);
                return relrect.add(refpoint);
        }
diff --git a/loleaflet/src/layer/tile/TileLayer.js 
b/loleaflet/src/layer/tile/TileLayer.js
index 6a0d27ba2..85ab40d74 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -3409,42 +3409,7 @@ L.TileLayer = L.GridLayer.extend({
                        return undefined;
                }
 
-               return this._parseRectangle(msgObj.rectangle);
-       },
-
-       _parsePoint: function (pointString) {
-               if (typeof pointString !== 'string') {
-                       console.error('invalid point string');
-                       return undefined;
-               }
-
-               var pointParts = pointString.match(/\d+/g);
-               if (pointParts.length < 2) {
-                       console.error('incomplete point');
-                       return undefined;
-               }
-
-               return new L.Point(parseInt(pointParts[0]), 
parseInt(pointParts[1]));
-       },
-
-       _parseRectangle: function (rectString) {
-
-               if (typeof rectString !== 'string') {
-                       console.error('invalid rectangle string');
-                       return undefined;
-               }
-
-               var strTwips = rectString.match(/\d+/g);
-               if (strTwips.length < 4) {
-                       console.error('incomplete rectangle');
-                       return undefined;
-               }
-
-               var topLeftTwips = new L.Point(parseInt(strTwips[0]), 
parseInt(strTwips[1]));
-               var offset = new L.Point(parseInt(strTwips[2]), 
parseInt(strTwips[3]));
-               var bottomRightTwips = topLeftTwips.add(offset);
-
-               return new L.Bounds(topLeftTwips, bottomRightTwips);
+               return L.Bounds.parse(msgObj.rectangle);
        },
 
        _debugGetTimeArray: function() {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to