From 7078dc52546e8f2bd35a9c4c0ba60e25acc82a73 Mon Sep 17 00:00:00 2001 From: Tomas Frydrych Date: Wed, 17 Jan 2007 16:00:00 +0000 Subject: [PATCH] documentation for fixed point API --- AUTHORS | 3 +- ChangeLog | 12 +++ clutter/clutter-behaviour-path.c | 5 + clutter/clutter-fixed.c | 8 +- clutter/clutter-fixed.h | 168 ++++++++++++++++++++++++++++++++-- configure.ac | 11 ++- doc/reference/tmpl/clutter-fixed.sgml | 93 +++++++++---------- 7 files changed, 235 insertions(+), 65 deletions(-) diff --git a/AUTHORS b/AUTHORS index a5b620e..a3798f7 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,4 +1,5 @@ Matthew Allum - primary authour Emmanuele Bassi - python bindings, gobject/glib mastery Iain Holmes - GTK Clutter widget -Jorn Baayen - Gstreamer bits \ No newline at end of file +Jorn Baayen - Gstreamer bits +Tomas Frydrych - Fixed point magic diff --git a/ChangeLog b/ChangeLog index 36f8dc6..2286ae0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2007-01-17 Tomas Frydrych + * 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 * clutter/clutter-feature.h: diff --git a/clutter/clutter-behaviour-path.c b/clutter/clutter-behaviour-path.c index 4a2acdd..ba7d9dd 100644 --- a/clutter/clutter-behaviour-path.c +++ b/clutter/clutter-behaviour-path.c @@ -196,8 +196,13 @@ node_distance (const ClutterKnot *begin, if (clutter_knot_equal (begin, end)) return 0; +#ifdef CFX_NO_FPU return clutter_sqrti ((end->x - begin->x) * (end->x - begin->x) + (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 diff --git a/clutter/clutter-fixed.c b/clutter/clutter-fixed.c index 217fb21..b174795 100644 --- a/clutter/clutter-fixed.c +++ b/clutter/clutter-fixed.c @@ -115,7 +115,7 @@ static ClutterFixed sin_tbl [] = * * Fixed point implementation of sine function * - * Return value: sine value (as fixed point). + * Return value: #ClutterFixed sine value. * * Since: 0.2 */ @@ -204,7 +204,7 @@ clutter_sinx (ClutterFixed angle) * ClutterAngle is an integer such that 1024 represents * full circle. * - * Return value: sine value (as fixed point). + * Return value: #ClutterFixed sine value. * * Since: 0.2 */ @@ -331,7 +331,7 @@ ClutterFixed sqrt_tbl [] = * * A fixed point implementation of squre root * - * Return value: square root (as fixed point). + * Return value: #ClutterFixed square root. * * Since: 0.2 */ @@ -450,7 +450,7 @@ clutter_sqrtx (ClutterFixed x) * * 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 diff --git a/clutter/clutter-fixed.h b/clutter/clutter-fixed.h index c511052..b9850df 100644 --- a/clutter/clutter-fixed.h +++ b/clutter/clutter-fixed.h @@ -30,7 +30,19 @@ G_BEGIN_DECLS +/** + * ClutterFixed: + * + * Fixed point number (16.16) + */ 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 */ #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 */ + +/** + * CFX_PI: + * + * Fixed point representation of Pi + */ #define CFX_PI 0x0003243f +/** + * CFX_2PI: + * + * Fixed point representation of Pi*2 + */ #define CFX_2PI 0x0006487f +/** + * CFX_PI2: + * + * Fixed point representation of 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_PI8192 0x6487ed51 /* pi * 0x2000, to improve precision */ - +/** + * CFX_360: + * + * Fixed point representation of the number 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) +/** + * CFX_180: + * + * Fixed point representation of the number 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) +/** + * CFX_60: + * + * Fixed point representation of the number 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) - +/** + * CLUTTER_FIXED_TO_FLOAT: + * + * Macro to convert from fixed to floating point. + */ #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)) - +/** + * CLUTTER_FLOAT_TO_FIXED: + * + * Macro to convert from floating to fixed point. + */ #define CLUTTER_FLOAT_TO_FIXED(x) \ ( (ABS(x) > 32767.0) ? \ (((x)/(x))*0x7fffffff) \ : ((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) - +/** + * CLUTTER_FIXED_INT: + * + * Macro to convert from fixed point to integer. + */ #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)) +/** + * CLUTTER_FIXED_FLOOR: + * + * Macro to obtain greatest integer lesser than given fixed point value. + */ #define CLUTTER_FIXED_FLOOR(x) \ (((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) - +/** + * CLUTTER_FIXED_MUL: + * + * Macro to multiply two fixed point numbers. + */ #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) /* some handy short aliases to avoid exessively long lines */ + +/** + * CFX_INT: + * + * Alias for CLUTTER_FIXED_INT: + */ #define CFX_INT CLUTTER_FIXED_INT +/** + * CFX_MUL: + * + * Alias for CLUTTER_FIXED_MUL: + */ #define CFX_MUL CLUTTER_FIXED_MUL + +/** + * CFX_DIV: + * + * Alias for CLUTTER_FIXED_DIV: + */ #define CFX_DIV CLUTTER_FIXED_DIV /* Fixed point math routines */ @@ -89,7 +210,36 @@ ClutterFixed clutter_sinx (ClutterFixed angle); ClutterFixed clutter_sini (ClutterAngle angle); /* 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) + +/** + * 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) ClutterFixed clutter_sqrtx (ClutterFixed x); diff --git a/configure.ac b/configure.ac index 87d916e..02a7a1f 100644 --- a/configure.ac +++ b/configure.ac @@ -132,6 +132,14 @@ fi 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 ======================================================== GTK_DOC_CHECK([1.4]) @@ -140,7 +148,7 @@ dnl ======================================================================== 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" AC_SUBST(CLUTTER_CFLAGS) @@ -170,4 +178,5 @@ echo " prefix: ${prefix}" echo "" echo " Debug level: ${enable_debug}" echo " Documentation: ${enable_gtk_doc}" +echo " FPU: ${with_fpu}" echo "" diff --git a/doc/reference/tmpl/clutter-fixed.sgml b/doc/reference/tmpl/clutter-fixed.sgml index 01ff19b..a5f67a4 100644 --- a/doc/reference/tmpl/clutter-fixed.sgml +++ b/doc/reference/tmpl/clutter-fixed.sgml @@ -29,28 +29,28 @@ floating-to-fixed conversion. - +Number of bits used to store fractional part of #ClutterFixed. - +#ClutterFixed representation of 1. - +Maximum number representable by #ClutterFixed. - +Minumum number representable by #ClutterFixed. @@ -63,198 +63,191 @@ floating-to-fixed conversion. - +#ClutterFixed representation of Pi. - +#ClutterFixed representation of 2 * Pi. - +#ClutterFixed representation of Pi/2. - - - - - - - - +#ClutterFixed representation of Pi/4. - +#ClutterFixed representation of 120. - +#ClutterFixed representation of 180. - +#ClutterFixed representation of 240. - +#ClutterFixed representation of 360. - +#ClutterFixed representation of 60. - +#ClutterFixed representation of 255. - +Alias for #CLUTTER_FIXED_DIV. - +Alias for #CLUTTER_FIXED_INT. - +Alias for #CLUTTER_FIXED_MUL. - +Macro for converting #ClutterFixed to single precission floating point. -@x: +@x: #ClutterFixed - +Macro for converting #ClutterFixed to double precission floating point. -@x: +@x: #ClutterFixed - +Macro for converting floating point numbers to #ClutterFixed. -@x: +@x: double or float - +Macro for converting integers to #ClutterFixed. -@x: +@x: int - +Macro to obtain integer part of #ClutterFixed. -@x: +@x: #ClutterFixed - +Macro to obtain the fraction of #ClutterFixed. -@x: +@x: #ClutterFixed - +Macro to obtain greatest integer smaller than given #ClutterFixed. -@x: +@x: #ClutterFixed - +Macro to obtain smallest integer greater than given #ClutterFixed. -@x: +@x: #ClutterFixed - +Macro for multiplication of two #ClutterFixed numbers. -@x: -@y: +@x: #ClutterFixed +@y: #ClutterFixed - +Macro for difvision of two #ClutterFixed numbers. -@x: -@y: +@x: #ClutterFixed +@y: #ClutterFixed - +Very fast fixed point cosine function. -@x: +@x: #ClutterAngle - +Fast fixed point cosine function. -@x: +@x: #ClutterFixed -- 2.7.4