fixed24.h

Go to the documentation of this file.
00001 // $Id: fixed24.h 751 2006-03-31 15:43:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 
00100 /*
00101 */ 
00102 
00103 // Stardate 070494.10:25. Captain's Log - supplementary
00104 // ====================================================
00105 //
00106 //      Pirated fixed16 code to base fixed24 upon
00107 //      This was from revision 1.27 of fixed16.h
00108 //                                                Jason
00109 
00110 
00111 /*********************************************************************************************
00112 
00113 >   class FIXED24
00114 
00115     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com> (Hijacked by Jason)
00116     Created:    26/4/1993 (07/04/94)
00117     SeeAlso:    CCMaths.h
00118     SeeAlso:    Fixedasm.h
00119     SeeAlso:    Div32By32
00120     SeeAlso:    Keyword FIXED24
00121     SeeAlso:    Keyword FIXED16
00122     Purpose:    
00123         A FIXED24 is a signed 32-bit value with a binary point between bits 23 and 24
00124         Its purpose is to represent floating point numbers in 32 bits.
00125         The implementation is very similar to FIXED16, but note that many methods are
00126         currently not defined in FIXED24, as it is used only in the colour system, which
00127         does not need large chunks of the FIXED16 functionality.
00128         No-one should include fixed24.h directly - always use ccmath.h. You should also
00129         never use the lower-case type 'fixed24' - always used 'FIXED24'.    
00130 
00131         Operations from FIXED16 that are not available in FIXED24 are currently removed
00132         by the use of #ifdef FULL_FIXED24 directives. (if there is no help on a function,
00133         then it is currently unsupported in FIXED24)
00134 
00135     Errors:     None.
00136     
00137 ********************************************************************************************/
00138 
00139 #ifndef INC_FIXED24
00140 #define INC_FIXED24
00141 
00142 #if !defined(USE_NATIVE_XLONG)
00143 class CCAPI xlong;
00144 #endif
00145 
00146 #ifdef FULL_FIXED24
00147 class CCAPI String;
00148 #endif
00149 
00150 class CCAPI fixed24
00151 {
00152 public:
00153     INT32 all;
00154 
00155 public:
00156 
00157     #define F24SHIFT (24)                               // marks binary point position
00158 
00159     // this converts a short into a fixed24 longword by casting to an INT32 then shifting it
00160     #define SHORT_FIXED24(x)    ( ((INT32)(x)) << F24SHIFT )
00161 
00162     inline fixed24() {};
00163     inline fixed24(const fixed24&);
00164     inline fixed24(INT32);
00165     inline fixed24(short);
00166     inline fixed24(double);
00167 
00168 #ifdef FULL_FIXED24
00169     fixed24& Sin();
00170     fixed24& Cos();
00171     
00172     void ToString(String* out) const;
00173 #endif
00174 
00175 
00176     // Friend Functions
00177 
00178     friend fixed24 CCAPI operator+ (const fixed24&, const fixed24&);
00179     friend fixed24 CCAPI operator- (const fixed24&, const fixed24&);
00180     friend fixed24 CCAPI operator- (const fixed24&);
00181     friend fixed24 CCAPI operator* (const fixed24&, const fixed24&);
00182     friend fixed24 CCAPI operator/ (const fixed24&, const fixed24&);
00183     friend fixed24 CCAPI operator>> (const fixed24&, UINT32);
00184     friend fixed24 CCAPI operator<< (const fixed24&, UINT32);
00185 
00186     // Relational Operators
00187     
00188     friend INT32 CCAPI operator== (const fixed24&, const fixed24&);
00189     friend INT32 CCAPI operator!= (const fixed24&, const fixed24&);
00190     friend INT32 CCAPI operator> (const fixed24&, const fixed24&);
00191     friend INT32 CCAPI operator< (const fixed24&, const fixed24&);
00192     friend INT32 CCAPI operator>= (const fixed24&, const fixed24&);
00193     friend INT32 CCAPI operator<= (const fixed24&, const fixed24&);
00194 
00195     friend INT32 CCAPI operator== (const fixed24&, const short);
00196     friend INT32 CCAPI operator!= (const fixed24&, const short);
00197     friend INT32 CCAPI operator> (const fixed24&, const short);
00198     friend INT32 CCAPI operator< (const fixed24&, const short);
00199     friend INT32 CCAPI operator>= (const fixed24&, const short);
00200     friend INT32 CCAPI operator<= (const fixed24&, const short);
00201     
00202     // Assignment Operators
00203 
00204     inline fixed24& operator= (const fixed24&);
00205     fixed24& operator= (const INT32);
00206     inline fixed24& operator= (const short);
00207     fixed24& operator= (const double);
00208     fixed24& operator+= (const fixed24&);
00209     fixed24& operator+= (const short);
00210     fixed24& operator-= (const fixed24&); 
00211     fixed24& operator-= (const short);
00212     fixed24& operator*= (const fixed24&); 
00213     fixed24& operator*= (const short);
00214     fixed24& operator/= (const fixed24&);
00215     fixed24& operator/= (const short); 
00216     fixed24& operator<<= (const UINT32); 
00217     fixed24& operator>>= (const UINT32); 
00218 
00219 
00220     // Increment\Decrement Operators
00221 
00222     fixed24& operator++ ();                         // prefix
00223     fixed24 operator++ (INT32);                     // postfix 
00224     fixed24& operator-- ();                         // prefix 
00225     fixed24 operator-- (INT32);                     // postfix 
00226 
00227     // Conversion functions
00228 
00229     inline INT32     MakeInt() const;
00230     inline short MakeShort() const;
00231     inline double MakeDouble() const;
00232     inline INT32  MakeLong() const;
00233     inline xlong MakeXlong() const;
00234 
00235     inline static fixed24 FromRawLong(INT32 d);     // DO NOT USE!
00236 
00237     inline INT32 GetAsFixed24(void);
00238     inline void SetAsFixed24(INT32 NewValue);
00239 };
00240 
00241 
00242 typedef fixed24 FIXED24;
00243 
00244 
00245 #include "fix24.h"
00246 
00247 /********************************************************************************************
00248 
00249 >   FIXED24_DBL(d) 
00250 
00251     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00252     Created:    10/6/93
00253     Inputs:     double.
00254     Outputs:    None
00255     Returns:    FIXED24.
00256     Purpose:    
00257         This macro converts constant doubles into FIXED24s at compile time. It is 
00258         very effecient because there is no runtime overhead unlike normal conversion.  
00259         
00260     Errors:     None.
00261 
00262 ********************************************************************************************/
00263 
00264 #define FIXED24_DBL(d) fixed24::FromRawLong((INT32)((d)*(1<<24)))
00265 
00266 /********************************************************************************************
00267 
00268 >   inline FIXED24::FIXED24 () 
00269 
00270     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00271     Created:    27/4/93
00272     Inputs:     None
00273     Outputs:    None
00274     Returns:    None.
00275     Purpose:    Default constructor for FIXED24. It does not actually do anything!
00276     Errors:     None.
00277 
00278 ********************************************************************************************/
00279 
00280 // actual (null) function can be found in class
00281 
00282 /********************************************************************************************
00283 
00284 >   inline FIXED24::FIXED24 (const FIXED24&) 
00285 
00286     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00287     Created:    27/4/93
00288     Inputs:     None
00289     Outputs:    None
00290     Returns:    None.
00291     Purpose:    Copy constructor.
00292     Errors:     None.
00293 
00294 ********************************************************************************************/
00295 
00296 inline fixed24::fixed24(const fixed24& initValue) 
00297 {
00298     all = initValue.all;
00299 }
00300 
00301 /********************************************************************************************
00302 
00303 >   inline FIXED24::FIXED24 (INT32) 
00304 
00305     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00306     Created:    27/4/93
00307     Inputs:     None
00308     Outputs:    None
00309     Returns:    None.
00310     Purpose:    Constructor.
00311     Errors:     None.
00312 
00313 ********************************************************************************************/
00314 
00315 inline fixed24::fixed24(INT32 initValue) 
00316 {
00317     all = SHORT_FIXED24( initValue );
00318 }
00319 
00320 /********************************************************************************************
00321 
00322 >   inline FIXED24::FIXED24 (short) 
00323 
00324     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00325     Created:    27/4/93
00326     Inputs:     None
00327     Outputs:    None
00328     Returns:    None.
00329     Purpose:    Constructor.
00330     Errors:     None.
00331 
00332 ********************************************************************************************/
00333 
00334 inline fixed24::fixed24(short initValue) 
00335 {
00336     all = SHORT_FIXED24( initValue );
00337 }
00338 
00339 /********************************************************************************************
00340 
00341 >   inline FIXED24::FIXED24 (double) 
00342 
00343     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00344     Created:    2/6/93
00345     SeeAlso:    Fixedasm.h
00346     Inputs:     None
00347     Outputs:    None
00348     Returns:    None.
00349     Purpose:    Constructor.
00350     Errors:     None.
00351 
00352 ********************************************************************************************/
00353 
00354 inline fixed24::fixed24(double initValue) 
00355 {
00356     *this = DoubleToFixed24(initValue);
00357 }
00358 
00359 /********************************************************************************************
00360 
00361 >   inline FIXED24 FIXED24::FromRawLong(INT32 d) 
00362 
00363     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00364     Created:    2/6/93
00365     Inputs:     An INT32
00366     Outputs:    A Fixed24
00367     Returns:    None.
00368     Scope:      Private - for FIXED_DBL macro
00369                 If you wish to access the private data in a FIXED24, then please
00370                 use GetAsFixed24, which is an interface inline function which
00371                 will always present the data to the outside world in 8.24 bit
00372                 format, even if we decide to change the internal format one day.
00373     Purpose:    converts an INT32 to a FIXED24.
00374     Errors:     None.
00375 
00376 ********************************************************************************************/
00377 
00378 inline fixed24 fixed24::FromRawLong(INT32 d)
00379 {
00380     fixed24 temp;
00381 
00382     temp.all = d;
00383     return temp;
00384 }
00385 
00386 
00387 
00388 /********************************************************************************************
00389 
00390 >   inline INT32 FIXED24::GetAsFixed24(void) 
00391 
00392     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00393     Created:    12/04/94
00394     Inputs:     None
00395     Outputs:    None
00396     Returns:    A fixed point value stored as 8.24 bits in a INT32
00397     Scope:      Sortof private for use in the DocColour system
00398     Purpose:    converts a FIXED24 to an 8.24 bit fixed point value stored in
00399                 a INT32. (i.e. pulls the 8.24 data word directly out of the FIXED24,
00400                 though obviously if the storage model in a fixed24 changes in the future
00401                 we can change this access function to still return a 8.24 INT32)
00402     Errors:     None.
00403 
00404 ********************************************************************************************/
00405 
00406 inline INT32 fixed24::GetAsFixed24(void)
00407 {
00408     return((INT32) all);
00409 }
00410 
00411 
00412 /********************************************************************************************
00413 
00414 >   inline INT32 FIXED24::SetAsFixed24(void) 
00415 
00416     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00417     Created:    12/04/94
00418     Inputs:     None
00419     Outputs:    None
00420     Returns:    None
00421     Scope:      Sortof private for use in the DocColour system
00422     Purpose:    Sets a FIXED24 to an 8.24 bit fixed point value stored in a INT32.
00423                 (i.e. plonks the 8.24 data word directly into the FIXED24, though
00424                 obviously if the storage model in a fixed24 changes in the future
00425                 we can change this access function to still accept a 8.24 INT32)
00426     Errors:     None.
00427 
00428 ********************************************************************************************/
00429 
00430 inline void fixed24::SetAsFixed24(INT32 NewValue)
00431 {
00432     all = NewValue;
00433 }
00434 
00435 
00436 
00437 /********************************************************************************************
00438 
00439 >   inline INT32 FIXED24::MakeInt() const 
00440 
00441     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00442     Created:    2/6/93
00443     Inputs:     None
00444     Outputs:    None
00445     Returns:    None.
00446     Purpose:    converts a FIXED24 to an integer.
00447     Errors:     None.
00448 
00449 ********************************************************************************************/
00450 
00451 inline INT32 fixed24::MakeInt() const
00452 {
00453     return (INT32) (all >> F24SHIFT);
00454 }
00455 
00456 /********************************************************************************************
00457 
00458 >   inline short FIXED24::MakeShort() const 
00459 
00460     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00461     Created:    2/6/93
00462     SeeAlso:    Fixedasm.h
00463     Inputs:     None
00464     Outputs:    None
00465     Returns:    None.
00466     Purpose:    converts a FIXED24 to an integer.
00467     Errors:     None.
00468 
00469 ********************************************************************************************/
00470 
00471 inline short fixed24::MakeShort() const
00472 {
00473     return (short) (all >> F24SHIFT);
00474 }
00475 
00476 /********************************************************************************************
00477 
00478 >   inline INT32 FIXED24::MakeLong() const
00479 
00480     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00481     Created:    2/6/93
00482     Inputs:     None
00483     Outputs:    None
00484     Returns:    None.
00485     Purpose:    converts a FIXED24 to a INT32.
00486     Errors:     None.
00487 
00488 ********************************************************************************************/
00489 
00490 inline INT32 fixed24::MakeLong() const
00491 {
00492     return all >> F24SHIFT;
00493 }
00494 
00495 /********************************************************************************************
00496 
00497 >   inline XLONG FIXED24::MakeXlong() const
00498 
00499     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00500     Created:    2/6/93
00501     Inputs:     None
00502     Outputs:    None
00503     Returns:    None.
00504     Purpose:    converts a FIXED24 to a INT32.
00505     Errors:     None.
00506 
00507 ********************************************************************************************/
00508 
00509 inline xlong fixed24::MakeXlong() const
00510 {
00511     return xlong( (short) (all >> F24SHIFT) );
00512 }
00513 
00514 /********************************************************************************************
00515 
00516 >   inline FIXED24& operator= (const FIXED24& operand) 
00517 
00518     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00519     Created:    27/4/93
00520     Inputs:     operand to be  assigned - rhs of assignment.
00521     Outputs:    None.
00522     Returns:    A reference to an FIXED24 with result of assignment.
00523     Purpose:    Overloading the assignment operator for FIXED24s.
00524     Errors:     None.
00525 
00526 ********************************************************************************************/
00527 
00528 inline fixed24& fixed24::operator= (const fixed24& operand)
00529 { 
00530     this->all = operand.all;
00531     
00532     return *this; 
00533 }
00534 /********************************************************************************************
00535 
00536 >   inline double FIXED24::MakeDouble() const
00537 
00538     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00539     Created:    7/6/93
00540     SeeAlso:    fixedasm.h
00541     Inputs:     None
00542     Outputs:    None
00543     Returns:    double. 
00544     Purpose:    Makes a double (32-bit signed value) out of a fixed point 24-bit value.
00545     Errors:     None.
00546 
00547 ********************************************************************************************/
00548 
00549 inline double fixed24::MakeDouble() const
00550 {
00551     return Fixed24ToDouble(*this);
00552 }
00553 
00554 /********************************************************************************************
00555 
00556 >   inline FIXED24& operator= (const short operand) 
00557 
00558     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00559     Created:    27/4/93
00560     SeeAlso:    Fixedasm.h
00561     Inputs:     operand to be  assigned - rhs of assignment.
00562     Outputs:    None.
00563     Returns:    A reference to an FIXED24 with result of assignment.
00564     Purpose:    Overloading the assignment operator for FIXED24s.
00565     Errors:     None.
00566 
00567 ********************************************************************************************/
00568 
00569 inline fixed24& fixed24::operator= (const short operand)
00570 { 
00571     this->all = SHORT_FIXED24( operand );
00572     return *this;
00573 }
00574 
00575 
00576 
00577 
00578 #endif

Generated on Sat Nov 10 03:45:20 2007 for Camelot by  doxygen 1.4.4