Skip to content

LinearRing.isInside SimplePolgon2d.contains : incorrect for anti-clockwise case #10

Open
@dsmith82

Description

@dsmith82

The isInside and contains methods have the following test

if (area > 0) {
    	return winding == 1;
} else {
    	return winding == 0;
}

I believe the code should be

if (area > 0) {
   return winding == 1;
 } else {
  return winding == -1;
}

This can be tested with the following simple example

		double[] xcoords0 = {0.0, 0.0, 10.0, 10.0, 0.0};
		double[] ycoords0 = {0.0, 10.0, 10.0, 0.0, 0.0};
		LinearRing2D ringCW = new LinearRing2D(xcoords0, ycoords0);

		// anti-clockwise 
		double[] xcoords1 = {0.0, 10.0, 10.0, 0.0, 0.0};
		double[] ycoords1 = {0.0, 0.0, 10.0, 10.0, 0.0};
		LinearRing2D ringACW = new LinearRing2D(xcoords1, ycoords1);

		System.out.println(ringCW.isInside(1.0, 1.0));
		System.out.println(ringCW.isInside(10.5, 10.5));
		
		System.out.println(ringACW.isInside(1.0, 1.0));
		System.out.println(ringACW.isInside(10.5, 10.5));

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions