## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# csgeom/fixed.h

Go to the documentation of this file.

    00001 /*
    00002     Copyright (C) 2005 by Jorrit Tyberghein
    00003                   2005 by Frank Richter
    00004
    00005     This library is free software; you can redistribute it and/or
    00006     modify it under the terms of the GNU Library General Public
    00007     License as published by the Free Software Foundation; either
    00008     version 2 of the License, or (at your option) any later version.
    00009
    00010     This library is distributed in the hope that it will be useful,
    00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013     Library General Public License for more details.
    00014
    00015     You should have received a copy of the GNU Library General Public
    00016     License along with this library; if not, write to the Free
    00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00018 */
    00019
    00020 #ifndef __CS_CSGEOM_FIXED_H__
    00021 #define __CS_CSGEOM_FIXED_H__
    00022
    00023 #include "csqint.h"
    00024
    00036 class csFixed16
    00037 {
    00038   int32 v;
    00039 public:
    00040   csFixed16 () {}
    00041   csFixed16 (const float f) : v (csQfixed16 (f)) {}
    00042
    00044   csFixed16& operator= (const float f)
    00045   {
    00046     v = csQfixed16 (f);
    00047     return *this;
    00048   }
    00049
    00051   inline friend csFixed16 operator- (const csFixed16& v1,
    00052     const csFixed16& v2)
    00053   {
    00054     csFixed16 v;
    00055     v.v = v1.v - v2.v;
    00056     return v;
    00057   }
    00059   inline friend csFixed16 operator- (float v1,
    00060     const csFixed16& v2)
    00061   {
    00062     csFixed16 v;
    00063     v.v = csQfixed16 (v1) - v2.v;
    00064     return v;
    00065   }
    00067   inline friend csFixed16 operator- (const csFixed16& v1,
    00068     float v2)
    00069   {
    00070     csFixed16 v;
    00071     v.v = v1.v - csQfixed16 (v2);
    00072     return v;
    00073   }
    00074
    00076   inline friend csFixed16 operator* (const csFixed16& v1,
    00077     float v2)
    00078   {
    00079     csFixed16 v;
    00080     v.v = (int32)(v1.v * v2);
    00081     return v;
    00082   }
    00083
    00085   inline friend csFixed16 operator* (const csFixed16& v1,
    00086     int v2)
    00087   {
    00088     csFixed16 v;
    00089     v.v = v1.v * v2;
    00090     return v;
    00091   }
    00092
    00094   inline csFixed16& operator+= (const csFixed16& x)
    00095   {
    00096     v += x.v;
    00097     return *this;
    00098   }
    00099
    00101   inline operator int() const
    00102   { return v >> 16; }
    00103
    00105   inline int32 GetFixed() const { return v; }
    00106
    00108   inline friend csFixed16 operator>> (const csFixed16& v1, int n)
    00109   {
    00110     csFixed16 vn;
    00111     vn.v = v1.v >> n;
    00112     return vn;
    00113   }
    00114 };
    00115
    00120 class csFixed24
    00121 {
    00122   int32 v;
    00123 public:
    00125   csFixed24& operator= (float f)
    00126   {
    00127     v = csQfixed24 (f);
    00128     return *this;
    00129   }
    00130
    00132   inline friend csFixed24 operator- (const csFixed24& v1,
    00133     const csFixed24& v2)
    00134   {
    00135     csFixed24 v;
    00136     v.v = v1.v - v2.v;
    00137     return v;
    00138   }
    00140   inline friend csFixed24 operator- (float v1,
    00141     const csFixed24& v2)
    00142   {
    00143     csFixed24 v;
    00144     v.v = csQfixed24 (v1) - v2.v;
    00145     return v;
    00146   }
    00148   inline friend csFixed24 operator- (const csFixed24& v1,
    00149     float v2)
    00150   {
    00151     csFixed24 v;
    00152     v.v = v1.v - csQfixed24 (v2);
    00153     return v;
    00154   }
    00155
    00157   inline friend csFixed24 operator* (const csFixed24& v1,
    00158     float v2)
    00159   {
    00160     csFixed24 v;
    00161     v.v = (int32)(v1.v * v2);
    00162     return v;
    00163   }
    00164
    00166   inline csFixed24& operator+= (const csFixed24& x)
    00167   {
    00168     v += x.v;
    00169     return *this;
    00170   }
    00171
    00173   inline operator int() const
    00174   { return v >> 16; }
    00175
    00177   inline int32 GetFixed() const { return v; }
    00178 };
    00179
    00182 #endif // __CS_CSGEOM_FIXED_H__
    00183