Files
MapLibreParticleLab/include/llmr/util/math.hpp
Konstantin Käfer 117078270d add text buffer code
2014-03-14 11:36:10 +01:00

45 lines
816 B
C++

#ifndef LLMR_UTIL_MATH
#define LLMR_UTIL_MATH
#include <cmath>
#include "vec.hpp"
namespace llmr {
namespace util {
template <typename T>
inline T max(T a, T b) {
return b > a ? b : a;
}
template <typename T>
inline T min(T a, T b) {
return b < a ? b : a;
}
inline double angle_between(double ax, double ay, double bx, double by) {
return atan2((ax * by - ay * bx), ax * bx + ay * by);
}
template <typename T, typename S1, typename S2>
inline vec2<T> normal(const S1& a, const S2& b) {
T dx = b.x - a.x;
T dy = b.y - a.y;
T c = sqrt(dx * dx + dy * dy);
return { dx / c, dy / c };
}
template <typename T, typename S1, typename S2>
inline T dist(const S1& a, const S2& b) {
T dx = b.x - a.x;
T dy = b.y - a.y;
T c = sqrt(dx * dx + dy * dy);
return c;
}
}
}
#endif