func (l loopRegion) intersects(loop *s2.Loop) bool { // Quick check if the bounding boxes intersect if !l.RectBound().Intersects(loop.RectBound()) { return false } // Quick check to see if the first vertex is in the loop. if l.ContainsPoint(loop.Vertex(0)) { return true } // At this stage the one vertex is outside the loop. We check if any of the edges of the cell // cross the loop. if l.edgesCrossPoints(loop.Vertices()) { return true } // At this stage we know that there is one point of the loop is outside us and the boundaries do // not interesect. The only way for the loops to intersect is if it contains us. We test this // by checking if an arbitrary vertex is inside the loop. if loop.RectBound().Contains(l.RectBound()) { return loop.ContainsPoint(l.Vertex(0)) } return false }
func loopArea(l *s2.Loop) float64 { n := l.NumEdges() origin := l.Vertex(0) var area float64 for i := 1; i < n-1; i++ { area += s2.PointArea(origin, l.Vertex(i), l.Vertex(i+1)) * float64(s2.RobustSign(origin, l.Vertex(i), l.Vertex(i+1))) } return area }