aboutsummaryrefslogtreecommitdiff
path: root/source/Utils.cpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-04-17 20:08:57 -0700
committerrtk0c <[email protected]>2022-04-17 20:08:57 -0700
commit5424a1d5434e3ddd911a504719918c2df027e2fd (patch)
tree6275aab13140d81dcc46c8290e73ac9a8bbb5605 /source/Utils.cpp
parentafcac59c7d04f4337d6b04ebed8cac7e871ccc50 (diff)
Changeset: 8 Initial work on sprites and texture system
Diffstat (limited to 'source/Utils.cpp')
-rw-r--r--source/Utils.cpp17
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;
+}