[Marble-devel] Routing in marble

Dennis Nienhüser earthwings at gentoo.org
Sun May 2 14:58:42 CEST 2010

```On 01.05.2010 17:29, Arnd Baecker wrote:
> - The most crucial point to me is the one mentioned in one of my
>   previous mails  which we already discussed a bit on the IRC:
>
>      Imagine a connection A-B-C which geometrically leads
>      to something like a half-circle.
>      Now I would like to add an additional point between A and B,
>      by dragging via the mouse. If this additional point
>      is placed closer to the connection between B-C
>      than the one between A-B
>      one gets (in terms of the old A, B, C): A-B-Newpoint-C.
>      However, I would have expected A-Newpoint-B-C,
>      i.e. the new point should be inserted in the list of points
>      between A and B  and not between the geometrically closest points.
>      ((Side remark: If one thinks of adding a new point somewhere
>      using a mouse-click, the current approach seems correct,
>      but not for modifying a segment between two points, at least IMO)).
>
>   To solve this, one somehow has to figure out from which segment
>   the point was dragged away. Then the new via point just has to be
>   inserted in between these two elements.
>   One approach to find the place in the list of via-points could be
>   as follows:
>   a) Determine the corresponding closest line segment
>      along the waypoints.
>      (Here the distance between the point and all line segments
>      has to be used, as for sharp bends of the route wrong
>      associations could happen).
>   b) Then one has to find the two closest via-points along the route.
>      You pointed out that waypoints and via points are stored
>      in two independent lists. So for each via-point one could
>      attach the corresponding label to the closest point of
>      the closest route segment (sorry, sounds complicated,
>      but this seems necessary to get the right association ... ;-).
>
>      With this preparation, one just has to go backward in the list of
>      waypoints from the line segment found in a) to find the
>      previous via-point and forward to find the next via-point.
>

I implemented it close to this now by calculating a mapping between
waypoints in the route and via points. The drag origin is close to an
existing waypoint. The previous and next waypoint in the mapping then
indicate the two neighboring via points. They're indicated by a dotted
line while dragging.

Regards,
Dennis

```