IntersectsCell reports whether this Polyline intersects the given Cell.
(cell Cell)
| 129 | |
| 130 | // IntersectsCell reports whether this Polyline intersects the given Cell. |
| 131 | func (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. |
| 163 | func (p *Polyline) ContainsPoint(point Point) bool { |