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

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 2006/01/22 17:58:01 fox Exp $                          *
00023 ********************************************************************************/
00024 #ifndef FXEXTENTF_H
00025 #define FXEXTENTF_H
00026 
00027 
00028 namespace FX {
00029 
00030 
00031 /// Extent
00032 class FXExtentf {
00033 public:
00034   FXVec2f lower;
00035   FXVec2f upper;
00036 public:
00037 
00038   /// Default constructor
00039   FXExtentf(){}
00040 
00041   /// Copy constructor
00042   FXExtentf(const FXExtentf& ext):lower(ext.lower),upper(ext.upper){}
00043 
00044   /// Initialize from two vectors
00045   FXExtentf(const FXVec2f& lo,const FXVec2f& hi):lower(lo),upper(hi){}
00046 
00047   /// Initialize from six numbers
00048   FXExtentf(FXfloat xlo,FXfloat xhi,FXfloat ylo,FXfloat yhi):lower(xlo,ylo),upper(xhi,yhi){}
00049 
00050   /// Assignment
00051   FXExtentf& operator=(const FXExtentf& ext){ lower=ext.lower; upper=ext.upper; return *this; }
00052 
00053   /// Indexing with 0..1
00054   FXVec2f& operator[](FXint i){ return (&lower)[i]; }
00055 
00056   /// Indexing with 0..1
00057   const FXVec2f& operator[](FXint i) const { return (&lower)[i]; }
00058 
00059   /// Comparison
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 
00063   /// Width of box
00064   FXfloat width() const { return upper.x-lower.x; }
00065 
00066   /// Height of box
00067   FXfloat height() const { return upper.y-lower.y; }
00068 
00069   /// Longest side
00070   FXfloat longest() const;
00071 
00072   /// shortest side
00073   FXfloat shortest() const;
00074 
00075   /// Length of diagonal
00076   FXfloat diameter() const;
00077 
00078   /// Get radius of box
00079   FXfloat radius() const;
00080 
00081   /// Compute diagonal
00082   FXVec2f diagonal() const;
00083 
00084   /// Get center of box
00085   FXVec2f center() const;
00086 
00087   /// Test if empty
00088   bool empty() const;
00089 
00090   /// Test if box contains point x,y
00091   bool contains(FXfloat x,FXfloat y) const;
00092 
00093   /// Test if box contains point p
00094   bool contains(const FXVec2f& p) const;
00095 
00096   /// Test if box properly contains another box
00097   bool contains(const FXExtentf& ext) const;
00098 
00099   /// Include point
00100   FXExtentf& include(FXfloat x,FXfloat y);
00101 
00102   /// Include point
00103   FXExtentf& include(const FXVec2f& v);
00104 
00105   /// Include given range into extent
00106   FXExtentf& include(const FXExtentf& ext);
00107 
00108   /// Test if bounds overlap
00109   friend FXAPI bool overlap(const FXExtentf& a,const FXExtentf& b);
00110 
00111   /// Get corner number 0..3
00112   FXVec2f corner(FXint c) const { return FXVec2f((&lower)[c&1].x, (&lower)[(c>>1)&1].y); }
00113 
00114   /// Union of two boxes
00115   friend FXAPI FXExtentf unite(const FXExtentf& a,const FXExtentf& b);
00116 
00117   /// Intersection of two boxes
00118   friend FXAPI FXExtentf intersect(const FXExtentf& a,const FXExtentf& b);
00119 
00120   /// Save object to a stream
00121   friend FXAPI FXStream& operator<<(FXStream& store,const FXExtentf& ext);
00122 
00123   /// Load object from a stream
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 

Copyright © 1997-2005 Jeroen van der Zijp