Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug on Polygon Contains (linked to https://github.com/golang/geo/issues/77 ?) #78

Open
gcollot opened this issue Jun 24, 2021 · 1 comment

Comments

@gcollot
Copy link

gcollot commented Jun 24, 2021

Hello There,

we noticed that Contains method returns false sometimes.

Ex: https://play.golang.org/p/WqDx36fG4rG

package main

import (
	"fmt"
	"github.com/golang/geo/s2"
)

func main() {
	polygon := s2.PolygonFromLoops([]*s2.Loop{
		s2.LoopFromPoints([]s2.Point{
			s2.PointFromLatLng(s2.LatLngFromDegrees(-38.0, -135.0)),
			s2.PointFromLatLng(s2.LatLngFromDegrees(-38.0, 149.0)),
			s2.PointFromLatLng(s2.LatLngFromDegrees(77.0, 149.0)),
			s2.PointFromLatLng(s2.LatLngFromDegrees(77.0, -135.0)),
			s2.PointFromLatLng(s2.LatLngFromDegrees(-38.0, -135.0)),
		}),
	})
	
	tile := s2.PolygonFromLoops([]*s2.Loop{
		s2.LoopFromPoints([]s2.Point{
			s2.PointFromLatLng(s2.LatLngFromDegrees(37.99616267972809, 13.007812500000002)),
			s2.PointFromLatLng(s2.LatLngFromDegrees(37.99616267972809, 13.359375000000002)),
			s2.PointFromLatLng(s2.LatLngFromDegrees(38.272819658516866, 13.359375000000002)),
			s2.PointFromLatLng(s2.LatLngFromDegrees(38.272819658516866, 13.007812500000002)),
			s2.PointFromLatLng(s2.LatLngFromDegrees(37.99616267972809, 13.007812500000002)),
		}),
	})
	
	// +0.2 lat +0.2 lon
	tileExtended :=  s2.PolygonFromLoops([]*s2.Loop{
		s2.LoopFromPoints([]s2.Point{
			s2.PointFromLatLng(s2.LatLngFromDegrees(37.99616267972809, 13.007812500000002)),
			s2.PointFromLatLng(s2.LatLngFromDegrees(37.99616267972809, 13.559375000000002)),
			s2.PointFromLatLng(s2.LatLngFromDegrees(38.472819658516866, 13.559375000000002)),
			s2.PointFromLatLng(s2.LatLngFromDegrees(38.472819658516866, 13.007812500000002)),
			s2.PointFromLatLng(s2.LatLngFromDegrees(37.99616267972809, 13.007812500000002)),
		}),
	})
	
	fmt.Println(polygon.Contains(tile))
	fmt.Println(polygon.Contains(tileExtended))
}

Returns

false
true

Program exited.

However, all these geometries (tile & tileExtended) are contained in polygon.

Maybe, this might be linked to #77

@sreekanth-cb
Copy link

sreekanth-cb commented Apr 20, 2022

Yes @gcollot, this is related to #77.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants