Skip to content

Port S2LegacyValidQuery and use in polygon validation #72

@parsaaes

Description

@parsaaes

In the documentation of PolygonFromOrientedLoops, it's said that:

It expects loops to be oriented such that the polygon interior is on the left-hand side of all loops. This implies that shells and holes should have opposite orientations in the input to this method.

and:

The loop orientations must all be consistent; for example, it is not valid to have one CCW loop nested inside another CCW loop, because the region between the two loops is on the left-hand side of one loop and the right-hand side of the other.

But in this example, I'm giving two nested counter-clockwise loops to PolygonFromOrientedLoops and it automatically makes the inner loop a hole like how it does in PolygonFromLoops. So shouldn't Validate returns an error in this situation or I'm missing something here?

This is the visualization of loops:
ccw

Code:

package main import (	"fmt"	"github.com/golang/geo/s2" ) func main() {	// ccw	s := [][]float64{	{	35.841751,	50.991497,	},	{	35.836811,	50.991626,	},	{	35.83695,	51.002612,	},	{	35.842065,	51.00081,	},	}	// ccw	h := [][]float64{	{	35.841056,	50.996089,	},	{	35.837785,	50.993557,	},	{	35.83789,	51.000381,	},	}	sLoop := loopFromDegrees(s)	hLoop := loopFromDegrees(h)	polygon := s2.PolygonFromOrientedLoops([]*s2.Loop{sLoop, hLoop})	fmt.Println(sLoop.Area() - hLoop.Area(), polygon.Area())	fmt.Println(polygon.Validate()) } func loopFromDegrees(in [][]float64) *s2.Loop {	points := make([]s2.Point, 0, len(in))	for _, p := range in {	points = append(points, s2.PointFromLatLng(s2.LatLngFromDegrees(p[0], p[1])))	}	return s2.LoopFromPoints(points) } 

Output:

9.931323540629714e-09 9.931323540629714e-09 <nil> 

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions