documentation for fixed point API

This commit is contained in:
Tomas Frydrych 2007-01-17 16:00:00 +00:00
parent 9bd77e25b2
commit 7078dc5254
7 changed files with 235 additions and 65 deletions

View File

@ -2,3 +2,4 @@ Matthew Allum <mallum@o-hand.com> - primary authour
Emmanuele Bassi <ebassi@o-hand.com> - python bindings, gobject/glib mastery Emmanuele Bassi <ebassi@o-hand.com> - python bindings, gobject/glib mastery
Iain Holmes <iain@o-hand.com> - GTK Clutter widget Iain Holmes <iain@o-hand.com> - GTK Clutter widget
Jorn Baayen <jorn@o-hand.com> - Gstreamer bits Jorn Baayen <jorn@o-hand.com> - Gstreamer bits
Tomas Frydrych <tf@o-hand.com> - Fixed point magic

View File

@ -1,3 +1,15 @@
2007-01-17 Tomas Frydrych <tf@openedhand.com>
* configure.ac:
* clutter/clutter-behavior-path.c:
Added --without-fpu option.
* doc/refrence/tmpl/clutter-fixed.sgml:
* clutter/clutter-fixed.c:
* clutter/clutter-fixed.h:
Documentation for fixed point API.
* AUTHORS: added self.
2007-01-17 Emmanuele Bassi <ebassi@openedhand.com> 2007-01-17 Emmanuele Bassi <ebassi@openedhand.com>
* clutter/clutter-feature.h: * clutter/clutter-feature.h:

View File

@ -196,8 +196,13 @@ node_distance (const ClutterKnot *begin,
if (clutter_knot_equal (begin, end)) if (clutter_knot_equal (begin, end))
return 0; return 0;
#ifdef CFX_NO_FPU
return clutter_sqrti ((end->x - begin->x) * (end->x - begin->x) + return clutter_sqrti ((end->x - begin->x) * (end->x - begin->x) +
(end->y - begin->y) * (end->y - begin->y)); (end->y - begin->y) * (end->y - begin->y));
#else
return (gint) sqrt ((end->x - begin->x) * (end->x - begin->x) +
(end->y - begin->y) * (end->y - begin->y));
#endif
} }
static gint static gint

View File

@ -115,7 +115,7 @@ static ClutterFixed sin_tbl [] =
* *
* Fixed point implementation of sine function * Fixed point implementation of sine function
* *
* Return value: sine value (as fixed point). * Return value: #ClutterFixed sine value.
* *
* Since: 0.2 * Since: 0.2
*/ */
@ -204,7 +204,7 @@ clutter_sinx (ClutterFixed angle)
* ClutterAngle is an integer such that 1024 represents * ClutterAngle is an integer such that 1024 represents
* full circle. * full circle.
* *
* Return value: sine value (as fixed point). * Return value: #ClutterFixed sine value.
* *
* Since: 0.2 * Since: 0.2
*/ */
@ -331,7 +331,7 @@ ClutterFixed sqrt_tbl [] =
* *
* A fixed point implementation of squre root * A fixed point implementation of squre root
* *
* Return value: square root (as fixed point). * Return value: #ClutterFixed square root.
* *
* Since: 0.2 * Since: 0.2
*/ */
@ -450,7 +450,7 @@ clutter_sqrtx (ClutterFixed x)
* *
* A fixed point implementation of square root for integers * A fixed point implementation of square root for integers
* *
* Return value: square root (as truncated integer). * Return value: integer square root (truncated).
* *
* *
* Since: 0.2 * Since: 0.2

View File

@ -30,7 +30,19 @@
G_BEGIN_DECLS G_BEGIN_DECLS
/**
* ClutterFixed:
*
* Fixed point number (16.16)
*/
typedef gint32 ClutterFixed; typedef gint32 ClutterFixed;
/**
* ClutterAngle:
*
* Integer representation of an agnle such that 1024 corresponds to
* fool circle (i.e., 2*Pi).
*/
typedef gint32 ClutterAngle; /* angle such that 1024 == 2*PI */ typedef gint32 ClutterAngle; /* angle such that 1024 == 2*PI */
#define CFX_Q 16 /* Decimal part size in bits */ #define CFX_Q 16 /* Decimal part size in bits */
@ -41,47 +53,156 @@ typedef gint32 ClutterAngle; /* angle such that 1024 == 2*PI */
/* /*
* some commonly used constants * some commonly used constants
*/ */
/**
* CFX_PI:
*
* Fixed point representation of Pi
*/
#define CFX_PI 0x0003243f #define CFX_PI 0x0003243f
/**
* CFX_2PI:
*
* Fixed point representation of Pi*2
*/
#define CFX_2PI 0x0006487f #define CFX_2PI 0x0006487f
/**
* CFX_PI2:
*
* Fixed point representation of Pi/2
*/
#define CFX_PI_2 0x00019220 /* pi/2 */ #define CFX_PI_2 0x00019220 /* pi/2 */
/**
* CFX_PI4:
*
* Fixed point representation of Pi/4
*/
#define CFX_PI_4 0x0000c910 /* pi/4 */ #define CFX_PI_4 0x0000c910 /* pi/4 */
#define CFX_PI8192 0x6487ed51 /* pi * 0x2000, to improve precision */ /**
* CFX_360:
*
* Fixed point representation of the number 360
*/
#define CFX_360 CLUTTER_INT_TO_FIXED (360) #define CFX_360 CLUTTER_INT_TO_FIXED (360)
/**
* CFX_240:
*
* Fixed point representation of the number 240
*/
#define CFX_240 CLUTTER_INT_TO_FIXED (240) #define CFX_240 CLUTTER_INT_TO_FIXED (240)
/**
* CFX_180:
*
* Fixed point representation of the number 180
*/
#define CFX_180 CLUTTER_INT_TO_FIXED (180) #define CFX_180 CLUTTER_INT_TO_FIXED (180)
/**
* CFX_120:
*
* Fixed point representation of the number 120
*/
#define CFX_120 CLUTTER_INT_TO_FIXED (120) #define CFX_120 CLUTTER_INT_TO_FIXED (120)
/**
* CFX_60:
*
* Fixed point representation of the number 60
*/
#define CFX_60 CLUTTER_INT_TO_FIXED (60) #define CFX_60 CLUTTER_INT_TO_FIXED (60)
/**
* CFX_255:
*
* Fixed point representation of the number 255
*/
#define CFX_255 CLUTTER_INT_TO_FIXED (255) #define CFX_255 CLUTTER_INT_TO_FIXED (255)
/**
* CLUTTER_FIXED_TO_FLOAT:
*
* Macro to convert from fixed to floating point.
*/
#define CLUTTER_FIXED_TO_FLOAT(x) ((float)((int)(x)/65536.0)) #define CLUTTER_FIXED_TO_FLOAT(x) ((float)((int)(x)/65536.0))
/**
* CLUTTER_FIXED_TO_DOUBLE:
*
* Macro to convert from fixed to doulbe precission floating point.
*/
#define CLUTTER_FIXED_TO_DOUBLE(x) ((double)((int)(x)/65536.0)) #define CLUTTER_FIXED_TO_DOUBLE(x) ((double)((int)(x)/65536.0))
/**
* CLUTTER_FLOAT_TO_FIXED:
*
* Macro to convert from floating to fixed point.
*/
#define CLUTTER_FLOAT_TO_FIXED(x) \ #define CLUTTER_FLOAT_TO_FIXED(x) \
( (ABS(x) > 32767.0) ? \ ( (ABS(x) > 32767.0) ? \
(((x)/(x))*0x7fffffff) \ (((x)/(x))*0x7fffffff) \
: ((long)((x) * 65536.0 + ((x) < 0 ? -0.5 : 0.5))) ) : ((long)((x) * 65536.0 + ((x) < 0 ? -0.5 : 0.5))) )
/**
* CLUTTER_INT_TO_FIXED:
*
* Macro to convert from int to fixed point representation.
*/
#define CLUTTER_INT_TO_FIXED(x) ((x) << CFX_Q) #define CLUTTER_INT_TO_FIXED(x) ((x) << CFX_Q)
/**
* CLUTTER_FIXED_INT:
*
* Macro to convert from fixed point to integer.
*/
#define CLUTTER_FIXED_INT(x) ((x) >> CFX_Q) #define CLUTTER_FIXED_INT(x) ((x) >> CFX_Q)
/**
* CLUTTER_FIXED_FRACTION:
*
* Macro to retrive the fraction of a fixed point number.
*/
#define CLUTTER_FIXED_FRACTION(x) ((x) & ((1 << CFX_Q) - 1)) #define CLUTTER_FIXED_FRACTION(x) ((x) & ((1 << CFX_Q) - 1))
/**
* CLUTTER_FIXED_FLOOR:
*
* Macro to obtain greatest integer lesser than given fixed point value.
*/
#define CLUTTER_FIXED_FLOOR(x) \ #define CLUTTER_FIXED_FLOOR(x) \
(((x) >= 0) ? ((x) >> CFX_Q) : ~((~(x)) >> CFX_Q)) (((x) >= 0) ? ((x) >> CFX_Q) : ~((~(x)) >> CFX_Q))
/**
* CLUTTER_FIXED_CEIL:
*
* Macro to obtain smallest integer greater than given fixed point value.
*/
#define CLUTTER_FIXED_CEIL(x) CLUTTER_FIXED_FLOOR(x + 0xffff) #define CLUTTER_FIXED_CEIL(x) CLUTTER_FIXED_FLOOR(x + 0xffff)
/**
* CLUTTER_FIXED_MUL:
*
* Macro to multiply two fixed point numbers.
*/
#define CLUTTER_FIXED_MUL(x,y) ((x) >> 8) * ((y) >> 8) #define CLUTTER_FIXED_MUL(x,y) ((x) >> 8) * ((y) >> 8)
/**
* CLUTTER_FIXED_DIV:
*
* Macro to divide two fixed point numbers.
*/
#define CLUTTER_FIXED_DIV(x,y) ((((x) << 8)/(y)) << 8) #define CLUTTER_FIXED_DIV(x,y) ((((x) << 8)/(y)) << 8)
/* some handy short aliases to avoid exessively long lines */ /* some handy short aliases to avoid exessively long lines */
/**
* CFX_INT:
*
* Alias for CLUTTER_FIXED_INT:
*/
#define CFX_INT CLUTTER_FIXED_INT #define CFX_INT CLUTTER_FIXED_INT
/**
* CFX_MUL:
*
* Alias for CLUTTER_FIXED_MUL:
*/
#define CFX_MUL CLUTTER_FIXED_MUL #define CFX_MUL CLUTTER_FIXED_MUL
/**
* CFX_DIV:
*
* Alias for CLUTTER_FIXED_DIV:
*/
#define CFX_DIV CLUTTER_FIXED_DIV #define CFX_DIV CLUTTER_FIXED_DIV
/* Fixed point math routines */ /* Fixed point math routines */
@ -89,7 +210,36 @@ ClutterFixed clutter_sinx (ClutterFixed angle);
ClutterFixed clutter_sini (ClutterAngle angle); ClutterFixed clutter_sini (ClutterAngle angle);
/* convenience macros for the cos functions */ /* convenience macros for the cos functions */
/**
* clutter_cosx:
* @angle: a #ClutterFixed angle in radians
*
* Fixed point cosine function
*
* Return value: #ClutterFixed cosine value.
*
* Note: Implemneted as a macro.
*
* Since: 0.2
*/
#define clutter_cosx(x) clutter_fixed_sin((x) - CFX_PI_2) #define clutter_cosx(x) clutter_fixed_sin((x) - CFX_PI_2)
/**
* clutter_cosi:
* @angle: a #ClutterAngle angle
*
* Very fast fixed point implementation of cosine function.
*
* ClutterAngle is an integer such that 1024 represents
* full circle.
*
* Return value: #ClutterFixed cosine value.
*
* Note: Implemneted as a macro.
*
* Since: 0.2
*/
#define clutter_cosi(x) clutter_sini((x) - 256) #define clutter_cosi(x) clutter_sini((x) - 256)
ClutterFixed clutter_sqrtx (ClutterFixed x); ClutterFixed clutter_sqrtx (ClutterFixed x);

View File

@ -132,6 +132,14 @@ fi
AC_SUBST(CLUTTER_DEBUG_CFLAGS) AC_SUBST(CLUTTER_DEBUG_CFLAGS)
AC_ARG_WITH(fpu, AS_HELP_STRING([--without-fpu],
[Assume no fpu is present]),
[with_fpu=$withval], [with_fpu=yes])
if test "x$with_fpu" != "xyes" ; then
CLUTTER_FIXED_CFLAGS="-DCFX_NO_FPU"
fi
dnl = GTK Doc check ======================================================== dnl = GTK Doc check ========================================================
GTK_DOC_CHECK([1.4]) GTK_DOC_CHECK([1.4])
@ -140,7 +148,7 @@ dnl ========================================================================
AC_SUBST(GCC_FLAGS) AC_SUBST(GCC_FLAGS)
CLUTTER_CFLAGS="$GLX_CLAGS $CLUTTER_DEPS_CFLAGS" CLUTTER_CFLAGS="$GLX_CLAGS $CLUTTER_DEPS_CFLAGS $CLUTTER_FIXED_CFLAGS"
CLUTTER_LIBS="$GLX_LIBS $CLUTTER_DEPS_LIBS" CLUTTER_LIBS="$GLX_LIBS $CLUTTER_DEPS_LIBS"
AC_SUBST(CLUTTER_CFLAGS) AC_SUBST(CLUTTER_CFLAGS)
@ -170,4 +178,5 @@ echo " prefix: ${prefix}"
echo "" echo ""
echo " Debug level: ${enable_debug}" echo " Debug level: ${enable_debug}"
echo " Documentation: ${enable_gtk_doc}" echo " Documentation: ${enable_gtk_doc}"
echo " FPU: ${with_fpu}"
echo "" echo ""

View File

@ -29,28 +29,28 @@ floating-to-fixed conversion.
<!-- ##### MACRO CFX_Q ##### --> <!-- ##### MACRO CFX_Q ##### -->
<para> <para>
Number of bits used to store fractional part of #ClutterFixed.
</para> </para>
<!-- ##### MACRO CFX_ONE ##### --> <!-- ##### MACRO CFX_ONE ##### -->
<para> <para>
#ClutterFixed representation of 1.
</para> </para>
<!-- ##### MACRO CFX_MAX ##### --> <!-- ##### MACRO CFX_MAX ##### -->
<para> <para>
Maximum number representable by #ClutterFixed.
</para> </para>
<!-- ##### MACRO CFX_MIN ##### --> <!-- ##### MACRO CFX_MIN ##### -->
<para> <para>
Minumum number representable by #ClutterFixed.
</para> </para>
@ -63,198 +63,191 @@ floating-to-fixed conversion.
<!-- ##### MACRO CFX_PI ##### --> <!-- ##### MACRO CFX_PI ##### -->
<para> <para>
#ClutterFixed representation of Pi.
</para> </para>
<!-- ##### MACRO CFX_2PI ##### --> <!-- ##### MACRO CFX_2PI ##### -->
<para> <para>
#ClutterFixed representation of 2 * Pi.
</para> </para>
<!-- ##### MACRO CFX_PI_2 ##### --> <!-- ##### MACRO CFX_PI_2 ##### -->
<para> <para>
#ClutterFixed representation of Pi/2.
</para> </para>
<!-- ##### MACRO CFX_PI_4 ##### --> <!-- ##### MACRO CFX_PI_4 ##### -->
<para> <para>
#ClutterFixed representation of Pi/4.
</para>
<!-- ##### MACRO CFX_PI8192 ##### -->
<para>
</para> </para>
<!-- ##### MACRO CFX_120 ##### --> <!-- ##### MACRO CFX_120 ##### -->
<para> <para>
#ClutterFixed representation of 120.
</para> </para>
<!-- ##### MACRO CFX_180 ##### --> <!-- ##### MACRO CFX_180 ##### -->
<para> <para>
#ClutterFixed representation of 180.
</para> </para>
<!-- ##### MACRO CFX_240 ##### --> <!-- ##### MACRO CFX_240 ##### -->
<para> <para>
#ClutterFixed representation of 240.
</para> </para>
<!-- ##### MACRO CFX_360 ##### --> <!-- ##### MACRO CFX_360 ##### -->
<para> <para>
#ClutterFixed representation of 360.
</para> </para>
<!-- ##### MACRO CFX_60 ##### --> <!-- ##### MACRO CFX_60 ##### -->
<para> <para>
#ClutterFixed representation of 60.
</para> </para>
<!-- ##### MACRO CFX_255 ##### --> <!-- ##### MACRO CFX_255 ##### -->
<para> <para>
#ClutterFixed representation of 255.
</para> </para>
<!-- ##### MACRO CFX_DIV ##### --> <!-- ##### MACRO CFX_DIV ##### -->
<para> <para>
Alias for #CLUTTER_FIXED_DIV.
</para> </para>
<!-- ##### MACRO CFX_INT ##### --> <!-- ##### MACRO CFX_INT ##### -->
<para> <para>
Alias for #CLUTTER_FIXED_INT.
</para> </para>
<!-- ##### MACRO CFX_MUL ##### --> <!-- ##### MACRO CFX_MUL ##### -->
<para> <para>
Alias for #CLUTTER_FIXED_MUL.
</para> </para>
<!-- ##### MACRO CLUTTER_FIXED_TO_FLOAT ##### --> <!-- ##### MACRO CLUTTER_FIXED_TO_FLOAT ##### -->
<para> <para>
Macro for converting #ClutterFixed to single precission floating point.
</para> </para>
@x: @x: #ClutterFixed
<!-- ##### MACRO CLUTTER_FIXED_TO_DOUBLE ##### --> <!-- ##### MACRO CLUTTER_FIXED_TO_DOUBLE ##### -->
<para> <para>
Macro for converting #ClutterFixed to double precission floating point.
</para> </para>
@x: @x: #ClutterFixed
<!-- ##### MACRO CLUTTER_FLOAT_TO_FIXED ##### --> <!-- ##### MACRO CLUTTER_FLOAT_TO_FIXED ##### -->
<para> <para>
Macro for converting floating point numbers to #ClutterFixed.
</para> </para>
@x: @x: double or float
<!-- ##### MACRO CLUTTER_INT_TO_FIXED ##### --> <!-- ##### MACRO CLUTTER_INT_TO_FIXED ##### -->
<para> <para>
Macro for converting integers to #ClutterFixed.
</para> </para>
@x: @x: int
<!-- ##### MACRO CLUTTER_FIXED_INT ##### --> <!-- ##### MACRO CLUTTER_FIXED_INT ##### -->
<para> <para>
Macro to obtain integer part of #ClutterFixed.
</para> </para>
@x: @x: #ClutterFixed
<!-- ##### MACRO CLUTTER_FIXED_FRACTION ##### --> <!-- ##### MACRO CLUTTER_FIXED_FRACTION ##### -->
<para> <para>
Macro to obtain the fraction of #ClutterFixed.
</para> </para>
@x: @x: #ClutterFixed
<!-- ##### MACRO CLUTTER_FIXED_FLOOR ##### --> <!-- ##### MACRO CLUTTER_FIXED_FLOOR ##### -->
<para> <para>
Macro to obtain greatest integer smaller than given #ClutterFixed.
</para> </para>
@x: @x: #ClutterFixed
<!-- ##### MACRO CLUTTER_FIXED_CEIL ##### --> <!-- ##### MACRO CLUTTER_FIXED_CEIL ##### -->
<para> <para>
Macro to obtain smallest integer greater than given #ClutterFixed.
</para> </para>
@x: @x: #ClutterFixed
<!-- ##### MACRO CLUTTER_FIXED_MUL ##### --> <!-- ##### MACRO CLUTTER_FIXED_MUL ##### -->
<para> <para>
Macro for multiplication of two #ClutterFixed numbers.
</para> </para>
@x: @x: #ClutterFixed
@y: @y: #ClutterFixed
<!-- ##### MACRO CLUTTER_FIXED_DIV ##### --> <!-- ##### MACRO CLUTTER_FIXED_DIV ##### -->
<para> <para>
Macro for difvision of two #ClutterFixed numbers.
</para> </para>
@x: @x: #ClutterFixed
@y: @y: #ClutterFixed
<!-- ##### MACRO clutter_cosi ##### --> <!-- ##### MACRO clutter_cosi ##### -->
<para> <para>
Very fast fixed point cosine function.
</para> </para>
@x: @x: #ClutterAngle
<!-- ##### MACRO clutter_cosx ##### --> <!-- ##### MACRO clutter_cosx ##### -->
<para> <para>
Fast fixed point cosine function.
</para> </para>
@x: @x: #ClutterFixed
<!-- ##### FUNCTION clutter_sini ##### --> <!-- ##### FUNCTION clutter_sini ##### -->