golang / geo

S2 geometry library in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Coverer.CellUnion(Point) can have multiple cells?

jsmorph opened this issue · comments

In S2, in some cases, a Coverer.CellUnion() of a Point can contain two cells. Is that the correct behavior? If so, what's the story?

Example:

package main

import (
	"fmt"

	"github.com/golang/geo/s2"
)

func main() {
	var (
		level   = 7
		coverer = s2.RegionCoverer{
			MinLevel: level,
			MaxLevel: level,
		}
		ll    = s2.LatLng{Lat: -0.8248776721189366, Lng: -2.038611228784389}
		p     = s2.PointFromLatLng(ll)
		union = coverer.CellUnion(p)
	)
	fmt.Println(len(union))
}

At the playground.

5/0030111 and 5/0101000 both contain s2.LatLng{Lat: -0.8248776721189366, Lng: -2.038611228784389} per the playground. Surprised me!

@rsned, thanks for the quick, detailed response.

For posterity:

Since Cell.ContainsPoint(Point) reports true for those two cells and that point, I decided to read the documentation, which says to convert a Cell to a Loop. That works.