Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXExtentf.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *          S i n g l e - P r e c i s i o n    E x t e n t    C l a s s          *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 2004,2010 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (at your option) any later version.                                           *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 ********************************************************************************/
00021 #ifndef FXEXTENTF_H
00022 #define FXEXTENTF_H
00023 
00024 
00025 namespace FX {
00026 
00027 
00028 /// Extent
00029 class FXAPI FXExtentf {
00030 public:
00031   FXVec2f lower;
00032   FXVec2f upper;
00033 public:
00034 
00035   /// Default constructor; value is not initialized
00036   FXExtentf(){}
00037 
00038   /// Copy constructor
00039   FXExtentf(const FXExtentf& ext):lower(ext.lower),upper(ext.upper){}
00040 
00041   /// Initialize with a single point
00042   FXExtentf(const FXVec2f& p):lower(p),upper(p){}
00043 
00044   /// Initialize from corner points
00045   FXExtentf(const FXVec2f& lo,const FXVec2f& hi):lower(lo),upper(hi){}
00046 
00047   /// Initialize with a single point
00048   FXExtentf(FXfloat x,FXfloat y):lower(x,y),upper(x,y){}
00049 
00050   /// Initialize with explicit values
00051   FXExtentf(FXfloat xl,FXfloat xh,FXfloat yl,FXfloat yh):lower(xl,yl),upper(xh,yh){}
00052 
00053   /// Assignment
00054   FXExtentf& operator=(const FXExtentf& ext){ lower=ext.lower; upper=ext.upper; return *this; }
00055 
00056   /// Set value from another range
00057   FXExtentf& set(const FXExtentf& ext){ lower=ext.lower; upper=ext.upper; return *this; }
00058 
00059   /// Set value from single point
00060   FXExtentf& set(const FXVec2f& p){ lower=upper=p; return *this; }
00061 
00062   /// Set value from corner points
00063   FXExtentf& set(const FXVec2f& lo,const FXVec2f& hi){ lower=lo; upper=hi; return *this; }
00064 
00065   /// Set value from single point
00066   FXExtentf& set(FXfloat x,FXfloat y){ lower.x=upper.x=x; lower.y=upper.y=y; return *this; }
00067 
00068   /// Set value from explicit values
00069   FXExtentf& set(FXfloat xl,FXfloat xh,FXfloat yl,FXfloat yh){ lower.set(xl,yl); upper.set(xh,yh); return *this; }
00070 
00071   /// Indexing with 0..1
00072   FXVec2f& operator[](FXint i){ return (&lower)[i]; }
00073 
00074   /// Indexing with 0..1
00075   const FXVec2f& operator[](FXint i) const { return (&lower)[i]; }
00076 
00077   /// Comparison
00078   FXbool operator==(const FXExtentf& ext) const { return lower==ext.lower && upper==ext.upper;}
00079   FXbool operator!=(const FXExtentf& ext) const { return lower!=ext.lower || upper!=ext.upper;}
00080 
00081   /// Width of box
00082   FXfloat width() const { return upper.x-lower.x; }
00083 
00084   /// Height of box
00085   FXfloat height() const { return upper.y-lower.y; }
00086 
00087   /// Longest side
00088   FXfloat longest() const;
00089 
00090   /// shortest side
00091   FXfloat shortest() const;
00092 
00093   /// Length of diagonal
00094   FXfloat diameter() const;
00095 
00096   /// Get radius of box
00097   FXfloat radius() const;
00098 
00099   /// Compute diagonal
00100   FXVec2f diagonal() const;
00101 
00102   /// Get center of box
00103   FXVec2f center() const;
00104 
00105   /// Test if empty
00106   FXbool empty() const;
00107 
00108   /// Test if box contains point x,y
00109   FXbool contains(FXfloat x,FXfloat y) const;
00110 
00111   /// Test if box contains point p
00112   FXbool contains(const FXVec2f& p) const;
00113 
00114   /// Test if box properly contains another box
00115   FXbool contains(const FXExtentf& ext) const;
00116 
00117   /// Include point
00118   FXExtentf& include(FXfloat x,FXfloat y);
00119 
00120   /// Include point
00121   FXExtentf& include(const FXVec2f& v);
00122 
00123   /// Include given range into extent
00124   FXExtentf& include(const FXExtentf& ext);
00125 
00126   /// Get corner number 0..3
00127   FXVec2f corner(FXint c) const { return FXVec2f((&lower)[c&1].x, (&lower)[(c>>1)&1].y); }
00128   };
00129 
00130 
00131 /// Test if bounds overlap
00132 extern FXAPI FXbool overlap(const FXExtentf& a,const FXExtentf& b);
00133 
00134 /// Union of two boxes
00135 extern FXAPI FXExtentf unite(const FXExtentf& a,const FXExtentf& b);
00136 
00137 /// Intersection of two boxes
00138 extern FXAPI FXExtentf intersect(const FXExtentf& a,const FXExtentf& b);
00139 
00140 /// Save object to a stream
00141 extern FXAPI FXStream& operator<<(FXStream& store,const FXExtentf& ext);
00142 
00143 /// Load object from a stream
00144 extern FXAPI FXStream& operator>>(FXStream& store,FXExtentf& ext);
00145 
00146 }
00147 
00148 #endif
00149 

Copyright © 1997-2010 Jeroen van der Zijp