File libchamplain-Fix-wrapping-champlain_view_x_to_longitude.patch of Package libchamplain

From 122d872eddec278d3b21aa6088ee2d57981e7da8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= <tomasz.miasko@gmail.com>
Date: Wed, 20 Dec 2017 00:00:00 +0000
Subject: Fix wrapping in champlain_view_x_to_longitude.

Previous implementation assumed that after using x_to_wrap_x further
wrapping would be needed only if x + priv->viewport_x >= width.
Unfortunately, this is not the case when priv->viewport_x is negative
and whole x + priv->viewport_x ends up negative.
---
 champlain/champlain-view.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c
index 784d644..154b5eb 100644
--- a/champlain/champlain-view.c
+++ b/champlain/champlain-view.c
@@ -2471,18 +2471,17 @@ champlain_view_x_to_longitude (ChamplainView *view,
 
   g_return_val_if_fail (CHAMPLAIN_IS_VIEW (view), 0.0);
 
+  x += priv->viewport_x;
+
   if (priv->hwrap)
     {
       gdouble width = get_map_width (view);
       x = x_to_wrap_x (x, width);
-
-      if (x >= width - priv->viewport_x)
-        x -= width;
     }
 
   longitude = champlain_map_source_get_longitude (priv->map_source,
         priv->zoom_level,
-        x + priv->viewport_x);
+        x);
 
   return longitude;
 }
-- 
cgit v0.12


From 602e52f5f32c6e5751653571b69105d389bfe125 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= <techet@gmail.com>
Date: Sun, 31 Dec 2017 14:51:41 +0100
Subject: Create a wrap-aware get_longitude() function and use it everywhere in
 view

---
 champlain/champlain-view.c | 53 ++++++++++++++++++++++++++--------------------
 1 file changed, 30 insertions(+), 23 deletions(-)

diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c
index 154b5eb..dd8b3bd 100644
--- a/champlain/champlain-view.c
+++ b/champlain/champlain-view.c
@@ -334,6 +334,26 @@ get_map_width (ChamplainView *view)
 }
 
 
+static gdouble
+get_longitude (ChamplainView *view,
+    guint zoom_level,
+    gdouble x)
+{
+  ChamplainViewPrivate *priv = view->priv;
+
+  DEBUG_LOG ()
+
+  g_return_val_if_fail (CHAMPLAIN_IS_VIEW (view), 0.0);
+
+  if (priv->hwrap)
+    x = x_to_wrap_x (x, get_map_width (view));
+
+  return champlain_map_source_get_longitude (priv->map_source,
+        zoom_level,
+        x);
+}
+
+
 static void
 update_coords (ChamplainView *view,
     gdouble x,
@@ -346,7 +366,7 @@ update_coords (ChamplainView *view,
 
   priv->viewport_x = x;
   priv->viewport_y = y;
-  priv->longitude = champlain_map_source_get_longitude (priv->map_source,
+  priv->longitude = get_longitude (view,
         priv->zoom_level,
         x + priv->viewport_width / 2.0);
   priv->latitude = champlain_map_source_get_latitude (priv->map_source,
@@ -1440,7 +1460,7 @@ zoom_gesture_zoom_cb (ClutterZoomAction *gesture,
       dx = (priv->viewport_width / 2.0) - focal_point->x;
       dy = (priv->viewport_height / 2.0) - focal_point->y;
 
-      lon = champlain_map_source_get_longitude (priv->map_source, zoom_level, focus.x + dx);
+      lon = get_longitude (view, zoom_level, focus.x + dx);
       lat = champlain_map_source_get_latitude (priv->map_source, zoom_level, focus.y + dy);
 
       champlain_view_center_on (view, lat, lon);
@@ -1830,7 +1850,7 @@ champlain_view_scroll (ChamplainView *view,
   y = priv->viewport_y + priv->viewport_height / 2.0 + deltay;
 
   lat = champlain_map_source_get_latitude (priv->map_source, priv->zoom_level, y);
-  lon = champlain_map_source_get_longitude (priv->map_source, priv->zoom_level, x);
+  lon = get_longitude (view, priv->zoom_level, x);
 
   if (priv->kinetic_mode)
     champlain_view_go_to_with_duration (view, lat, lon, 300);
@@ -2465,25 +2485,12 @@ champlain_view_x_to_longitude (ChamplainView *view,
     gdouble x)
 {
   ChamplainViewPrivate *priv = view->priv;
-  gdouble longitude;
 
   DEBUG_LOG ()
 
   g_return_val_if_fail (CHAMPLAIN_IS_VIEW (view), 0.0);
 
-  x += priv->viewport_x;
-
-  if (priv->hwrap)
-    {
-      gdouble width = get_map_width (view);
-      x = x_to_wrap_x (x, width);
-    }
-
-  longitude = champlain_map_source_get_longitude (priv->map_source,
-        priv->zoom_level,
-        x);
-
-  return longitude;
+  return get_longitude (view, priv->zoom_level, x + priv->viewport_x);
 }
 
 
@@ -4036,12 +4043,12 @@ get_bounding_box (ChamplainView *view,
   bbox->bottom = champlain_map_source_get_latitude (priv->map_source,
                                                     zoom_level,
                                                     y + priv->viewport_height);
-  bbox->left = champlain_map_source_get_longitude (priv->map_source,
-                                                   zoom_level,
-                                                   x);
-  bbox->right = champlain_map_source_get_longitude (priv->map_source,
-                                                    zoom_level,
-                                                    x + priv->viewport_width);
+  bbox->left = get_longitude (view,
+                              zoom_level,
+                              x);
+  bbox->right = get_longitude (view,
+                               zoom_level,
+                               x + priv->viewport_width);
   return bbox;
 }
 
-- 
cgit v0.12


From 8752cbe1825a301418451c4cf2e20d8577308c93 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= <techet@gmail.com>
Date: Sun, 31 Dec 2017 14:57:34 +0100
Subject: Properly wrap coordinates in champlain_view_center_on()

---
 champlain/champlain-view.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c
index dd8b3bd..4edabef 100644
--- a/champlain/champlain-view.c
+++ b/champlain/champlain-view.c
@@ -1950,7 +1950,10 @@ champlain_view_center_on (ChamplainView *view,
 
   DEBUG ("Centering on %f, %f (%g, %g)", latitude, longitude, x, y);
 
-  position_viewport (view, x, y);
+  if (priv->hwrap)
+    position_viewport (view, x_to_wrap_x (x, get_map_width (view)), y);
+  else
+    position_viewport (view, x, y);
   load_visible_tiles (view, FALSE);
 }
 
-- 
cgit v0.12
openSUSE Build Service is sponsored by