📄 math.h
字号:
/* * GPAC - Multimedia Framework C SDK * * Copyright (c) Jean Le Feuvre 2000-2005 * All rights reserved * * This file is part of GPAC / common tools sub-project * * GPAC is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * GPAC is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * */#ifndef _GF_MATH_H_#define _GF_MATH_H_#ifdef __cplusplusextern "C" {#endif/*! * \file <gpac/math.h> * \brief math and trigo functions. */#include <gpac/setup.h> /*NOTE: there is a conflict on Win32 VC6 with C++ and gpac headers when including <math.h>*/#if !defined(__cplusplus) || defined(__SYMBIAN32__)#include <math.h>#endif/*! \cond DUMMY_DOXY_SECTION*/#ifndef GPAC_FIXED_POINT/*note: to turn fp on, change to GPAC_FIXED_POINT to turn fp off, change to GPAC_NO_FIXED_POINT this is needed by configure+sed to modify this file directly*/#define GPAC_NO_FIXED_POINT#endif/*! \endcond*//*! *\addtogroup math_grp math *\ingroup utils_grp *\brief Mathematics and Trigonometric functions * *This section documents the math and trigo functions used in the GPAC framework. GPAC can be compiled with *fixed-point support, representing float values on a 16.16 signed integer, which implies a developer *must take care of float computations when using GPAC.\n *A developper should not need to know in which mode the framework has been compiled as long as he uses *the math functions of GPAC which work in both float and fixed-point mode.\n *Using fixed-point version is decided at compilation time and cannot be changed. The feature is signaled *through the following macros: *- GPAC_FIXED_POINT: when defined, GPAC has been compiled in fixed-point mode *- GPAC_NO_FIXED_POINT: when defined, GPAC has been compiled in regular (float) mode * @{ *//***************************************************************************************** FIXED-POINT SUPPORT - HARDCODED FOR 16.16 representation the software rasterizer also use a 16.16 representation even in non-fixed version******************************************************************************************/#ifdef GPAC_FIXED_POINT/*! *Fixed 16.16 number *\hideinitializer \note This documentation has been generated for a fixed-point version of the GPAC framework. */typedef s32 Fixed;#define FIX_ONE 0x10000L#define INT2FIX(v) ((Fixed)( ((s32) (v) ) << 16))#define FLT2FIX(v) ((Fixed) ((v) * FIX_ONE))#define FIX2INT(v) ((s32)(((v)+((FIX_ONE>>1)))>>16))#define FIX2FLT(v) ((Float)( ((Float)(v)) / ((Float) FIX_ONE)))#define FIX_EPSILON 2#define FIX_MAX 0x7FFFFFFF#define FIX_MIN -FIX_MAX#define GF_PI2 102944#define GF_PI 205887#define GF_2PI 411774/*!\return 1/a, expressed as fixed number*/Fixed gf_invfix(Fixed a);/*!\return a*b, expressed as fixed number*/Fixed gf_mulfix(Fixed a, Fixed b);/*!\return a*b/c, expressed as fixed number*/Fixed gf_muldiv(Fixed a, Fixed b, Fixed c);/*!\return a/b, expressed as fixed number*/Fixed gf_divfix(Fixed a, Fixed b);/*!\return sqrt(a), expressed as fixed number*/Fixed gf_sqrt(Fixed x);/*!\return ceil(a), expressed as fixed number*/Fixed gf_ceil(Fixed a);/*!\return floor(a), expressed as fixed number*/Fixed gf_floor(Fixed a);/*!\return cos(a), expressed as fixed number*/Fixed gf_cos(Fixed angle);/*!\return sin(a), expressed as fixed number*/Fixed gf_sin(Fixed angle);/*!\return tan(a), expressed as fixed number*/Fixed gf_tan(Fixed angle);/*!\return acos(a), expressed as fixed number*/Fixed gf_acos(Fixed angle);/*!\return asin(a), expressed as fixed number*/Fixed gf_asin(Fixed angle);/*!\return atan(y, x), expressed as fixed number*/Fixed gf_atan2(Fixed y, Fixed x);#else/*!Fixed is 32bit float number \note This documentation has been generated for a float version of the GPAC framework.*/typedef Float Fixed;#define FIX_ONE 1.0f#define INT2FIX(v) ((Float) (v))#define FLT2FIX(v) ((Float) (v))#define FIX2INT(v) ((s32)(v))#define FIX2FLT(v) ((Float) (v))#define FIX_EPSILON GF_EPSILON_FLOAT#define FIX_MAX GF_MAX_FLOAT#define FIX_MIN -GF_MAX_FLOAT#define GF_PI2 1.5707963267949f#define GF_PI 3.1415926535898f#define GF_2PI 6.2831853071796f/*!\hideinitializer 1/_a, expressed as fixed number*/#define gf_invfix(_a) (FIX_ONE/(_a))/*!\hideinitializer _a*_b, expressed as fixed number*/#define gf_mulfix(_a, _b) ((_a)*(_b))/*!\hideinitializer _a*_b/_c, expressed as fixed number*/#define gf_muldiv(_a, _b, _c) ((_c) ? (_a)*(_b)/(_c) : GF_MAX_FLOAT)/*!\hideinitializer _a/_b, expressed as fixed number*/#define gf_divfix(_a, _b) ((_b) ? (_a)/(_b) : GF_MAX_FLOAT)/*!\hideinitializer sqrt(_a), expressed as fixed number*/#define gf_sqrt(_a) ((Float) sqrt(_a))/*!\hideinitializer ceil(_a), expressed as fixed number*/#define gf_ceil(_a) ((Float) ceil(_a))/*!\hideinitializer floor(_a), expressed as fixed number*/#define gf_floor(_a) ((Float) floor(_a))/*!\hideinitializer cos(_a), expressed as fixed number*/#define gf_cos(_a) ((Float) cos(_a))/*!\hideinitializer sin(_a), expressed as fixed number*/#define gf_sin(_a) ((Float) sin(_a))/*!\hideinitializer tan(_a), expressed as fixed number*/#define gf_tan(_a) ((Float) tan(_a))/*!\hideinitializer atan2(_y,_x), expressed as fixed number*/#define gf_atan2(_y, _x) ((Float) atan2(_y, _x))/*!\hideinitializer acos(_a), expressed as fixed number*/#define gf_acos(_a) ((Float) acos(_a))/*!\hideinitializer asin(_a), expressed as fixed number*/#define gf_asin(_a) ((Float) asin(_a))#endif/*!\def FIX_ONE \hideinitializer Fixed unit value*//*!\def INT2FIX(v) \hideinitializer Conversion from integer to fixed*//*!\def FLT2FIX(v) \hideinitializer Conversion from float to fixed*//*!\def FIX2INT(v) \hideinitializer Conversion from fixed to integer*//*!\def FIX2FLT(v) \hideinitializer Conversion from fixed to float*//*!\def FIX_EPSILON \hideinitializer Epsilon Fixed (positive value closest to 0)*//*!\def FIX_MAX \hideinitializer Maximum Fixed (maximum representable fixed value)*//*!\def FIX_MIN \hideinitializer Minimum Fixed (minimum representable fixed value)*//*!\def GF_PI2 \hideinitializer PI/2 expressed as Fixed*//*!\def GF_PI \hideinitializer PI expressed as Fixed*//*!\def GF_2PI \hideinitializer 2*PI expressed as Fixed*/Fixed gf_angle_diff(Fixed a, Fixed b);/*! * \brief Field bit-size * * Gets the number of bits needed to represent the value. * \param MaxVal Maximum value to be represented. * \return number of bits required to represent the value. */u32 gf_get_bit_size(u32 MaxVal);/*! *\addtogroup math2d_grp math2d *\ingroup math_grp *\brief 2D Mathematics functions * *This section documents mathematic tools for 2D geometry and color matrices operations * @{ *//*!\brief 2D point * *The 2D point object is used in all the GPAC framework for both point and vector representation.*/typedef struct __vec2f{ Fixed x; Fixed y;} GF_Point2D;/*! *\brief get 2D vector length * *Gets the length of a 2D vector *\return length of the vector */Fixed gf_v2d_len(GF_Point2D *vec);/*! *\brief 2D vector from polar coordinates * *Constructs a 2D vector from its polar coordinates *\param length the length of the vector *\param angle the angle of the vector in radians *\return the 2D vector */GF_Point2D gf_v2d_from_polar(Fixed length, Fixed angle);/*!\brief rectangle 2D * *The 2D rectangle used in the GPAC project. */typedef struct{ /*!the left coordinate of the rectangle*/ Fixed x; /*!the top coordinate of the rectangle, regardless of the canvas orientation. In other words, y is always the greatest coordinate value, even if the rectangle is presented bottom-up. This insures proper rectangles testing*/ Fixed y; /*!the width of the rectangle. Width must be greater than or equal to 0*/ Fixed width; /*!the height of the rectangle. Height must be greater than or equal to 0*/ Fixed height;} GF_Rect;/*! \brief rectangle union * *Gets the union of two rectangles. *\param rc1 first rectangle of the union. Upon return, this rectangle will contain the result of the union *\param rc2 second rectangle of the union*/void gf_rect_union(GF_Rect *rc1, GF_Rect *rc2);/*! \brief centers a rectangle * *Builds a rectangle centered on the origin *\param w width of the rectangle *\param h height of the rectangle *\return centered rectangle object*/GF_Rect gf_rect_center(Fixed w, Fixed h);/*! \brief rectangle overlap test * *Tests if two rectangles overlap. *\param rc1 first rectangle to test *\param rc2 second rectangle to test *\return 1 if rectangles overlap, 0 otherwise*/Bool gf_rect_overlaps(GF_Rect rc1, GF_Rect rc2);/*! \brief rectangle identity test * *Tests if two rectangles are identical. *\param rc1 first rectangle to test *\param rc2 second rectangle to test *\return 1 if rectangles are identical, 0 otherwise*/Bool gf_rect_equal(GF_Rect rc1, GF_Rect rc2);/*! *\brief pixel-aligned rectangle * *Pixel-aligned rectangle used in the GPAC framework. This is usually needed for 2D drawing algorithms. */typedef struct{ /*!the left coordinate of the rectangle*/ s32 x; /*!the top coordinate of the rectangle, regardless of the canvas orientation. In other words, y is always the greatest coordinate value, even if the rectangle is presented bottom-up. This insures proper rectangles operations*/ s32 y; /*!the width of the rectangle. Width must be greater than or equal to 0*/ s32 width; /*!the height of the rectangle. Height must be greater than or equal to 0*/ s32 height;} GF_IRect;/*! *\brief gets the pixelized version of a rectangle
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -