SCM Repository
View of /branches/charisee/src/include/Diderot/inline-vec2.h
Parent Directory
|
Revision Log
Revision 2604 -
(download)
(as text)
(annotate)
Fri Apr 25 18:23:44 2014 UTC (8 years ago) by jhr
File size: 2901 byte(s)
Fri Apr 25 18:23:44 2014 UTC (8 years ago) by jhr
File size: 2901 byte(s)
added some bug fixes and other edits from the trunk
/*! \file inline-vec2.h * * \author John Reppy * * \brief inline functions for 2D vectors */ /* * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu) * All rights reserved. */ #ifndef _DIDEROT_INLINE_VEC2_H_ #define _DIDEROT_INLINE_VEC2_H_ #ifndef _DIDEROT_TYPES_H_ #include "Diderot/types.h" #endif STATIC_INLINE Diderot_vec2_t vec2 (Diderot_real_t a, Diderot_real_t b) { #ifdef VEC2_OK return __extension__ (Diderot_vec2_t){ a, b }; #else return __extension__ (Diderot_vec2_t){ a, b, 0.0, 0.0 }; #endif } STATIC_INLINE Diderot_ivec2_t vec2i (Diderot_int_t x, Diderot_int_t y) { #ifdef VEC2_OK return __extension__ (Diderot_ivec2_t){x,y}; #else return __extension__ (Diderot_ivec2_t){x,y, 0, 0 }; #endif } STATIC_INLINE Diderot_ivec2_t vec2rtoi (Diderot_vec2_t v) { Diderot_union2_t u; u.v = v; #ifdef VEC2_OK return __extension__ (Diderot_ivec2_t){ (Diderot_int_t)u.r[0], (Diderot_int_t)u.r[1] }; #else return __extension__ (Diderot_ivec2_t){ (Diderot_int_t)u.r[0], (Diderot_int_t)u.r[1], 0, 0 }; #endif } STATIC_INLINE Diderot_vec2_t vec2itor (Diderot_ivec2_t v) { union2i_t u; u.v = v; #ifdef VEC2_OK return __extension__ (Diderot_vec2_t){ (Diderot_real_t)u.i[0], (Diderot_real_t)u.i[1] }; #else return __extension__ (Diderot_vec2_t){ (Diderot_real_t)u.i[0], (Diderot_real_t)u.i[1], (Diderot_real_t)u.i[2], 0 }; #endif } STATIC_INLINE Diderot_vec2_t scale2 (Diderot_real_t s, Diderot_vec2_t v) { return vec2(s, s) * v; } STATIC_INLINE Diderot_vec2_t clamp2 (Diderot_vec2_t lo, Diderot_vec2_t hi, Diderot_vec2_t v) { // FIXME: there is probably a vectorized way to compute this Diderot_union2_t a, b, c; a.v = lo; b.v = hi; c.v = v; return vec2( clamp(a.r[0], b.r[0], c.r[0]), clamp(a.r[1], b.r[1], c.r[1])); } STATIC_INLINE Diderot_vec2_t lerp2 (Diderot_vec2_t a, Diderot_vec2_t b, Diderot_real_t t) { return a + scale2(t, b - a); } STATIC_INLINE Diderot_vec2_t floor2 (Diderot_vec2_t v) { Diderot_union2_t u; u.v = v; return vec2(FLOOR(u.r[0]), FLOOR(u.r[1])); } STATIC_INLINE Diderot_ivec2_t truncToInt2 (Diderot_vec2_t v) { Diderot_union2_t t; t.v = v; #ifdef VEC2_OK return __extension__ (Diderot_ivec2_t){ (Diderot_int_t)TRUNC(t.r[0]), (Diderot_int_t)TRUNC(t.r[1]) }; #else return __extension__ (Diderot_ivec2_t){ (Diderot_int_t)TRUNC(t.r[0]), (Diderot_int_t)TRUNC(t.r[1]), 0, 0 }; #endif } STATIC_INLINE Diderot_real_t dot2 (Diderot_vec2_t u, Diderot_vec2_t v) { Diderot_union2_t uv = __extension__ (Diderot_union2_t)(u*v); return uv.r[0] + uv.r[1]; } STATIC_INLINE Diderot_real_t length2 (Diderot_vec2_t v) { return SQRT(dot2(v, v)); } STATIC_INLINE Diderot_vec2_t normalize2 (Diderot_vec2_t v) { return scale2(1.0 / length2(v), v); } #endif /* !_DIDEROT_INLINE_VEC2_H_ */
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |