diff options
author | hanemile <hanemile@protonmail.com> | 2018-10-30 15:23:47 +0100 |
---|---|---|
committer | hanemile <hanemile@protonmail.com> | 2018-10-30 15:23:47 +0100 |
commit | 1f1679b276ae1f9f0dccf9fe7572666132b57023 (patch) | |
tree | d0d5ba3ad58a7f8e9eec9c4007361fffb2befcdf | |
parent | 74ca6c5f87b7ca29231c3666f8bc49296559b473 (diff) |
add the containsPoint method that returns true if the given point is
inside of the cell the method is called on.
-rw-r--r-- | structs/structs.go | 15 |
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 +} |