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

/home/jeroen/FOX/fox/fox-1.7.33/include/FXExtentf.h
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,2012 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 
00029 class FXAPI FXExtentf {
00030 public:
00031   FXVec2f lower;
00032   FXVec2f upper;
00033 public:
00034 
00036   FXExtentf(){}
00037 
00039   FXExtentf(const FXExtentf& ext):lower(ext.lower),upper(ext.upper){}
00040 
00042   FXExtentf(const FXVec2f& p):lower(p),upper(p){}
00043 
00045   FXExtentf(const FXVec2f& lo,const FXVec2f& hi):lower(lo),upper(hi){}
00046 
00048   FXExtentf(FXfloat x,FXfloat y):lower(x,y),upper(x,y){}
00049 
00051   FXExtentf(FXfloat xl,FXfloat xh,FXfloat yl,FXfloat yh):lower(xl,yl),upper(xh,yh){}
00052 
00054   FXExtentf& operator=(const FXExtentf& ext){ lower=ext.lower; upper=ext.upper; return *this; }
00055 
00057   FXExtentf& set(const FXExtentf& ext){ lower=ext.lower; upper=ext.upper; return *this; }
00058 
00060   FXExtentf& set(const FXVec2f& p){ lower=upper=p; return *this; }
00061 
00063   FXExtentf& set(const FXVec2f& lo,const FXVec2f& hi){ lower=lo; upper=hi; return *this; }
00064 
00066   FXExtentf& set(FXfloat x,FXfloat y){ lower.x=upper.x=x; lower.y=upper.y=y; return *this; }
00067 
00069   FXExtentf& set(FXfloat xl,FXfloat xh,FXfloat yl,FXfloat yh){ lower.set(xl,yl); upper.set(xh,yh); return *this; }
00070 
00072   FXVec2f& operator[](FXint i){ return (&lower)[i]; }
00073 
00075   const FXVec2f& operator[](FXint i) const { return (&lower)[i]; }
00076 
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 
00082   FXfloat width() const { return upper.x-lower.x; }
00083 
00085   FXfloat height() const { return upper.y-lower.y; }
00086 
00088   FXfloat longest() const;
00089 
00091   FXfloat shortest() const;
00092 
00094   FXfloat diameter() const;
00095 
00097   FXfloat radius() const;
00098 
00100   FXVec2f diagonal() const;
00101 
00103   FXVec2f center() const;
00104 
00106   FXbool empty() const;
00107 
00109   FXbool contains(FXfloat x,FXfloat y) const;
00110 
00112   FXbool contains(const FXVec2f& p) const;
00113 
00115   FXbool contains(const FXExtentf& ext) const;
00116 
00118   FXExtentf& include(FXfloat x,FXfloat y);
00119 
00121   FXExtentf& include(const FXVec2f& v);
00122 
00124   FXExtentf& include(const FXExtentf& ext);
00125 
00127   FXVec2f corner(FXint c) const { return FXVec2f((&lower)[c&1].x, (&lower)[(c>>1)&1].y); }
00128 
00130  ~FXExtentf(){}
00131   };
00132 
00133 
00135 extern FXAPI FXbool overlap(const FXExtentf& a,const FXExtentf& b);
00136 
00138 extern FXAPI FXExtentf unite(const FXExtentf& a,const FXExtentf& b);
00139 
00141 extern FXAPI FXExtentf intersect(const FXExtentf& a,const FXExtentf& b);
00142 
00144 extern FXAPI FXStream& operator<<(FXStream& store,const FXExtentf& ext);
00145 
00147 extern FXAPI FXStream& operator>>(FXStream& store,FXExtentf& ext);
00148 
00149 }
00150 
00151 #endif
00152 

Copyright © 1997-2011 Jeroen van der Zijp