Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/charisee/src/include/Diderot/inline-vec2.h
ViewVC logotype

Diff of /branches/charisee/src/include/Diderot/inline-vec2.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1370, Wed Jun 22 21:11:20 2011 UTC revision 1640, Wed Nov 16 02:19:51 2011 UTC
# Line 17  Line 17 
17  #include "Diderot/types.h"  #include "Diderot/types.h"
18  #endif  #endif
19    
20  STATIC_INLINE vec2f_t vec2f (float a, float b)  STATIC_INLINE Diderot_vec2_t vec2 (Diderot_real_t a, Diderot_real_t b)
21  {  {
22  #ifdef VEC2_OK  #ifdef VEC2_OK
23      return __extension__ (vec2f_t){ a, b };      return __extension__ (Diderot_vec2_t){ a, b };
24  #else  #else
25      return __extension__ (vec2f_t){ a, b, 0.0, 0.0 };      return __extension__ (Diderot_vec2_t){ a, b, 0.0, 0.0 };
26  #endif  #endif
27  }  }
28    
29  STATIC_INLINE vec2i_t vec2ftoi (vec2f_t v)  STATIC_INLINE Diderot_ivec2_t vec2rtoi (Diderot_vec2_t v)
30  {  {
31      union2f_t u;      Diderot_union2_t u;
32      u.v = v;      u.v = v;
33  #ifdef VEC2_OK  #ifdef VEC2_OK
34      return __extension__ (vec2i_t){ (int32_t)u.r[0], (int32_t)u.r[1] };      return __extension__ (Diderot_ivec2_t){ (Diderot_int_t)u.r[0], (Diderot_int_t)u.r[1] };
35  #else  #else
36      return __extension__ (vec2i_t){ (int32_t)u.r[0], (int32_t)u.r[1], 0, 0 };      return __extension__ (Diderot_ivec2_t){ (Diderot_int_t)u.r[0], (Diderot_int_t)u.r[1], 0, 0 };
37  #endif  #endif
38  }  }
39    
40  STATIC_INLINE vec2f_t vec2itof (vec2i_t v)  STATIC_INLINE Diderot_vec2_t vec2itor (Diderot_ivec2_t v)
41  {  {
42      union2i_t u;      union2i_t u;
43      u.v = v;      u.v = v;
44  #ifdef VEC2_OK  #ifdef VEC2_OK
45      return __extension__ (vec2f_t){ (float)u.i[0], (float)u.i[1] };      return __extension__ (Diderot_vec2_t){ (Diderot_real_t)u.i[0], (Diderot_real_t)u.i[1] };
46  #else  #else
47      return __extension__ (vec2f_t){ (float)u.i[0], (float)u.i[1], (float)u.i[2], 0 };      return __extension__ (Diderot_vec2_t){ (Diderot_real_t)u.i[0], (Diderot_real_t)u.i[1], (Diderot_real_t)u.i[2], 0 };
48  #endif  #endif
49  }  }
50    
51  STATIC_INLINE vec2f_t scale2f (float s, vec2f_t v)  STATIC_INLINE Diderot_vec2_t scale2 (Diderot_real_t s, Diderot_vec2_t v)
52  {  {
53      return vec2f(s, s) * v;      return vec2(s, s) * v;
54  }  }
55    
56  STATIC_INLINE vec2f_t clamp2f (vec2f_t lo, vec2f_t hi, vec2f_t v)  STATIC_INLINE Diderot_vec2_t clamp2 (Diderot_vec2_t lo, Diderot_vec2_t hi, Diderot_vec2_t v)
57  {  {
58    // FIXME: there is probably a vectorized way to compute this    // FIXME: there is probably a vectorized way to compute this
59      union2f_t a, b, c;      Diderot_union2_t a, b, c;
60      a.v = lo; b.v = hi; c.v = v;      a.v = lo; b.v = hi; c.v = v;
61      return vec2f(      return vec2(
62          clampf(a.r[0], b.r[0], c.r[0]),          clamp(a.r[0], b.r[0], c.r[0]),
63          clampf(a.r[1], b.r[1], c.r[1]));          clamp(a.r[1], b.r[1], c.r[1]));
64  }  }
65    
66  STATIC_INLINE vec2f_t lerp2f (vec2f_t a, vec2f_t b, float t)  STATIC_INLINE Diderot_vec2_t lerp2 (Diderot_vec2_t a, Diderot_vec2_t b, Diderot_real_t t)
67  {  {
68      return a + scale2f(t, b - a);      return a + scale2(t, b - a);
69  }  }
70    
71  STATIC_INLINE vec2f_t floor2f (vec2f_t v)  STATIC_INLINE Diderot_vec2_t floor2 (Diderot_vec2_t v)
72  {  {
73      union2f_t u;      Diderot_union2_t u;
74      u.v = v;      u.v = v;
75      return vec2f(floorf(u.r[0]), floorf(u.r[1]));      return vec2(FLOOR(u.r[0]), FLOOR(u.r[1]));
76  }  }
77    
78  STATIC_INLINE vec2i_t truncToInt2f (vec2f_t v)  STATIC_INLINE Diderot_ivec2_t truncToInt2 (Diderot_vec2_t v)
79  {  {
80      union2f_t t;      Diderot_union2_t t;
81      t.v = v;      t.v = v;
82  #ifdef VEC2_OK  #ifdef VEC2_OK
83      return __extension__ (vec2i_t){      return __extension__ (Diderot_ivec2_t){
84          (int32_t)truncf(t.r[0]),          (Diderot_int_t)TRUNC(t.r[0]),
85          (int32_t)truncf(t.r[1]) };          (Diderot_int_t)TRUNC(t.r[1]) };
86  #else  #else
87      return __extension__ (vec2i_t){      return __extension__ (Diderot_ivec2_t){
88          (int32_t)truncf(t.r[0]),          (Diderot_int_t)TRUNC(t.r[0]),
89          (int32_t)truncf(t.r[1]),          (Diderot_int_t)TRUNC(t.r[1]),
90          0,          0,
91          0 };          0 };
92  #endif  #endif
93  }  }
94    
95  STATIC_INLINE float dot2f (vec2f_t u, vec2f_t v)  STATIC_INLINE Diderot_real_t dot2 (Diderot_vec2_t u, Diderot_vec2_t v)
96  {  {
97      union2f_t uv = __extension__ (union2f_t)(u*v);      Diderot_union2_t uv = __extension__ (Diderot_union2_t)(u*v);
98      return uv.r[0] + uv.r[1];      return uv.r[0] + uv.r[1];
99  }  }
100    
101  STATIC_INLINE float length2f (vec2f_t v)  STATIC_INLINE Diderot_real_t length2 (Diderot_vec2_t v)
102  {  {
103      return sqrtf(dot2f(v, v));      return SQRT(dot2(v, v));
104  }  }
105    
106  STATIC_INLINE vec2f_t normalize2f (vec2f_t v)  STATIC_INLINE Diderot_vec2_t normalize2 (Diderot_vec2_t v)
107  {  {
108      return scale2f(1.0 / length2f(v), v);      return scale2(1.0 / length2(v), v);
109  }  }
110    
111  #endif /* !_DIDEROT_INLINE_VEC2_H_ */  #endif /* !_DIDEROT_INLINE_VEC2_H_ */

Legend:
Removed from v.1370  
changed lines
  Added in v.1640

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0