From 59f43b4498fc35a52eee859db07f6b15fc4e2ab3 Mon Sep 17 00:00:00 2001 From: emile Date: Mon, 8 Oct 2018 15:54:09 +0200 Subject: Not exporting the forces function anymore, because the CalcAllForces function is accessing it. The CalcAllFucntion calculates all the forces acting in between the stars in the given Slice and returns the slice with the forces stored in the star structs. --- forces/forces.go | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/forces/forces.go b/forces/forces.go index 6869630..5d0c414 100644 --- a/forces/forces.go +++ b/forces/forces.go @@ -31,7 +31,7 @@ func forceActing(s1 structs.Star, s2 structs.Star) structs.Force { } // forces calculates the forces acting in between a given star and all the other stars in a given array. -func Forces(stars_arr []structs.Star, nr int) structs.Force { +func forces(stars_arr []structs.Star, nr int) structs.Force { var force structs.Force @@ -53,3 +53,30 @@ func Forces(stars_arr []structs.Star, nr int) structs.Force { return force } + +func CalcAllForces(starSlice []structs.Star) []structs.Star { + + // Define a new slice in which the stars (and the forces acting on them) should be saved + var new_slice []structs.Star + + // Iterate over all the stars in the original slice + for index := range starSlice { + + // Calculate the force acting inbetween the given star and all other stars + // This utilizes go-routines :D + var force = forces(starSlice, index) + + // create a new star + current_star := structs.Star{ + structs.Coord{starSlice[index].C.X, starSlice[index].C.Y}, + structs.Force{force.X, force.Y}, + starSlice[index].Mass, + } + + // append the new star to the new slice + new_slice = append(new_slice, current_star) + + } + + return new_slice +} -- cgit 1.4.1