MCPcopy
hub / github.com/golang/geo / IntersectsCell

Method IntersectsCell

s2/polyline.go:131–160  ·  view source on GitHub ↗

IntersectsCell reports whether this Polyline intersects the given Cell.

(cell Cell)

Source from the content-addressed store, hash-verified

129
130// IntersectsCell reports whether this Polyline intersects the given Cell.
131func (p *Polyline) IntersectsCell(cell Cell) bool {
132 if len(*p) == 0 {
133 return false
134 }
135
136 // We only need to check whether the cell contains vertex 0 for correctness,
137 // but these tests are cheap compared to edge crossings so we might as well
138 // check all the vertices.
139 if slices.ContainsFunc(*p, cell.ContainsPoint) {
140 return true
141 }
142
143 cellVertices := []Point{
144 cell.Vertex(0),
145 cell.Vertex(1),
146 cell.Vertex(2),
147 cell.Vertex(3),
148 }
149
150 for j := range 4 {
151 crosser := NewChainEdgeCrosser(cellVertices[j], cellVertices[(j+1)&3], (*p)[0])
152 for i := 1; i < len(*p); i++ {
153 if crosser.ChainCrossingSign((*p)[i]) != DoNotCross {
154 // There is a proper crossing, or two vertices were the same.
155 return true
156 }
157 }
158 }
159 return false
160}
161
162// ContainsPoint returns false since Polylines are not closed.
163func (p *Polyline) ContainsPoint(point Point) bool {

Callers 1

Calls 3

NewChainEdgeCrosserFunction · 0.85
ChainCrossingSignMethod · 0.80
VertexMethod · 0.45

Tested by 1