Skip to content

Commit

Permalink
improve many body performance
Browse files Browse the repository at this point in the history
  • Loading branch information
li3zhen1 committed Oct 10, 2023
1 parent 18b4eed commit ecce85e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions Sources/ForceSimulation/forces/ManyBodyForce.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ final public class ManyBodyForce<N>: Force where N: Identifiable {
}
}

var theta2: Float = 0.1
var theta2: Float = 0.81
var theta: Float { theta2.squareRoot() }

var distanceMin2: Float = 0.1
var distanceMin2: Float = 0.01
var distanceMax2: Float = Float.infinity

internal init(
Expand Down Expand Up @@ -227,8 +227,7 @@ final public class ManyBodyForce<N>: Force where N: Identifiable {
if quadNode.isLeaf || (distanceSquared * self.theta2 > quadNode.quad.area) {

forces[i] +=
self.strength * alpha * quadNode.quadDelegate.accumulatedProperty * vec
/ pow(distanceSquared, 1.5)
self.strength * alpha * quadNode.quadDelegate.accumulatedProperty * vec / distanceSquared / sqrt(distanceSquared)

return false
} else {
Expand Down
4 changes: 2 additions & 2 deletions Tests/ForceSimulationTests/MiserableGraphTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ final class MiserableGraphTest: XCTestCase {
let collideForce = sim.createCollideForce(radius: .constant(5))

// sim.tick()
measure {
measure {
for _ in 0..<120{
sim.tick()
}
}
}
sim.tick()
// print(sim.simulationNodes)

Expand Down

0 comments on commit ecce85e

Please sign in to comment.