diff options
Diffstat (limited to 'source/Utils.cpp')
-rw-r--r-- | source/Utils.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/source/Utils.cpp b/source/Utils.cpp index d47f35b..5083eb7 100644 --- a/source/Utils.cpp +++ b/source/Utils.cpp @@ -56,3 +56,20 @@ FILE* Utils::OpenCstdioFile(const char* path, IoMode mode, bool binary) { return fopen(path, ::GetModeString(mode, binary)); #endif } + +bool Utils::InRangeInclusive(int n, int lower, int upper) { + if (lower > upper) { + std::swap(lower, upper); + } + return n >= lower && n <= upper; +} + +bool Utils::LineContains(glm::ivec2 p1, glm::ivec2 p2, glm::ivec2 candidate) { + bool verticalLine = p1.x == p2.x && InRangeInclusive(candidate.x, p1.x, p2.x); + bool horizontalLine = p1.y == p2.y && InRangeInclusive(candidate.y, p1.y, p2.y); + return verticalLine && horizontalLine; +} + +bool Utils::IsColinear(glm::ivec2 p1, glm::ivec2 p2) { + return p1.x == p2.x || p1.y == p2.y; +} |