Errors in SharpMap. Wrong calculate LinearRing.IsPointWithin method

Topics: Algorithms, SharpMap Project, SharpMap v0.9 / v1.x, SharpMap v2.0
Apr 11, 2008 at 1:46 PM
Edited Apr 11, 2008 at 1:49 PM
!Wrong calculate LinearRing.IsPointWithin method.
Example.
LinearRing ring = new LinearRing();
ring.Vertices.Add(new Point(10,10));
ring.Vertices.Add(new Point(20,10));
ring.Vertices.Add(new Point(20,20));
ring.Vertices.Add(new Point(20,10));

ring.IsPointWithin(new Point(12, 12)); //True
ring.IsPointWithin(new Point(18, 12)); //True
ring.IsPointWithin(new Point(18, 18)); //True
ring.IsPointWithin(new Point(12, 18)); //False

Code:
> for (int i = 0; i < this.Vertices.Count; i++)
> {
> for (int j = i + 1; j < (this.Vertices.Count - 1); j++)
> {

Need replace to:
>for (int i = 0, j = sourceRing.Vertices.Count-1; i < sourceRing.Vertices.Count; j = i++)
> {

Wrong calculate variable j and i.

See: http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
Developer
Apr 11, 2008 at 5:29 PM
Thanks for reporting SMiGL.

The Dan&Joel patch had fixed that bug already. I have commited that code:
http://www.codeplex.com/SharpMap/SourceControl/FileView.aspx?itemId=30521&changeSetId=32815