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

FXRange.h

00001 /********************************************************************************
00002 *                                                                               *
00003 *                             R a n g e    C l a s s                            *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1994,2004 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: FXRange.h,v 1.12 2004/02/08 17:17:34 fox Exp $                           *
00023 ********************************************************************************/
00024 #ifndef FXRANGE_H
00025 #define FXRANGE_H
00026 
00027 namespace FX {
00028 
00029 
00030 /// Range
00031 class FXAPI FXRange {
00032 protected:
00033   FXfloat d[3][2];
00034 public:
00035 
00036   /// Default constructor
00037   FXRange(){}
00038 
00039   /// Initialize
00040   FXRange(FXfloat xlo,FXfloat xhi,FXfloat ylo,FXfloat yhi,FXfloat zlo,FXfloat zhi){
00041     d[0][0]=xlo; d[0][1]=xhi;
00042     d[1][0]=ylo; d[1][1]=yhi;
00043     d[2][0]=zlo; d[2][1]=zhi;
00044     }
00045 
00046   /// Length of side i
00047   FXfloat side(FXint i) const { return d[i][1]-d[i][0]; }
00048 
00049   /// Width of box
00050   FXfloat width() const { return d[0][1]-d[0][0]; }
00051 
00052   /// Height of box
00053   FXfloat height() const { return d[1][1]-d[1][0]; }
00054 
00055   /// Depth of box
00056   FXfloat depth() const { return d[2][1]-d[2][0]; }
00057 
00058   /// Longest side
00059   FXfloat longest() const;
00060 
00061   /// shortest side
00062   FXfloat shortest() const;
00063 
00064   /// Test if empty
00065   FXbool empty() const;
00066 
00067   /// Test if overlap
00068   FXbool overlap(const FXRange& box) const;
00069 
00070   /// Test if box contains point x,y,z
00071   FXbool contains(FXfloat x,FXfloat y,FXfloat z) const;
00072 
00073   /// Indexing
00074   FXfloat* operator[](FXint i){ return d[i]; }
00075 
00076   /// Indexing
00077   const FXfloat* operator[](FXint i) const { return d[i]; }
00078 
00079   /// Include given range into box
00080   FXRange& include(const FXRange& box);
00081 
00082   /// Include point
00083   FXRange& include(FXfloat x,FXfloat y,FXfloat z);
00084 
00085   /// Include point
00086   FXRange& include(const FXVec3f& v);
00087 
00088   /// Clip domain against another
00089   FXRange& clipTo(const FXRange& box);
00090 
00091   /// Get corners of box
00092   friend FXAPI void boxCorners(FXVec3f* points,const FXRange& box);
00093 
00094   /// Ray intersection test
00095   friend FXAPI FXbool boxIntersect(const FXRange& box,const FXVec3f& u,const FXVec3f& v);
00096 
00097   /// Get center of box
00098   friend FXAPI FXVec3f boxCenter(const FXRange& box);
00099 
00100   /// Compute diagonal
00101   friend FXAPI FXfloat boxDiagonal(const FXRange& box);
00102 
00103   /// Save object to a stream
00104   friend FXAPI FXStream& operator<<(FXStream& store,const FXRange& box);
00105 
00106   /// Load object from a stream
00107   friend FXAPI FXStream& operator>>(FXStream& store,FXRange& box);
00108   };
00109 
00110 }
00111 
00112 #endif

Copyright © 1997-2004 Jeroen van der Zijp