diff --git a/include/bx/bx.h b/include/bx/bx.h index 7139af9..a87a9b0 100644 --- a/include/bx/bx.h +++ b/include/bx/bx.h @@ -35,24 +35,37 @@ namespace bx template bool isEnabled(); - /// - bool ignoreC4127(bool _x); - - /// + /// Exchange two values. template void xchg(Ty& _a, Ty& _b); - /// + /// Exchange memory. void xchg(void* _a, void* _b, size_t _numBytes); - /// + /// Returns minimum of two values. template Ty min(const Ty& _a, const Ty& _b); - /// + /// Returns maximum of two values. template Ty max(const Ty& _a, const Ty& _b); + /// Returns minimum of three values. + template + Ty min(const Ty& _a, const Ty& _b, const Ty& _c); + + /// Returns maximum of three values. + template + Ty max(const Ty& _a, const Ty& _b, const Ty& _c); + + /// Returns middle of three values. + template + Ty mid(const Ty& _a, const Ty& _b, const Ty& _c); + + /// Returns clamped value between min/max. + template + Ty clamp(const Ty& _a, const Ty& _min, const Ty& _max); + // http://cnicholson.net/2011/01/stupid-c-tricks-a-better-sizeof_array/ template char (&COUNTOF_REQUIRES_ARRAY_ARGUMENT(const T(&)[N]) )[N]; diff --git a/include/bx/inline/bx.inl b/include/bx/inline/bx.inl index ed6f63b..70a6e6d 100644 --- a/include/bx/inline/bx.inl +++ b/include/bx/inline/bx.inl @@ -44,4 +44,28 @@ namespace bx return _a > _b ? _a : _b; } + template + inline Ty min(const Ty& _a, const Ty& _b, const Ty& _c) + { + return min(min(_a, _b), _c); + } + + template + inline Ty max(const Ty& _a, const Ty& _b, const Ty& _c) + { + return max(max(_a, _b), _c); + } + + template + inline Ty mid(const Ty& _a, const Ty& _b, const Ty& _c) + { + return max(min(_a, _b), min(max(_a, _b), _c) ); + } + + template + inline Ty clamp(const Ty& _a, const Ty& _min, const Ty& _max) + { + return max(min(_a, _max), _min); + } + } // namespace bx