             }
         }
         func intersects(index1: Int, index2: Int, callback: (Int, Int) -> Void) {
-            guard boxes[index1].overlaps(boxes[index2]) else {
+            guard self.boundingBoxes[index1].overlaps(self.boundingBoxes[index2]) else {
                 return // nothing to do
             }
             let leaf1 = index1 >= inodecount

            lastRowIndex += 1
        }
        self.lastRowIndex = lastRowIndex

        
        for i in 0..<leafBoxes.count {
            let nodeIndex = i+self.inodeCount


internal class BVH {
    
    fileprivate let boundingBoxes: UnsafePointer<BoundingBox>
    fileprivate var inodeCount: Int
    fileprivate var lastRowIndex: Int
    fileprivate var elementCount: Int
        
    var boundingBox: BoundingBox {
        return self.boundingBoxes[0]
    }
    
    fileprivate static func leafNodeIndexToElementIndex(_ nodeIndex: Int, leafCount: Int, lastRowIndex: Int) -> Int {
