about summary refs log tree commit diff
path: root/structs/star.go
diff options
context:
space:
mode:
Diffstat (limited to 'structs/star.go')
-rw-r--r--structs/star.go56
1 files changed, 54 insertions, 2 deletions
diff --git a/structs/star.go b/structs/star.go
index f495d99..d2bb124 100644
--- a/structs/star.go
+++ b/structs/star.go
@@ -1,7 +1,5 @@
 package structs
 
-import "C"
-
 // Define a struct storing essential star information such as it's coordinate, velocity and mass
 type Star2D struct {
 	C Vec2    // coordinates of the star
@@ -9,6 +7,60 @@ type Star2D struct {
 	M float64 // mass        of the star
 }
 
+// InsideOf is a method that tests if the star it is applied on is in or outside of the given
+// BoundingBox. It returns true if the star is inside of the BoundingBox and false if it isn't.
+func (s Star2D) InsideOf(boundary BoundingBox) bool {
+
+	// Test if the star is inside or outside of the bounding box.
+	// Abort testing if one of the conditions is not met
+	if s.C.X < boundary.center.X+boundary.width/2 {
+		if s.C.X > boundary.center.X-boundary.width/2 {
+			if s.C.Y < boundary.center.Y+boundary.width/2 {
+				if s.C.Y > boundary.center.Y-boundary.width/2 {
+					return true
+				} else {
+					return false
+				}
+			} else {
+				return false
+			}
+		} else {
+			return false
+		}
+	} else {
+		return false
+	}
+}
+
+// Quadrant returns a string indicating in which quadrant of the given quadtree the point the method
+// is applied on is.
+// This methods presumes that the point is inside of the boundingBox
+func (s Star2D) Quadrant(starsQuadtree *Quadtree) string {
+	centerX := starsQuadtree.boundary.center.X
+	centerY := starsQuadtree.boundary.center.Y
+
+	// test if the point is left the the center or not
+	if s.C.X < centerX {
+
+		// Test if the point is above or below of the center
+		if s.C.Y > centerY {
+			return "northwest"
+		} else {
+			return "southwest"
+		}
+
+		// The point is right of the center
+	} else {
+
+		// Test if the point is above or below of the center
+		if s.C.Y > centerY {
+			return "northeast"
+		} else {
+			return "southeast"
+		}
+	}
+}
+
 // Return a copy of the star by returning a star struct with the same values.
 func (s *Star2D) Copy() Star2D {
 	return Star2D{s.C.Copy(), s.V.Copy(), s.M}