# [mkgmap-dev] Explanation of the is_in function

From Ticker Berkin rwb-mkgmap at jagit.co.uk on Sat May 23 11:01:25 BST 2020

```Hi Gerd

Here is a patch that should fix the problem - In the original code I
got carried away with the symmetry of Lat/Lon handling in the distance
calculation but the set-up for the crossing calculation isn't
symmetric!

I've also explained the ON error area more carefully and used INFINITY
instead of NaN because that is the horizontal distance where a line
through the node would meet a horizontal polygon side.

Ticker

On Fri, 2020-05-22 at 21:44 +0100, Ticker Berkin wrote:
> Hi Gerd
>
> I think I understand what is going wrong. I'll do another patch
> tomorrow.
>
> Ticker
>
>
> On Fri, 2020-05-22 at 13:36 +0000, Gerd Petermann wrote:
> > Hi Ticker,
> >
> > the patched version still returns ON for a Coord which is not ON
> > and
> > thus doesn't work with my example.
> > The result doesn't depend on the position of the last point of the
> > way as long as it is builds a nearly or exactly straight line with
> > two nodes of the shape.
> >
> > Your algorithm returns true for each such point, even when it is
> > 100m
> > away from any shape vertex.
> > See my new example where A,B and C build a straight line. Another
> > node is very close to the edge but still returns  IN (OK)
> >
> > Gerd
> >
> >
> > ________________________________________
> > Von: mkgmap-dev <mkgmap-dev-bounces at lists.mkgmap.org.uk> im Auftrag
> > von Ticker Berkin <rwb-mkgmap at jagit.co.uk>
> > Gesendet: Donnerstag, 21. Mai 2020 17:07
> > An: Development list for mkgmap
> > Betreff: Re: [mkgmap-dev] Explanation of the is_in function
> >
> > Hi Gerd
> >
> > Here is patch that prevents possible underflow when node is very
> > close
> > to an almost horizontal or vertical line and incorrect results when
> > exactly on this line.
> >
> > Ticker
> >
> > _______________________________________________
> > mkgmap-dev mailing list
> > mkgmap-dev at lists.mkgmap.org.uk
> > http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
> _______________________________________________
> mkgmap-dev mailing list
> mkgmap-dev at lists.mkgmap.org.uk
> http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: isPointInShape_v3.patch
Type: text/x-patch
Size: 3157 bytes
Desc: not available
URL: <http://www.mkgmap.org.uk/pipermail/mkgmap-dev/attachments/20200523/c97ffbb1/attachment.bin>
```