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,2006 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (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 GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************
00022 * $Id: FXExtentf.h,v 1.8.2.1 2006/07/25 01:35:36 fox Exp $                          *
00023 ********************************************************************************/
00024 #ifndef FXEXTENTF_H
00025 #define FXEXTENTF_H
00026 
00027 
00028 namespace FX {
00029 
00030 
00032 class FXAPI FXExtentf {
00033 public:
00034   FXVec2f lower;
00035   FXVec2f upper;
00036 public:
00037 
00039   FXExtentf(){}
00040 
00042   FXExtentf(const FXExtentf& ext):lower(ext.lower),upper(ext.upper){}
00043 
00045   FXExtentf(const FXVec2f& lo,const FXVec2f& hi):lower(lo),upper(hi){}
00046 
00048   FXExtentf(FXfloat xlo,FXfloat xhi,FXfloat ylo,FXfloat yhi):lower(xlo,ylo),upper(xhi,yhi){}
00049 
00051   FXExtentf& operator=(const FXExtentf& ext){ lower=ext.lower; upper=ext.upper; return *this; }
00052 
00054   FXVec2f& operator[](FXint i){ return (&lower)[i]; }
00055 
00057   const FXVec2f& operator[](FXint i) const { return (&lower)[i]; }
00058 
00060   bool operator==(const FXExtentf& ext) const { return lower==ext.lower && upper==ext.upper;}
00061   bool operator!=(const FXExtentf& ext) const { return lower!=ext.lower || upper!=ext.upper;}
00062 
00064   FXfloat width() const { return upper.x-lower.x; }
00065 
00067   FXfloat height() const { return upper.y-lower.y; }
00068 
00070   FXfloat longest() const;
00071 
00073   FXfloat shortest() const;
00074 
00076   FXfloat diameter() const;
00077 
00079   FXfloat radius() const;
00080 
00082   FXVec2f diagonal() const;
00083 
00085   FXVec2f center() const;
00086 
00088   bool empty() const;
00089 
00091   bool contains(FXfloat x,FXfloat y) const;
00092 
00094   bool contains(const FXVec2f& p) const;
00095 
00097   bool contains(const FXExtentf& ext) const;
00098 
00100   FXExtentf& include(FXfloat x,FXfloat y);
00101 
00103   FXExtentf& include(const FXVec2f& v);
00104 
00106   FXExtentf& include(const FXExtentf& ext);
00107 
00109   friend FXAPI bool overlap(const FXExtentf& a,const FXExtentf& b);
00110 
00112   FXVec2f corner(FXint c) const { return FXVec2f((&lower)[c&1].x, (&lower)[(c>>1)&1].y); }
00113 
00115   friend FXAPI FXExtentf unite(const FXExtentf& a,const FXExtentf& b);
00116 
00118   friend FXAPI FXExtentf intersect(const FXExtentf& a,const FXExtentf& b);
00119 
00121   friend FXAPI FXStream& operator<<(FXStream& store,const FXExtentf& ext);
00122 
00124   friend FXAPI FXStream& operator>>(FXStream& store,FXExtentf& ext);
00125   };
00126 
00127 
00128 extern FXAPI bool overlap(const FXExtentf& a,const FXExtentf& b);
00129 
00130 extern FXAPI FXExtentf unite(const FXExtentf& a,const FXExtentf& b);
00131 extern FXAPI FXExtentf intersect(const FXExtentf& a,const FXExtentf& b);
00132 
00133 extern FXAPI FXStream& operator<<(FXStream& store,const FXExtentf& ext);
00134 extern FXAPI FXStream& operator>>(FXStream& store,FXExtentf& ext);
00135 
00136 }
00137 
00138 #endif
00139 

(C) 2002-2009 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Nov 20 18:31:20 2009 for TnFOX by doxygen v1.4.7