| 1 | /* |
| 2 | * LegacyClonk |
| 3 | * |
| 4 | * Copyright (c) 1998-2000, Matthes Bender (RedWolf Design) |
| 5 | * Copyright (c) 2017-2021, The LegacyClonk Team and contributors |
| 6 | * |
| 7 | * Distributed under the terms of the ISC license; see accompanying file |
| 8 | * "COPYING" for details. |
| 9 | * |
| 10 | * "Clonk" is a registered trademark of Matthes Bender, used with permission. |
| 11 | * See accompanying file "TRADEMARK" for details. |
| 12 | * |
| 13 | * To redistribute this file separately, substitute the full license texts |
| 14 | * for the above references. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include <cstdint> |
| 20 | |
| 21 | template <class T> inline T Abs(T val) { return val > 0 ? val : -val; } |
| 22 | template <class T> inline constexpr bool Inside(T ival, T lbound, T rbound) { return ival >= lbound && ival <= rbound; } |
| 23 | template <class T> inline T BoundBy(T bval, T lbound, T rbound) { return bval < lbound ? lbound : bval > rbound ? rbound : bval; } |
| 24 | template <class T> inline int Sign(T val) { return val < 0 ? -1 : val > 0 ? 1 : 0; } |
| 25 | template <class T> inline void Toggle(T &v) { v = !v; } |
| 26 | |
| 27 | inline int DWordAligned(int val) |
| 28 | { |
| 29 | if (val % 4) { val >>= 2; val <<= 2; val += 4; } |
| 30 | return val; |
| 31 | } |
| 32 | |
| 33 | int32_t Distance(int32_t iX1, int32_t iY1, int32_t iX2, int32_t iY2); |
| 34 | int Angle(int iX1, int iY1, int iX2, int iY2); |
| 35 | int Pow(int base, int exponent); |
| 36 | |