about summary refs log tree commit diff
path: root/forces
diff options
context:
space:
mode:
authoremile <hanemile@protonmail.com>2018-10-10 21:44:48 +0200
committeremile <hanemile@protonmail.com>2018-10-10 21:44:48 +0200
commit2d1492140872c51093e3ca11d9935ef78e919b63 (patch)
tree45e4c9cb95143f8eb8c8dcabe43b86f85cf88556 /forces
parent8dabefde6078790689e35abdba3952e53042c0cc (diff)
added forcesThread function working as a go worker in gothreads
Diffstat (limited to 'forces')
-rw-r--r--forces/forces.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/forces/forces.go b/forces/forces.go
index 03c6c7a..5eaff5f 100644
--- a/forces/forces.go
+++ b/forces/forces.go
@@ -56,6 +56,28 @@ func forces(stars_arr []structs.Star, nr int) structs.Force {
 	return force
 }
 
+// forcesThread calculates the forces acting on a given amount of stars in a given range for a given slice of stars
+// as a go-routine
+func forcesThread(starSlice []structs.Star, localRangeStart int, localRangeEnd int, channel chan structs.Star) {
+
+	// iterate over the given range
+	for index := localRangeStart; index < localRangeEnd; index++ {
+
+		// Calculate the force acting inbetween the given star and all other stars
+		var force = forces(starSlice, index)
+
+		// create a new star
+		newStar := structs.Star{
+			structs.Coord{starSlice[index].C.X, starSlice[index].C.Y},
+			structs.Force{force.X, force.Y},
+			starSlice[index].Mass,
+		}
+
+		// push the new Star into the channel
+		channel <- newStar
+	}
+}
+
 // CalcAllForces calculates all the forces acting inbetween all the stars in the given starSlice slice and
 // returns a "new" slice contaning the forces
 func CalcAllForces(starSlice []structs.Star) []structs.Star {