title: GKRTree return all elements found overlapped with the specified bounding region?
body: <p>I'm trying to do this by using <code>GKRTree</code> in <code>GameKit</code>. What I did:</p>
  
  <ol>
  <li>Parsing data from GeoJson</li>
  <li>Add all polygons (MKPolygon) to an GKRTree</li>
  <li>In <code>regionDidChangeAnimated</code> delegate function, get all visible polygons from the <code>GKRTree</code> by using <code>elements</code> query.</li>
  </ol>
  
  <p>Based on Apple's document, <code>elements</code> query will return:</p>
  
  <blockquote>
    <p>An array of objects stored in the tree whose bounding regions overlap the specified region. The array is empty if no such objects are found.</p>
  </blockquote>
  
  <p>But unfortunately, this is not the case. This query will only return the objects <strong><em>contained</em></strong> instead of <strong><em>overlap</em></strong> the specified region.</p>
  
  <p>My code:</p>
  
  <pre><code>    // loading from GeoJson
      self.rtree = GKRTree&lt;MKPolygon&gt;(maxNumberOfChildren: 5)
      self.polygons = polygons
      polygons.forEach({ polygon in
        if let overlay = polygon.mapShape() as? MKPolygon {
  
          let rect = overlay.boundingMapRect
  
          let vecMin = vector_float2([Float(rect.minX),Float(rect.minY)])
          let vecMax = vector_float2([Float(rect.maxX), Float(rect.maxY)])
  
          self.rtree?.addElement(overlay, boundingRectMin: vecMin, boundingRectMax: vecMax, splitStrategy: GKRTreeSplitStrategy.linear)
        }
      })
  
  
  func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
      if let rtree = self.rtree {
        let rect = mapView.visibleMapRect
        let vecMin = vector_float2([Float(rect.minX),Float(rect.minY)])
        let vecMax = vector_float2([Float(rect.maxX), Float(rect.maxY)])
  
        let all = rtree.elements(inBoundingRectMin: vecMin, rectMax: vecMax)
        //print(all)
  
        mapView.removeOverlays(mapView.overlays)
        var overlays = [MKPolygon]()
        for polygon in all {
          overlays.append(polygon)
        }
        self.mapView.addOverlays(overlays)
      }
  </code></pre>
  
  <p>Please refer to my screenshots:</p>
  
  <p><a href="https://i.stack.imgur.com/ZmAEN.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZmAEN.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/3K7cL.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3K7cL.jpg" alt="enter image description here"></a></p>
  
  <p>Any idea? Thanks.</p>