champlain_view_go_to() animates transition in a wrong direction when wrapping happens
@tmiasko
Submitted by Tomasz Miąsko Link to original bug (#791755)
Description
In case of drag-and-drop with mouse, view is wrapped horizontally as necessary in viewport_pos_changed_cb. On the other hand, delegation of work in default key-event handler looks as below, and neither of those take care of wrapping (in fact get_latitude and get_longitude perform clamping instead):
- kinetic_scroll_key_press_cb
- champlain_view_scroll
- champlain_map_source_get_longitude
- champlain_view_go_to_with_duration or champlain_view_center_on
- champlain_view_scroll
Additionally, after enabling horizontal wrapping in demos/keyboard-mapping.py (which has custom key-bindings), the wrapping is performed only in one direction. This seem to be result of following code in champlain_view_x_to_longitude:
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);
To work correctly, the result of expression x + priv->viewport_x passed as an argument to champlain_map_source_get_longitude shouldn't require any further wrapping. x + priv->viewport_x is certainly < width as established by condition above, but if viewport_x is negative (which in fact may happen), then it still could be less than zero. Though, I must say it is hardly clear to me which one of those is the root problem here, i.e., the fact that viewport_x is negative in the first place, or that wrapping is not performed correctly for negative numbers.