MyMath.h revision cae46a08a948c1f6fa3736b5449b8d8c56d92d1f
/*
* MyMath.h
* nlivarot
*
* Created by fred on Wed Jun 18 2003.
*
*/
#ifndef my_math
#define my_math
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#else
# ifdef HAVE_STDINT_H
# include <stdint.h>
# endif
#endif
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
typedef struct vec2
{
double x, y;
} vec2;
typedef struct mat2
{
} mat2;
typedef struct vec2d
{
double x, y;
} vec2d;
typedef struct mat2d
{
} mat2d;
#define RotCCW(a) {\
double t = (a).x;\
(a).x = (a).y;\
(a).y = -t;\
}
#define RotCCWTo(a,d) {\
(d).x = (a).y;\
(d).y = -(a).x;\
}
#define RotCW(a) {\
double t = (a).x;\
(a).x = -(a).y;\
(a).y = t;\
}
#define RotCWTo(a,d) {\
(d).x = -(a).y;\
(d).y = (a).x;\
}
#define Normalize(a) { \
double _le = (a).x*(a).x+(a).y*(a).y; \
if ( _le > 0.0001 ) { \
(a).x *= _le; \
(a).y *= _le; \
} \
}
#define L_VEC_Set(a,u,v) { \
a.x = u; \
a.y = v; \
}
#define L_VEC_Length(a,l) { \
l = sqrt(a.x*a.x+a.y*a.y); \
}
#define L_VEC_Add(a,b,r) { \
r.x = a.x+b.x; \
r.y = a.y+b.y; \
}
#define L_VEC_Sub(a,b,r) { \
r.x = a.x-b.x; \
r.y = a.y-b.y; \
}
#define L_VEC_Mul(a,b,r) { \
r.x = a.x*b.x; \
r.y = a.y*b.y; \
}
#define L_VEC_Div(a,b,r) { \
r.x = a.x/b.x; \
r.y = a.y/b.y; \
}
#define L_VEC_AddMul(a,b,c,r) { \
r.x = a.x+b.x*c.x; \
r.y = a.y+b.y*c.y; \
}
#define L_VEC_SubMul(a,b,c,r) { \
r.x = a.x-b.x*c.x; \
r.y = a.y-b.y*c.y; \
}
#define L_VEC_MulC(a,b,r) { \
r.x = a.x*(b); \
r.y = a.y*(b); \
}
#define L_VEC_DivC(a,b,r) { \
r.x = a.x/(b); \
r.y = a.y/(b); \
}
#define L_VEC_AddMulC(a,b,c,r) { \
r.x = a.x+b.x*c; \
r.y = a.y+b.y*c; \
}
#define L_VEC_SubMulC(a,b,c,r) { \
r.x = a.x-b.x*c; \
r.y = a.y-b.y*c; \
}
((a.y > b.y)?1:-1))
#define L_VEC_Normalize(d) { \
double l=sqrt(d.x*d.x+d.y*d.y); \
if ( l < 0.00000001 ) { \
d.x=d.y=0; \
} else { \
d.x/=l; \
d.y/=l; \
} \
}
#define L_VEC_Distance(a,b,d) { \
double dx = a.x-b.x; \
double dy = a.y-b.y; \
}
#define L_VEC_Neg(d) { \
d.x=d.x; d.y=-d.y; \
}
#define L_VEC_RotCW(d) { \
double t=d.x; d.x=d.y; d.y=-t; \
} \
#define L_VEC_RotCCW(d) { \
double t=d.x; d.x=-d.y; d.y=t; \
}
#define L_VEC_Cross(a,b,r) { \
r = a.x*b.x+a.y*b.y; \
}
#define L_VEC_Dot(a,b,r) { \
r = a.x*b.y-a.y*b.x; \
}
#define L_MAT(m,a,b) { \
}
if ( no == 0 ) { \
r.x = m.xx; \
r.y = m.yx; \
} \
if ( no == 0 ) { \
r.x = m.xy; \
r.y = m.yy; \
} \
}
if ( no == 0 ) { \
r.x = m.xx; \
r.y = m.xy; \
} \
if ( no == 0 ) { \
r.x = m.yx; \
r.y = m.yy; \
} \
}
#define L_MAT_Inv(m) { \
double d; \
L_MAT_Det(m,d); \
double inv_d = 1.0/d; \
}
#define L_MAT_Cof(m) { \
}
#define L_MAT_Add(u,v,m) { \
}
#define L_MAT_Sub(u,v,m) { \
}
#define L_MAT_Mul(u,v,m) { \
mat2d r; \
m=r; \
}
#define L_MAT_MulC(u,v,m) { \
}
#define L_MAT_DivC(u,v,m) { \
double iv = 1.0/v; \
}
#define L_MAT_MulV(m,v,r) { \
vec2d t; \
r=t; \
}
#define L_MAT_TMulV(m,v,r) { \
vec2d t; \
r=t; \
}
#endif