             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
        

                    let distance = db.magnitude
                    let direction = db.normalized
                    
                    if distance > minDistance(node) {
                        if let max = maxDistance {
                            if distance < max(node) {
                                node.force = node.force + direction * repulsion / (distance * distance * 0.5)
                            }
                        }
                        else {
                            node.force = node.force + direction * repulsion / (distance * distance * 0.5)
                        }
                    }
                }
            }
        }
