// Overlaps computes whether the prepared geometry overlaps the other
// prepared geometry.
555339
func (p *PGeometry) Overlaps(other *Geometry) (bool, error) {
	return p.predicate("overlaps", cGEOSPreparedOverlaps, other)
}
1192770
func (b *Bound) Intersects(bound *Bound) bool {

	if (b.ne[0] < bound.sw[0]) ||
		(b.sw[0] > bound.ne[0]) ||
		(b.ne[1] < bound.sw[1]) ||
		(b.sw[1] > bound.ne[1]) {
		return false
	}

	return true
}
589651
func (s1 Int64) Intersection(s2 Int64) Int64 {
	var walk, other Int64
	result := NewInt64()
	if s1.Len() < s2.Len() {
		walk = s1
		other = s2
	} else {
		walk = s2
		other = s1
	}
	for key := range walk {
		if other.Has(key) {
			result.Insert(key)
		}
	}
	return result
}
955732
func (r Region) Intersection(other Region) (ret Region) {
	if !r.Contains(other.Begin()) && !other.Contains(r.Begin()) {
		return
	}
	r2 := Region{Max(r.Begin(), other.Begin()), Min(r.End(), other.End())}
	if r2.Size() != 0 {
		ret = r2
	}
	return
}
570092
func Geometry(b orb.Bound, g orb.Geometry) orb.Geometry {
	if g == nil {
		return nil
	}

	if !b.Intersects(g.Bound()) {
		return nil
	}

	switch g := g.(type) {
	case orb.Point:
		return g // Intersect check above
	case orb.MultiPoint:
		mp := MultiPoint(b, g)
		if len(mp) == 1 {
			return mp[0]
		}

		if mp == nil {
			return nil
		}

		return mp
	case orb.LineString:
		mls := LineString(b, g)
		if len(mls) == 1 {
			return mls[0]
		}

		if len(mls) == 0 {
			return nil
		}
		return mls
	case orb.MultiLineString:
		mls := MultiLineString(b, g)
		if len(mls) == 1 {
			return mls[0]
		}

		if mls == nil {
			return nil
		}

		return mls
	case orb.Ring:
		r := Ring(b, g)
		if r == nil {
			return nil
		}

		return r
	case orb.Polygon:
		p := Polygon(b, g)
		if p == nil {
			return nil
		}

		return p
	case orb.MultiPolygon:
		mp := MultiPolygon(b, g)
		if len(mp) == 1 {
			return mp[0]
		}

		if mp == nil {
			return nil
		}

		return mp
	case orb.Collection:
		c := Collection(b, g)
		if len(c) == 1 {
			return c[0]
		}

		if c == nil {
			return nil
		}

		return c
	case orb.Bound:
		b = Bound(b, g)
		if b.IsEmpty() {
			return nil
		}

		return b
	}

	panic(fmt.Sprintf("geometry type not supported: %T", g))
}
83699
func (b *BitSet) Intersection(compare *BitSet) (result *BitSet) {
	panicIfNull(b)
	panicIfNull(compare)
	b, compare = sortByLength(b, compare)
	result = New(b.length)
	for i, word := range b.set {
		result.set[i] = word & compare.set[i]
	}
	return
}
937936
func (g Geometry) Geometry() orb.Geometry {
	if g.Coordinates != nil {
		return g.Coordinates
	}

	c := make(orb.Collection, 0, len(g.Geometries))
	for _, geom := range g.Geometries {
		c = append(c, geom.Geometry())
	}
	return c
}
1208316
func (g *Geometry) Difference(other *Geometry) (*Geometry, error) {
	return g.binaryTopo("Difference", cGEOSDifference, other)
}
1107
func (e editSet) intersect(x editSet) {
	for pos := range e {
		if _, ok := x[pos]; !ok {
			delete(e, pos)
		}
	}
}
376787
func (p *Polygon) Contains(o *Polygon) bool {
	// If both polygons have one loop, use the more efficient Loop method.
	// Note that Loop's Contains does its own bounding rectangle check.
	if len(p.loops) == 1 && len(o.loops) == 1 {
		return p.loops[0].Contains(o.loops[0])
	}

	// Otherwise if neither polygon has holes, we can still use the more
	// efficient Loop's Contains method (rather than compareBoundary),
	// but it's worthwhile to do our own bounds check first.
	if !p.subregionBound.Contains(o.bound) {
		// Even though Bound(A) does not contain Bound(B), it is still possible
		// that A contains B. This can only happen when union of the two bounds
		// spans all longitudes. For example, suppose that B consists of two
		// shells with a longitude gap between them, while A consists of one shell
		// that surrounds both shells of B but goes the other way around the
		// sphere (so that it does not intersect the longitude gap).
		if !p.bound.Lng.Union(o.bound.Lng).IsFull() {
			return false
		}
	}

	if !p.hasHoles && !o.hasHoles {
		for _, l := range o.loops {
			if !p.anyLoopContains(l) {
				return false
			}
		}
		return true
	}

	// Polygon A contains B iff B does not intersect the complement of A. From
	// the intersection algorithm below, this means that the complement of A
	// must exclude the entire boundary of B, and B must exclude all shell
	// boundaries of the complement of A. (It can be shown that B must then
	// exclude the entire boundary of the complement of A.) The first call
	// below returns false if the boundaries cross, therefore the second call
	// does not need to check for any crossing edges (which makes it cheaper).
	return p.containsBoundary(o) && o.excludesNonCrossingComplementShells(p)
}
419923
func (p *Path) Intersection(geometry interface{}) ([]*Point, [][2]int) {
	var points []*Point
	var segments [][2]int

	switch g := geometry.(type) {
	case Line:
		points, segments = p.IntersectionLine(&g)
	case *Line:
		points, segments = p.IntersectionLine(g)
	case Path:
		points, segments = p.IntersectionPath(&g)
	case *Path:
		points, segments = p.IntersectionPath(g)
	default:
		panic("can only determine intersection with lines and paths")
	}

	return points, segments
}
58180
func (b Bound) Intersects(bound Bound) bool {
	if (b.Max[0] < bound.Min[0]) ||
		(b.Min[0] > bound.Max[0]) ||
		(b.Max[1] < bound.Min[1]) ||
		(b.Min[1] > bound.Max[1]) {
		return false
	}

	return true
}
613904
func (r Range) Intersect(other Range) (Range, bool) {
	if !r.Overlaps(other) {
		return Range{}, false
	}
	newRange := r
	if newRange.Start.Before(other.Start) {
		newRange.Start = other.Start
	}
	if newRange.End.After(other.End) {
		newRange.End = other.End
	}
	return newRange, true
}
263523
func (r Region) Intersects(r2 Region) bool {
	return r.Intersection(r2).Size() > 0
}
454551
func Intersection(set1, set2 Interface, sets ...Interface) Interface {
	all := Union(set1, set2, sets...)
	result := Union(set1, set2, sets...)

	all.Each(func(item interface{}) bool {
		if !set1.Has(item) || !set2.Has(item) {
			result.Remove(item)
		}

		for _, set := range sets {
			if !set.Has(item) {
				result.Remove(item)
			}
		}
		return true
	})
	return result
}
232949
func (s *PortSpec) Overlaps(p *PortSpec) bool {
	a := p
	b := s
	if a.Min > b.Min {
		a = s
		b = p
	}
	if a.Max >= b.Min {
		return true
	}
	return false
}
1070955
func (p *Path) Intersects(geometry interface{}) bool {
	var result bool

	switch g := geometry.(type) {
	case Line:
		result = p.IntersectsLine(&g)
	case *Line:
		result = p.IntersectsLine(g)
	case Path:
		result = p.IntersectsPath(&g)
	case *Path:
		result = p.IntersectsPath(g)
	default:
		panic("can only determine intersection with lines and paths")
	}

	return result
}