FXRanged.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    R a n g e    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: FXRanged.h,v 1.17 2006/01/22 17:58:08 fox Exp $                          *
00023 ********************************************************************************/
00024 #ifndef FXRANGED_H
00025 #define FXRANGED_H
00026 
00027 
00028 namespace FX {
00029 
00030 
00031 class FXSphered;
00032 
00033 
00035 class FXAPI FXRanged {
00036 public:
00037   FXVec3d lower;
00038   FXVec3d upper;
00039 public:
00040 
00042   FXRanged(){}
00043 
00045   FXRanged(const FXRanged& bounds):lower(bounds.lower),upper(bounds.upper){}
00046 
00048   FXRanged(const FXVec3d& lo,const FXVec3d& hi):lower(lo),upper(hi){}
00049 
00051   FXRanged(FXdouble xlo,FXdouble xhi,FXdouble ylo,FXdouble yhi,FXdouble zlo,FXdouble zhi):lower(xlo,ylo,zlo),upper(xhi,yhi,zhi){}
00052 
00054   FXRanged(const FXSphered& sphere);
00055 
00057   FXRanged& operator=(const FXRanged& bounds){ lower=bounds.lower; upper=bounds.upper; return *this; }
00058 
00060   FXRanged& set(const FXRanged& bounds){ lower=bounds.lower; upper=bounds.upper; return *this; }
00061 
00063   FXRanged& set(const FXVec3d& lo,const FXVec3d& hi){ lower=lo; upper=hi; return *this; }
00064 
00066   FXRanged& set(FXdouble xlo,FXdouble xhi,FXdouble ylo,FXdouble yhi,FXdouble zlo,FXdouble zhi){ lower.set(xlo,ylo,zlo); upper.set(xhi,yhi,zhi); return *this; }
00067 
00069   FXVec3d& operator[](FXint i){ return (&lower)[i]; }
00070 
00072   const FXVec3d& operator[](FXint i) const { return (&lower)[i]; }
00073 
00075   bool operator==(const FXRanged& r) const { return lower==r.lower && upper==r.upper; }
00076   bool operator!=(const FXRanged& r) const { return lower!=r.lower || upper!=r.upper; }
00077 
00079   FXdouble width() const { return upper.x-lower.x; }
00080 
00082   FXdouble height() const { return upper.y-lower.y; }
00083 
00085   FXdouble depth() const { return upper.z-lower.z; }
00086 
00088   FXdouble longest() const;
00089 
00091   FXdouble shortest() const;
00092 
00094   FXdouble diameter() const;
00095 
00097   FXdouble radius() const;
00098 
00100   FXVec3d diagonal() const;
00101 
00103   FXVec3d center() const;
00104 
00106   bool empty() const;
00107 
00109   bool contains(FXdouble x,FXdouble y,FXdouble z) const;
00110 
00112   bool contains(const FXVec3d& p) const;
00113 
00115   bool contains(const FXRanged& bounds) const;
00116 
00118   bool contains(const FXSphered& sphere) const;
00119 
00121   FXRanged& include(FXdouble x,FXdouble y,FXdouble z);
00122 
00124   FXRanged& include(const FXVec3d& v);
00125 
00127   FXRanged& include(const FXRanged& box);
00128 
00130   FXRanged& include(const FXSphered& sphere);
00131 
00133   FXint intersect(const FXVec4d &plane) const;
00134 
00136   bool intersect(const FXVec3d& u,const FXVec3d& v);
00137 
00139   friend FXAPI bool overlap(const FXRanged& a,const FXRanged& b);
00140 
00142   FXVec3d corner(FXint c) const { return FXVec3d((&lower)[c&1].x, (&lower)[(c>>1)&1].y, (&lower)[c>>2].z); }
00143 
00145   friend FXAPI FXRanged unite(const FXRanged& a,const FXRanged& b);
00146 
00148   friend FXAPI FXRanged intersect(const FXRanged& a,const FXRanged& b);
00149 
00151   friend FXAPI FXStream& operator<<(FXStream& store,const FXRanged& bounds);
00152 
00154   friend FXAPI FXStream& operator>>(FXStream& store,FXRanged& bounds);
00155   };
00156 
00157 
00158 extern FXAPI bool overlap(const FXRanged& a,const FXRanged& b);
00159 
00160 extern FXAPI FXRanged unite(const FXRanged& a,const FXRanged& b);
00161 extern FXAPI FXRanged intersect(const FXRanged& a,const FXRanged& b);
00162 
00163 extern FXAPI FXStream& operator<<(FXStream& store,const FXRanged& bounds);
00164 extern FXAPI FXStream& operator>>(FXStream& store,FXRanged& bounds);
00165 
00166 }
00167 
00168 #endif
00169 

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