Refactor and reformat
This commit is contained in:
parent
8d31a13c30
commit
35c0cc4446
2 changed files with 23 additions and 18 deletions
15
src/Lib.hs
15
src/Lib.hs
|
@ -1,11 +1,6 @@
|
|||
module Lib (
|
||||
gravity,
|
||||
Body,
|
||||
bodyName,
|
||||
bodyRadius,
|
||||
bodyMass,
|
||||
bodyPosition,
|
||||
bodySpeed,
|
||||
Body(..),
|
||||
bodyDistance,
|
||||
field,
|
||||
acceleration,
|
||||
|
@ -55,14 +50,14 @@ bodyDistance body1 body2 =
|
|||
-- Field created by a body on a certain position
|
||||
field :: Body -> Point V3 Double -> V3 Double
|
||||
field body pos =
|
||||
unP $ (gravity * m / r**2) *^ (normalize vec)
|
||||
unP $ (gravity * m / r**2) *^ normalize vec
|
||||
where m = bodyMass body
|
||||
vec = (bodyPosition body) - pos
|
||||
vec = bodyPosition body - pos
|
||||
r = norm vec
|
||||
|
||||
-- Acceleration given to a body by its neighbours
|
||||
acceleration :: Body -> [Body] -> V3 Double
|
||||
acceleration body = foldr f (fromInteger 0)
|
||||
acceleration body = foldr f 0
|
||||
where f neighbour acc =
|
||||
acc + field neighbour (bodyPosition body)
|
||||
|
||||
|
@ -81,7 +76,7 @@ update dt (Body name r m pos speed) neighbours =
|
|||
|
||||
-- Update all bodies with a timestep dt
|
||||
updateAll :: Double -> [Body] -> [Body]
|
||||
updateAll dt bodies = aux [] [] bodies
|
||||
updateAll dt = aux [] []
|
||||
where
|
||||
-- Cycles through all bodies, updates each one and stores it in
|
||||
-- res. Each body already updated is moved to prev.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue