Skip to content

Commit

Permalink
libcore|Math: Added math functions: mod(), Vector2::cross()
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent f65e3ec commit 54dadc2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doomsday/libs/core/include/de/core/vector.h
Expand Up @@ -246,6 +246,9 @@ class Vector2
ddouble dot(Vector2 const &other) const {
return x * other.x + y * other.y;
}
ddouble cross(Vector2 const &other) const {
return x * other.y - y * other.x;
}
Vector2 min(Vector2 const &other) const {
return Vector2(de::min(x, other.x), de::min(y, other.y));
}
Expand Down
6 changes: 6 additions & 0 deletions doomsday/libs/core/include/de/math.h
Expand Up @@ -63,6 +63,12 @@ inline Type sign(Type a) {
if (a < 0) return Type(-1); else return Type(1);
}

template <typename Integer>
inline Integer mod(Integer a, Integer b) {
const Integer r = a % b;
return r < 0 ? (r + b) : r;
}

/// Minimum of two values.
template <typename Type>
inline Type min(Type a, Type b) {
Expand Down

0 comments on commit 54dadc2

Please sign in to comment.