Adobe.com
Contents Suites Classes Class Index Member Index

AIRealMath.h

Go to the documentation of this file.
00001 #ifndef __AIRealMath__
00002 #define __AIRealMath__
00003 
00004 /*
00005  *        Name: AIRealMath.h
00006  *   $Revision: 28 $
00007  *      Author:
00008  *        Date:
00009  *     Purpose: Adobe Illustrator AIReal Math Suite.
00010  *
00011  * ADOBE SYSTEMS INCORPORATED
00012  * Copyright 1986-2007 Adobe Systems Incorporated.
00013  * All rights reserved.
00014  *
00015  * NOTICE:  Adobe permits you to use, modify, and distribute this file 
00016  * in accordance with the terms of the Adobe license agreement 
00017  * accompanying it. If you have received this file from a source other 
00018  * than Adobe, then your use, modification, or distribution of it 
00019  * requires the prior written permission of Adobe.
00020  *
00021  */
00022 
00023 
00024 /*******************************************************************************
00025  **
00026  **     Imports
00027  **
00028  **/
00029 
00030 #ifndef __AITypes__
00031 #include "AITypes.h"
00032 #endif
00033 
00034 #include <math.h>       // for floor and ceil
00035 #include <float.h>
00036 
00037 #include "AIHeaderBegin.h"
00038 
00042 /*******************************************************************************
00043  **
00044  **     Constants
00045  **
00046  **/
00047 
00048 #define kAIRealMathSuite                        "AI Real Math Suite"
00049 #define kAIRealMathSuiteVersion         AIAPI_VERSION(5)
00050 #define kAIRealMathVersion                      kAIRealMathSuiteVersion
00051 
00052 // Most of this stuff is completely unnecessary, and is just here to ease the
00053 // transition between Fixed and AIReal.  We should probably make a later pass
00054 // to clean the unnecessary stuff out.
00055 
00056 // common AIReal constants
00057 #define kAIRealMax                                      ((AIReal)(DBL_MAX / 10.0F))
00058 #define kAIRealMin                                      ((AIReal)-(DBL_MAX / 10.0F))
00059 #define kAIRealUnknown                          ((AIReal)DBL_MAX)
00060 
00061 #define kAIFloatUnknown                         ((AIFloat)FLT_MAX)
00062 
00063 #ifndef kAIRealOne
00064 #define kAIRealOne                                      ((AIReal) 1.0)
00065 #endif
00066 #ifndef kAIRealZero
00067 #define kAIRealZero                                     ((AIReal) 0.0)
00068 #endif
00069 
00070 #ifndef kAIFloatOne
00071 #define kAIFloatOne                                     (1.0f)
00072 #endif
00073 
00074 #ifndef kAIFloatZero
00075 #define kAIFloatZero                                    (0.0f)
00076 #endif
00077 
00078 #define kAIRealHundredth                        ((AIReal) 0.01)
00079 #define kAIRealSixteenth                        ((AIReal) (1.0/16.0))
00080 #define kAIRealTenth                            ((AIReal) 0.1)
00081 #define kAIRealEighth                           ((AIReal) 0.125)
00082 
00083 #ifndef kAIRealQuarter
00084 #define kAIRealQuarter                          ((AIReal) 0.25)
00085 #endif
00086 
00087 #ifndef kAIRealHalf
00088 #define kAIRealHalf                             ((AIReal) 0.5)
00089 #endif
00090 
00091 #define kAIRealSevenEighths                     ((AIReal) 0.875)
00092 #define kAIRealOneThird                         ((AIReal) (1.0/3.0))
00093 #define kAIRealTwoThirds                        ((AIReal) (2.0/3.0))
00094 #define kAIRealFourThirds                       ((AIReal) (4.0/3.0))
00095 #define kAIRealThreeHalves                      ((AIReal) 1.5)
00096 
00097 #define kAIPi                                           3.141592653589793238462643383279502884197169399375
00098 #define kAIDoublePi                                     ((double) kAIPi)
00099 #define kAIRealPi                                       ((AIReal) kAIPi)
00100 #define kAIRealPi4                                      ((AIReal) (kAIPi/4.0))
00101 #define kAIRealPi2                                      ((AIReal) (kAIPi/2.0))
00102 #define kAIReal3PiOver2                         ((AIReal) (kAIRealThreeHalves*kAIPi))
00103 #define kAIRealTwoPi                            ((AIReal) (kAIPi*2.0))
00104 
00105 #define kAIRealSquareRootOfTwo          ((AIReal) 1.4142135623)                                                         /* 2^(1/2) */
00106 #define kAIRealSquareRootOfThree        ((AIReal) 1.7320508075688772935274463415059)            /* 3^(1/2) */
00107 #define kAIRealAvogadrosOther           ((AIReal) 0.5522847498)                                                         /* (4/3) [2^(1/2) - 1] */
00108 #define kAIRealGolden                           ((AIReal) 1.6180339888)                                                         /* [1 + 5^(1/2)]/2 */
00109 
00110 #define kSmallestFixedNumberEquivalent_Tolerance                ((AIReal) (1.0 / (1 << 16)) )   // 1 / 2^16
00111 #define kAIRealTolerance                                                                kSmallestFixedNumberEquivalent_Tolerance
00112 
00113 #define kAIMinTransformDimensionValue                   ((AIReal) 0.00001)
00114 #define kAIToleranceForZero                             ((AIReal) (1.0 / (1 << 19)) )    // 1 / 2^19
00115 
00116 
00117 /*******************************************************************************
00118  **
00119  **     Macros
00120  **
00121  **/
00122 
00123 #if __BUILD_PLUGIN__
00124 
00125 // This code used to depend on WIN_ENV.  But fmin, round, and floor are not ANSI,
00126 // and they don't seem to be available on the Mac.
00127 
00128 #define _AIRealMIN(x, y)        ((x) > (y) ? (y) : (x))
00129 #define _AIRealMAX(x, y)        ((x) > (y) ? (x) : (y))
00130 #define _AIRealAbs(x)           ((x) >= kAIRealZero ? (x) : -(x))
00131 
00132 #define _AIRealRound( x)                (AIReal)( (x) > 0 ? floor((x) + 0.5) : ceil((x) - 0.5))
00133 // NOTE:  Trunc() trunc toward 0
00134 #define _AIRealTrunc( x)                (AIReal)( (x) > 0 ? floor((x)) : ceil((x)))
00135 #define _AIRealFloor( x)                (AIReal)floor( x)
00136 
00137 #if 0           // Formerly #ifndef WIN_ENV
00138         #define _AIRealMIN( x, y)       fmin( (x), (y))
00139         #define _AIRealMAX( x, y)       fmax( (x), (y))
00140 
00141         #define _AIRealRound( x)                (AIReal)round( x)
00142         #define _AIRealFloor( x)                (AIReal)floor( x)
00143         #define _AIRealTrunc( x)                (AIReal)trunc( x)
00144 #endif
00145 
00146 // type conversion macros
00147 #define _ShortToAIReal(a)               ((AIReal) (a))
00148 #define _AIRealRoundToShort(a)  ((ai::int16) _AIRealRound(a))
00149 #define _AIRealTruncToShort(a)  ((ai::int16) _AIRealTrunc(a))
00150 
00151 // other macros
00152 
00153 #define _AIRealFraction(a)              ((AIReal) ((a) - _AIRealTrunc(a)))
00154 #define _AIRealAverage(a, b)    ((AIReal) (((a) + (b)) / 2.0))
00155 #define _AIRealHalf(a)                  ((AIReal) ((a) / 2.0))
00156 #define _AIRealOverflow(a)              ((a) == kAIRealMax || (a) == kAIRealMin)
00157 
00158 #define _AIRealSign(a)                  ((AIReal) ((a) > 0 ? +1 : ((a) < 0 ? -1 : 0)))
00159 
00160 //FIXME: Removed AIRealCeiling, because the definition of its fixed counterpart
00161 //implies that it's meaningless for floats.
00162 //#define _AIRealCeiling(a)             _AIRealFloor((a) + kAIRealOne1)
00163 
00164 
00165 #endif
00166 
00167 
00168 /*******************************************************************************
00169  **
00170  **     Suite
00171  **
00172  **/
00173 
00193 typedef struct {
00194 
00201         AIAPI AIReal (*AIRealAdd) ( AIReal a, AIReal b );
00202 
00209         AIAPI AIReal (*AIRealMul) ( AIReal a, AIReal b );
00210 
00217         AIAPI AIReal (*AIRealDiv) ( AIReal a, AIReal b );
00218 
00225         AIAPI AIReal (*ShortRatio) ( ai::int16 a, ai::int16 b );
00226 
00233         AIAPI AIReal (*AIRealRatio) ( AIReal a, AIReal b );
00234 
00243         AIAPI AIReal (*AIRealMulAdd) ( AIReal a, AIReal b, AIReal c, AIReal d );
00244 
00256         AIAPI AIReal (*AIRealMultiple) (AIReal a, AIReal multiple, AIBoolean ceiling );
00257 
00262         AIAPI AIReal (*AIRealSin) ( AIReal a );
00263 
00268         AIAPI AIReal (*AIRealCos) ( AIReal a );
00269 
00276         AIAPI AIReal (*AIRealATan) ( AIReal a, AIReal b );
00277 
00282         AIAPI AIReal (*DegreeToRadian) ( AIReal degree );
00283 
00288     AIAPI AIReal (*RadianToDegree) ( AIReal radian );
00289 
00294         AIAPI AIReal (*AIRealSqrt) ( AIReal a );
00295 
00302         AIAPI AIReal (*AIRealLength) ( AIReal a, AIReal b );
00303 
00313         AIAPI AIReal (*AIRealInterpolate) ( AIReal a, AIReal b, AIReal t );
00314 
00321         AIAPI void (*AIRealPointAdd) ( const AIRealPoint *a, const AIRealPoint *b, AIRealPoint *result );
00322 
00329         AIAPI void (*AIRealPointSubtract) ( const AIRealPoint *a, const AIRealPoint *b, AIRealPoint *result );
00330 
00337         AIAPI AIBoolean (*AIRealPointEqual) ( const AIRealPoint *a, const AIRealPoint *b );
00338 
00349         AIAPI AIBoolean (*AIRealPointClose) ( const AIRealPoint *a, const AIRealPoint *b, AIReal tolerance );
00350 
00356         AIAPI AIReal (*AIRealPointAngle) ( const AIRealPoint *a, const AIRealPoint *b );
00357 
00363         AIAPI AIReal (*AIRealPointLength) ( const AIRealPoint *a, const AIRealPoint *b );
00364 
00370         AIAPI void (*AIRealPointLengthAngle) ( AIReal length, AIReal angle, AIRealPoint *result );
00371 
00380         AIAPI void (*AIRealPointInterpolate) ( const AIRealPoint *a, const AIRealPoint *b, AIReal t, AIRealPoint *result );
00381 
00391         AIAPI void (*AIRealRectSet) ( AIRealRect *a, AIReal left, AIReal top, AIReal right, AIReal bottom );
00392 
00399         AIAPI AIBoolean (*AIRealRectEqual) ( const AIRealRect *a, const AIRealRect *b );
00400 
00408         AIAPI AIBoolean (*AIRealRectEmpty) ( const AIRealRect *a );
00409 
00417         AIAPI void (*AIRealRectInset) ( AIRealRect *a, AIReal h, AIReal v );
00418 
00426         AIAPI void (*AIRealRectOffset) ( AIRealRect *a, AIReal h, AIReal v );
00427 
00433         AIAPI void (*AIRealRectUnion) ( const AIRealRect *a, const AIRealRect *b, AIRealRect *result );
00434 
00440         AIAPI void (*AIRealPointUnion) ( const AIRealPoint *a, const AIRealRect *b, AIRealRect *result );
00441 
00447         AIAPI AIBoolean (*AIRealRectOverlap) ( const AIRealRect *a, const AIRealRect *b );
00448 
00455         AIAPI AIBoolean (*AIRealRectIntersect) ( const AIRealRect *a, const AIRealRect *b, AIRealRect *result );
00456 
00463         AIAPI AIBoolean (*AIRealRectInAIRealRect) ( const AIRealRect *a, const AIRealRect *b );
00464 
00471         AIAPI AIBoolean (*AIRealPointInAIRealRect) ( const AIRealPoint *a, const AIRealRect *b );
00472 
00480         AIAPI void (*AIRealRectAlign) ( const AIRealRect *a, AIRealRect *result );
00481 
00491         AIAPI void (*AIRealMatrixSet) ( AIRealMatrix *m, AIReal a, AIReal b, AIReal c, AIReal d, AIReal tx, AIReal ty );
00492 
00496         AIAPI void (*AIRealMatrixSetIdentity) ( AIRealMatrix *m );
00497 
00503         AIAPI AIBoolean (*AIRealMatrixEqual) ( const AIRealMatrix *m, const AIRealMatrix *n );
00504 
00509         AIAPI AIBoolean (*AIRealMatrixIdentity) ( const AIRealMatrix *m );
00510 
00515         AIAPI AIBoolean (*AIRealMatrixSingular) ( const AIRealMatrix *m );
00516 
00522         AIAPI void (*AIRealMatrixSetTranslate) ( AIRealMatrix *m, AIReal tx, AIReal ty );
00523 
00529         AIAPI void (*AIRealMatrixSetScale) ( AIRealMatrix *m, AIReal h, AIReal v );
00530 
00535         AIAPI void (*AIRealMatrixSetRotate) ( AIRealMatrix *m, AIReal angle );
00536 
00543         AIAPI void (*AIRealMatrixConcatTranslate) ( AIRealMatrix *m, AIReal tx, AIReal ty );
00544 
00551         AIAPI void (*AIRealMatrixConcatScale) ( AIRealMatrix *m, AIReal h, AIReal v );
00552 
00558         AIAPI void (*AIRealMatrixConcatRotate) ( AIRealMatrix *m, AIReal angle );
00559 
00565         AIAPI void (*AIRealMatrixConcat) (const AIRealMatrix *m, const AIRealMatrix *n, AIRealMatrix *result );
00566 
00571         AIAPI ai::int16 (*AIRealMatrixInvert) (AIRealMatrix *m );
00572 
00578         AIAPI void (*AIRealMatrixXformPoint) ( const AIRealMatrix *m, const AIRealPoint *a, AIRealPoint *result );
00579     
00585     AIAPI void (*AIRealMatrixXformRect) ( const AIRealMatrix *m, const AIRealRect *a, AIRealRect *result );
00586 
00591         AIAPI AIFixed (*AIRealToAIFixed) ( AIReal r );
00592 
00597         AIAPI AIReal (*AIFixedToAIReal) ( AIFixed f );
00598 
00603         AIAPI void (*AIRealPointToAIFixedPoint) ( const AIRealPoint *r, AIFixedPoint *f );
00604 
00609         AIAPI void (*AIFixedPointToAIRealPoint) ( const AIFixedPoint *f, AIRealPoint *r );
00610 
00615         AIAPI void (*AIRealRectToAIFixedRect) ( const AIRealRect *r, AIFixedRect *f );
00616 
00621         AIAPI void (*AIFixedRectToAIRealRect) ( const AIFixedRect *f, AIRealRect *r );
00622 
00627         AIAPI void (*AIRealMatrixToAIFixedMatrix) ( const AIRealMatrix *r, AIFixedMatrix *f );
00628 
00633         AIAPI void (*AIFixedMatrixToAIRealMatrix) ( const AIFixedMatrix *f, AIRealMatrix *r );
00634 
00635 
00636 //      AIAPI void (*AIFloatMatrixToAIRealMatrix) ( const AIFloatMatrix *f, AIRealMatrix *r );
00637 
00638         AIAPI void (*AIFloatMatrixToAIRealMatrix) ( const AIFloatMatrix *f, AIRealMatrix *r );
00639 
00640         
00641         AIAPI void (*AIFloatPointToAIRealPoint) ( const AIFloatPoint *f, AIRealPoint *r );
00642         
00643         
00644         
00654         AIAPI AIBoolean (*IsAIRealUnknown) ( AIReal r );
00655 
00661         AIAPI AIBoolean (*AIRealIsNAN) ( AIReal r );
00662 
00670         AIAPI AIBoolean (*AlmostEqual) (const AIReal a, const AIReal b, const AIReal percent);
00671 
00678         AIAPI AIBoolean (*EqualWithinTol) (const AIReal a, const AIReal b, const AIReal tolerance);
00679 
00685         AIAPI void (*AIRealMatrixGetTranslate) ( const AIRealMatrix *m, AIReal *tx, AIReal *ty );
00686 
00692         AIAPI void (*AIRealMatrixGetScale) ( const AIRealMatrix *m, AIReal *h, AIReal *v );
00693 
00698         AIAPI void (*AIRealMatrixGetRotate) ( const AIRealMatrix *m, AIReal *angle );
00699 
00706         AIAPI void (*AIDoubleRectUnion) ( const AIDoubleRect *a, const AIDoubleRect *b, AIDoubleRect *result );
00707 
00714         AIAPI AIReal(*RestrictAngleToRange)(AIReal angle, AIReal startAngle);
00715 } AIRealMathSuite;
00716 
00717 
00718 #include "AIHeaderEnd.h"
00719 
00720 
00721 #endif


Contents Suites Classes Class Index Member Index
Adobe Solutions Network
 
Copyright © 2014 Adobe Systems Incorporated. All rights reserved.
Terms of Use Online Privacy Policy Adobe and accessibility Avoid software piracy Permissions and Trademarks