Skip to content

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

Closed
@gcollot

Description

@gcollot

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions