From 1f1679b276ae1f9f0dccf9fe7572666132b57023 Mon Sep 17 00:00:00 2001 From: hanemile Date: Tue, 30 Oct 2018 15:23:47 +0100 Subject: add the containsPoint method that returns true if the given point is inside of the cell the method is called on. --- structs/structs.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 +} -- cgit 1.4.1