getCellsForEdge populates the cells field to the set of index cells intersected by an edge AB.
(a, b Point)
| 252 | |
| 253 | // getCellsForEdge populates the cells field to the set of index cells intersected by an edge AB. |
| 254 | func (c *CrossingEdgeQuery) getCellsForEdge(a, b Point) { |
| 255 | c.cells = nil |
| 256 | |
| 257 | segments := FaceSegments(a, b) |
| 258 | for _, segment := range segments { |
| 259 | c.a = segment.a |
| 260 | c.b = segment.b |
| 261 | |
| 262 | // Optimization: rather than always starting the recursive subdivision at |
| 263 | // the top level face cell, instead we start at the smallest S2CellId that |
| 264 | // contains the edge (the edge root cell). This typically lets us skip |
| 265 | // quite a few levels of recursion since most edges are short. |
| 266 | edgeBound := r2.RectFromPoints(c.a, c.b) |
| 267 | pcell := PaddedCellFromCellID(CellIDFromFace(segment.face), 0) |
| 268 | edgeRoot := pcell.ShrinkToFit(edgeBound) |
| 269 | |
| 270 | // Now we need to determine how the edge root cell is related to the cells |
| 271 | // in the spatial index (cellMap). There are three cases: |
| 272 | // |
| 273 | // 1. edgeRoot is an index cell or is contained within an index cell. |
| 274 | // In this case we only need to look at the contents of that cell. |
| 275 | // 2. edgeRoot is subdivided into one or more index cells. In this case |
| 276 | // we recursively subdivide to find the cells intersected by AB. |
| 277 | // 3. edgeRoot does not intersect any index cells. In this case there |
| 278 | // is nothing to do. |
| 279 | relation := c.iter.LocateCellID(edgeRoot) |
| 280 | switch relation { |
| 281 | case Indexed: |
| 282 | // edgeRoot is an index cell or is contained by an |
| 283 | // index cell (case 1). |
| 284 | c.cells = append(c.cells, c.iter.IndexCell()) |
| 285 | case Subdivided: |
| 286 | // edgeRoot is subdivided into one or more index cells |
| 287 | // (case 2). We find the cells intersected by AB using |
| 288 | // recursive subdivision. |
| 289 | if !edgeRoot.isFace() { |
| 290 | pcell = PaddedCellFromCellID(edgeRoot, 0) |
| 291 | } |
| 292 | c.computeCellsIntersected(pcell, edgeBound) |
| 293 | case Disjoint: |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | // computeCellsIntersected computes the index cells intersected by the current |
| 299 | // edge that are descendants of pcell and adds them to this queries set of cells. |
no test coverage detected