             let dq = quad.center - node.position
             let distance = dq.magnitude
             let direction = dq.normalized
-            node.force = node.force + direction * repulsion * CGFloat(quad.count) / (distance * distance * 0.5)
+            if let max = maxDistance {
+                if distance < max(node) {
+                    node.force = node.force + direction * repulsion * CGFloat(quad.count) / (distance * distance * 0.5)
+                }
+            }
+            else {
+                node.force = node.force + direction * repulsion * CGFloat(quad.count) / (distance * distance * 0.5)
+            }
         }
     }
 }
    }
    
    private func applyBarnesHut(node: Node, quad: Quad<Node>) {
        let s = (quad.bounds.width + quad.bounds.height)/2
        let d = (quad.center - node.position).magnitude
        

        repulsion = value
        return self
    }
    
    private(set) public var minDistance: (Node) -> CGFloat = { _ in 1 }
    public func minDistance(value: CGFloat) -> NBody {
        // TODO: enforce no negative values
        minDistance = { _ in value }
        return self
    }
    public func minDistance(closure: (Node) -> CGFloat) -> NBody {
        minDistance = closure
        return self
    }
    
    private(set) public var maxDistance: ((Node) -> CGFloat)? = nil
    public func maxDistance(value: CGFloat) -> NBody {
        // TODO: enforce no negative values
        maxDistance = { _ in value }
        return self
    }
    public func maxDistance(closure: ((Node) -> CGFloat)?) -> NBody {
        maxDistance = closure
        return self
    }
    
    
    /// Range of [0,1]
    private(set) public var theta: CGFloat = 0.8
