示例#1
0
文件: s2.go 项目: dgraph-io/dgraph
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
}
示例#2
0
文件: s2.go 项目: dgraph-io/dgraph
// Intersects returns true if the two loops intersect.
func Intersects(l1 *s2.Loop, l2 *s2.Loop) bool {
	if l2.NumEdges() > l1.NumEdges() {
		// Use the larger loop for edge indexing.
		return loopRegion{l2}.intersects(l1)
	}
	return loopRegion{l1}.intersects(l2)
}
示例#3
0
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
}