15#define M_PI 3.14159265358979323846
18#define M_SQRT2 1.41421356237309504880
21#define M_SQRTPI 1.77245385090551602792981
24#define M_TWOPI (M_PI * 2.0)
27#define DBL_MAX (1E+37)
30#define M_SQRT1_2 0.70710678118654752440
33#define M_SQRT3_OVER_2 0.866025403784439
36#define M_SQRT2PI 2.50662827463100
39#define M_PI_2 1.57079632679489661923
42#define M_PI_3 1.04719755119660
45#define M_PI_4 0.78539816339744830962
49#define ROUND_INT(x) (((x) >= 0) ? ((long)((x)+0.5)) : (long)(-(-(x)+0.5)))
52#define FLOOR_PLM_LONG(x) ((plm_long) floor (x))
53#define ROUND_PLM_LONG(x) \
54 (((x) >= 0) ? ((plm_long)((x)+0.5)) : (plm_long)(-(-(x)+0.5)))
57#define FLOOR_SIZE_T(x) (((x) >= 0) ? ((size_t)(x)) : 0)
58#define ROUND_SIZE_T(x) (((x) >= 0) ? ((size_t)((x)+0.5)) : 0)
61#define ROUND(x) ((double) (ROUND_INT(x)))
64#define SIGN(x) (((x) >= 0) ? (+1) : (-1))
69#if !defined (_M_IA64) && !defined (_M_AMD64) && defined (_WIN32)
72#define logf(x) ((float)log((double)(x)))
78#define FLOAT_SMALL_VECTOR_LENGTH 1e-6
81static inline double exp10_ (
double m) {
82 return exp (2.3025850929940456840179914546844 * m);
86static inline void vec2_add2 (
double* v1,
const double* v2) {
87 v1[0] += v2[0]; v1[1] += v2[1];
90static inline void vec3_add2 (
double* v1,
const double* v2) {
91 v1[0] += v2[0]; v1[1] += v2[1]; v1[2] += v2[2];
94static inline void vec3_add3 (
double* v1,
const double* v2,
const double* v3) {
95 v1[0] = v2[0] + v3[0]; v1[1] = v2[1] + v3[1]; v1[2] = v2[2] + v3[2];
98template<
class T>
static inline void
100 v1[0] += v2[0]; v1[1] += v2[1]; v1[2] += v2[2];
103template<
class T>
static inline void
105 v1[0] = v2[0] + v3[0]; v1[1] = v2[1] + v3[1]; v1[2] = v2[2] + v2[2];
108template<
class T>
static inline void
110 v1[0] = v2[0]; v1[1] = v2[1]; v1[2] = v2[2];
113static inline void vec4_copy (
double* v1,
const double* v2) {
114 v1[0] = v2[0]; v1[1] = v2[1]; v1[2] = v2[2]; v1[3] = v2[3];
117template<
class T>
static inline T
119 return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2];
122template<
class T,
class U>
static inline float
124 return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2];
127static inline double vec4_dot (
const double* v1,
const double* v2) {
128 return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2] + v1[3] * v2[3];
132 v1[0] *= a; v1[1] *= a; v1[2] *= a;
135template<
class T,
class U>
static inline void
137 v1[0] = a * v2[0]; v1[1] = a * v2[1]; v1[2] = a * v2[2];
140template<
class T>
static inline void
142 v1[0] -= v2[0]; v1[1] -= v2[1]; v1[2] -= v2[2];
145template<
class T,
class U,
class V>
static inline void
147 v1[0] = v2[0] - v3[0]; v1[1] = v2[1] - v3[1]; v1[2] = v2[2] - v3[2];
155 memset (v1, 0, n*
sizeof(
double));
159template<
class T>
static inline T
166template<>
inline double
171template<>
inline float
180template<
class T>
static inline T
187template<
class T>
static inline T
195template<
class T>
static inline void
198 v1[0] = v2[1] * v3[2] - v2[2] * v3[1];
199 v1[1] = v2[2] * v3[0] - v2[0] * v3[2];
200 v1[2] = v2[0] * v3[1] - v2[1] * v3[0];
204static inline void vec_outer (
double* v1,
const double* v2,
const double* v3,
const int n)
207 for (j=0; j<n; j++) {
208 for (i=0; i<n; i++) {
209 v1[n*j + i] = v2[j] * v3[i];
217#define m_idx(m1,c,i,j) m1[i*c+j]
229 const double* m2,
int m2_rows,
int m2_cols,
230 const double* m3,
int m3_rows,
int m3_cols)
234 for (i = 0; i < m2_rows; i++) {
235 for (j = 0; j < m3_cols; j++) {
237 for (k = 0; k < m2_cols; k++) {
238 acc +=
m_idx(m2,m2_cols,i,k) *
m_idx(m3,m3_cols,k,j);
240 m_idx(m1,m3_cols,i,j) = acc;
249 if (!(x == x))
return 0;
253#if defined (commentout)
254 if (std::numeric_limits<double>::has_infinity &&
255 x == std::numeric_limits<double>::infinity())
265clamp (T value, T min_value, T max_value) {
266 if (value < min_value)
return min_value;
267 if (value > max_value)
return max_value;
273 return (v1 > v2) ? v1 : v2;
278 return (v1 < v2) ? v1 : v2;
283 return degrees *
M_PI / 180.;
291 return (fabsf (value - comp_value) <= tolerance);
294#define NLMIN(T) (-std::numeric_limits<T>::max())
295#define NLMAX(T) std::numeric_limits<T>::max()
#define UNUSED_VARIABLE(a)
Definition compiler_warnings.h:7
static void mat_mult_mat(double *m1, const double *m2, int m2_rows, int m2_cols, const double *m3, int m3_rows, int m3_cols)
Definition plm_math.h:227
static void vec_zero(double *v1, int n)
Definition plm_math.h:154
static void vec3_sub3(T *v1, const U *v2, const V *v3)
Definition plm_math.h:146
static T vec3_lensq(const T *v1)
Definition plm_math.h:160
static int is_number(const double x)
Definition plm_math.h:246
static void vec3_copy(T *v1, const T *v2)
Definition plm_math.h:109
static T vec3_len(const T *)
static void vec3_add3(double *v1, const double *v2, const double *v3)
Definition plm_math.h:94
static void vec3_invert(double *v1)
Definition plm_math.h:150
float vec3_len< float >(const float *v1)
Definition plm_math.h:172
static void mat43_mult_vec4(double *v1, const double *m2, const double *v3)
Definition plm_math.h:220
static void vec3_scale3(T *v1, const T *v2, U a)
Definition plm_math.h:136
T plm_max(T v1, T v2)
Definition plm_math.h:272
T clamp(T value, T min_value, T max_value)
Definition plm_math.h:265
static T vec3_dot(const T *v1, const T *v2)
Definition plm_math.h:118
static void vec3_add(T *v1, const T *v2)
Definition plm_math.h:99
static void vec4_copy(double *v1, const double *v2)
Definition plm_math.h:113
static bool within_abs_tolerance(float value, float comp_value, float tolerance)
Definition plm_math.h:289
static void vec3_add2(double *v1, const double *v2)
Definition plm_math.h:90
static double vec4_dot(const double *v1, const double *v2)
Definition plm_math.h:127
static void vec3_scale2(double *v1, double a)
Definition plm_math.h:131
static T vec3_distsq(const T *v1, const T *v2)
Definition plm_math.h:181
static void vec3_sub2(T *v1, const T *v2)
Definition plm_math.h:141
T plm_min(T v1, T v2)
Definition plm_math.h:277
static double exp10_(double m)
Definition plm_math.h:81
static void vec3_normalize1(double *v1)
Definition plm_math.h:176
static T vec3_dist(const T *v1, const T *v2)
Definition plm_math.h:188
#define m_idx(m1, c, i, j)
Definition plm_math.h:217
#define M_PI
Definition plm_math.h:15
static void vec3_cross(T *v1, const T *v2, const T *v3)
Definition plm_math.h:196
T radians_from_degrees(T degrees)
Definition plm_math.h:282
static void vec_outer(double *v1, const double *v2, const double *v3, const int n)
Definition plm_math.h:204
static void vec2_add2(double *v1, const double *v2)
Definition plm_math.h:86
#define DBL_MAX
Definition plm_math.h:27