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

SCM Repository

[diderot] View of /branches/pure-cfg/src/include/Diderot/inline-vec2.h
ViewVC logotype

View of /branches/pure-cfg/src/include/Diderot/inline-vec2.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 710 - (download) (as text) (annotate)
Wed Mar 30 16:56:13 2011 UTC (9 years, 6 months ago) by jhr
File size: 1794 byte(s)
  Split up diderot header file into multiple files.
/*! \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 vec2f_t vec2f (float a, float b)
{
#ifdef VEC2_OK
    return __extension__ (vec2f_t){ a, b };
#else
    return __extension__ (vec2f_t){ a, b, 0.0, 0.0 };
#endif
}

STATIC_INLINE vec2i_t vec2ftoi (vec2f_t v)
{
    union2f_t u;
    u.v = v;
#ifdef VEC2_OK
    return __extension__ (vec2i_t){ (int32_t)u.r[0], (int32_t)u.r[1] };
#else
    return __extension__ (vec2i_t){ (int32_t)u.r[0], (int32_t)u.r[1], 0, 0 };
#endif
}

STATIC_INLINE vec2f_t vec2itof (vec2i_t v)
{
    union2i_t u;
    u.v = v;
#ifdef VEC2_OK
    return __extension__ (vec2f_t){ (float)u.i[0], (float)u.i[1] };
#else
    return __extension__ (vec2f_t){ (float)u.i[0], (float)u.i[1], (float)u.i[2], 0 };
#endif
}

STATIC_INLINE vec2f_t scale2f (float s, vec2f_t v)
{
    return vec2f(s, s) * v;
}

STATIC_INLINE vec2f_t floor2f (vec2f_t v)
{
    union2f_t u;
    u.v = v;
    return vec2f(floorf(u.r[0]), floorf(u.r[1]));
}

STATIC_INLINE vec2i_t truncToInt2f (vec2f_t v)
{
    union2f_t t;
    t.v = v;
#ifdef VEC2_OK
    return __extension__ (vec2i_t){
	(int32_t)truncf(t.r[0]),
	(int32_t)truncf(t.r[1]) };
#else
    return __extension__ (vec2i_t){
	(int32_t)truncf(t.r[0]),
	(int32_t)truncf(t.r[1]),
	0,
	0 };
#endif
}

STATIC_INLINE float dot2f (vec2f_t u, vec2f_t v)
{
    union2f_t uv = __extension__ (union2f_t)(u*v);
    return uv.r[0] + uv.r[1];
}

STATIC_INLINE float length2f (vec2f_t v)
{
    return sqrtf(dot2f(v, v));
}

#endif /* !_DIDEROT_INLINE_VEC2_H_ */

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