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

FXExtentd.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *          D o u b 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 FXEXTENTD_H
00022 #define FXEXTENTD_H
00023 
00024 
00025 namespace FX {
00026 
00027 
00028 /// Extent
00029 class FXAPI FXExtentd {
00030 public:
00031   FXVec2d lower;
00032   FXVec2d upper;
00033 public:
00034 
00035   /// Default constructor; value is not initialized
00036   FXExtentd(){}
00037 
00038   /// Copy constructor
00039   FXExtentd(const FXExtentd& ext):lower(ext.lower),upper(ext.upper){}
00040 
00041   /// Initialize with a single point
00042   FXExtentd(const FXVec2d& p):lower(p),upper(p){}
00043 
00044   /// Initialize from corner points
00045   FXExtentd(const FXVec2d& lo,const FXVec2d& hi):lower(lo),upper(hi){}
00046 
00047   /// Initialize with a single point
00048   FXExtentd(FXdouble x,FXdouble y):lower(x,y),upper(x,y){}
00049 
00050   /// Initialize with explicit values
00051   FXExtentd(FXdouble xl,FXdouble xh,FXdouble yl,FXdouble yh):lower(xl,yl),upper(xh,yh){}
00052 
00053   /// Assignment
00054   FXExtentd& operator=(const FXExtentd& ext){ lower=ext.lower; upper=ext.upper; return *this; }
00055 
00056   /// Set value from another range
00057   FXExtentd& set(const FXExtentd& ext){ lower=ext.lower; upper=ext.upper; return *this; }
00058 
00059   /// Set value from single point
00060   FXExtentd& set(const FXVec2d& p){ lower=upper=p; return *this; }
00061 
00062   /// Set value from corner points
00063   FXExtentd& set(const FXVec2d& lo,const FXVec2d& hi){ lower=lo; upper=hi; return *this; }
00064 
00065   /// Set value from single point
00066   FXExtentd& set(FXdouble x,FXdouble y){ lower.x=upper.x=x; lower.y=upper.y=y; return *this; }
00067 
00068   /// Set value from explicit values
00069   FXExtentd& set(FXdouble xl,FXdouble xh,FXdouble yl,FXdouble yh){ lower.set(xl,yl); upper.set(xh,yh); return *this; }
00070 
00071   /// Indexing with 0..1
00072   FXVec2d& operator[](FXint i){ return (&lower)[i]; }
00073 
00074   /// Indexing with 0..1
00075   const FXVec2d& operator[](FXint i) const { return (&lower)[i]; }
00076 
00077   /// Comparison
00078   FXbool operator==(const FXExtentd& ext) const { return lower==ext.lower && upper==ext.upper;}
00079   FXbool operator!=(const FXExtentd& ext) const { return lower!=ext.lower || upper!=ext.upper;}
00080 
00081   /// Width of box
00082   FXdouble width() const { return upper.x-lower.x; }
00083 
00084   /// Height of box
00085   FXdouble height() const { return upper.y-lower.y; }
00086 
00087   /// Longest side
00088   FXdouble longest() const;
00089 
00090   /// shortest side
00091   FXdouble shortest() const;
00092 
00093   /// Length of diagonal
00094   FXdouble diameter() const;
00095 
00096   /// Get radius of box
00097   FXdouble radius() const;
00098 
00099   /// Compute diagonal
00100   FXVec2d diagonal() const;
00101 
00102   /// Get center of box
00103   FXVec2d center() const;
00104 
00105   /// Test if empty
00106   FXbool empty() const;
00107 
00108   /// Test if box contains point x,y
00109   FXbool contains(FXdouble x,FXdouble y) const;
00110 
00111   /// Test if box contains point p
00112   FXbool contains(const FXVec2d& p) const;
00113 
00114   /// Test if box properly contains another box
00115   FXbool contains(const FXExtentd& ext) const;
00116 
00117   /// Include point
00118   FXExtentd& include(FXdouble x,FXdouble y);
00119 
00120   /// Include point
00121   FXExtentd& include(const FXVec2d& v);
00122 
00123   /// Include given range into extent
00124   FXExtentd& include(const FXExtentd& ext);
00125 
00126   /// Get corner number 0..3
00127   FXVec2d corner(FXint c) const { return FXVec2d((&lower)[c&1].x, (&lower)[(c>>1)&1].y); }
00128   };
00129 
00130 
00131 /// Test if bounds overlap
00132 extern FXAPI FXbool overlap(const FXExtentd& a,const FXExtentd& b);
00133 
00134 /// Union of two boxes
00135 extern FXAPI FXExtentd unite(const FXExtentd& a,const FXExtentd& b);
00136 
00137 /// Intersection of two boxes
00138 extern FXAPI FXExtentd intersect(const FXExtentd& a,const FXExtentd& b);
00139 
00140 /// Save object to a stream
00141 extern FXAPI FXStream& operator<<(FXStream& store,const FXExtentd& ext);
00142 
00143 /// Load object from a stream
00144 extern FXAPI FXStream& operator>>(FXStream& store,FXExtentd& ext);
00145 
00146 }
00147 
00148 #endif
00149 

Copyright © 1997-2010 Jeroen van der Zijp