about summary refs log tree commit diff
path: root/structs
diff options
context:
space:
mode:
authorhanemile <hanemile@protonmail.com>2018-10-30 15:23:47 +0100
committerhanemile <hanemile@protonmail.com>2018-10-30 15:23:47 +0100
commit1f1679b276ae1f9f0dccf9fe7572666132b57023 (patch)
treed0d5ba3ad58a7f8e9eec9c4007361fffb2befcdf /structs
parent74ca6c5f87b7ca29231c3666f8bc49296559b473 (diff)
add the containsPoint method that returns true if the given point is
inside of the cell the method is called on.
Diffstat (limited to 'structs')
-rw-r--r--structs/structs.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/structs/structs.go b/structs/structs.go
index 6f1dd57..b4b550a 100644
--- a/structs/structs.go
+++ b/structs/structs.go
@@ -16,3 +16,18 @@ type boundingBox struct {
 	center        coord
 	halfDimension float64
 }
+
+// containsPoint returns true if the given point is inside of the boundingBox the method is called on
+func (boundingBox *boundingBox) containsPoint(point coord) bool {
+	// find out if the point is in or outside of the box
+	if boundingBox.center.x-boundingBox.halfDimension < point.x && boundingBox.center.x+boundingBox.halfDimension > point.x {
+		if boundingBox.center.y-boundingBox.halfDimension < point.y && boundingBox.center.y+boundingBox.halfDimension > point.y {
+
+			// the point is inside of the cell -> return true
+			return true
+		}
+	}
+
+	// the point is outside of the cell -> return false
+	return false
+}