Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   Related Pages  

BBox2C.h

00001 //-------------------------------------------------------------------------
00002 //
00003 // File:        BBox2C.h
00004 // Desc:        2D bounding box class.
00005 // Author:      memon <memon@inside.org>
00006 //
00007 //-------------------------------------------------------------------------
00008 //  Copyright (c) 2000-2002 Moppi Productions. All Rights Reserved.
00009 //  This file is part of Moppi Demopaja SDK. For conditions of 
00010 //  distribution and use, see the accompanying license.txt file.
00011 //  http://moppi.inside.org/demopaja/
00012 //-------------------------------------------------------------------------
00013 
00014 #ifndef __DEMOPAJA_BBOX2C_H__
00015 #define __DEMOPAJA_BBOX2C_H__
00016 
00017 #include <math.h>
00018 #include "PajaTypes.h"
00019 #include "Vector2C.h"
00020 
00021 namespace PajaTypes {
00022 
00023 
00025 
00037     class BBox2C
00038     {
00039     public:
00041         BBox2C();
00042         
00044         BBox2C( const Vector2C& rMin, const Vector2C& rMax );
00045         
00047         BBox2C( const BBox2C& rBBox );
00048         
00050         virtual ~BBox2C();
00051 
00053 
00057         float32             width() const;
00058 
00060 
00064         float32             height() const;
00065 
00067 
00070         Vector2C            center() const;
00071         
00073 
00078         Vector2C            size() const;
00079         
00081 
00085         bool                contains( const Vector2C& rVec ) const;
00086         
00088 
00092         bool                contains( const BBox2C& rBBox ) const;
00093         
00095 
00099         BBox2C              trim( const BBox2C& rBBox ) const;
00100         
00102 
00105         BBox2C              normalize() const;
00106         
00108 
00110         BBox2C              offset( const Vector2C& rOffset ) const;
00111         
00113 
00118         BBox2C              combine( const BBox2C& rBBox ) const;
00119 
00121 
00127         Vector2C&           operator[]( int i );
00128 
00130 
00136         const Vector2C&     operator[]( int i ) const;
00137 
00139 
00143         bool                operator==( const BBox2C& rBBox ) const;
00144 
00146 
00150         bool                operator!=( const BBox2C& rBBox ) const;
00151 
00152     private:
00153         Vector2C    m_rMin, m_rMax;
00154     };
00155 
00156 
00157     inline
00158     float32
00159     BBox2C::width() const
00160     {
00161         return (float32)fabs( m_rMax[0] - m_rMin[0] );
00162     }
00163     
00164     inline
00165     float32
00166     BBox2C::height() const
00167     {
00168         return (float32)fabs( m_rMax[1] - m_rMin[1] );
00169     }
00170     
00171     inline
00172     Vector2C
00173     BBox2C::center() const
00174     {
00175         return (m_rMin + m_rMax) * 0.5;
00176     }
00177 
00178     inline
00179     Vector2C
00180     BBox2C::size() const
00181     {
00182         return m_rMax - m_rMin;
00183     }
00184     
00185     inline
00186     bool
00187     BBox2C::contains( const Vector2C& rVec ) const
00188     {
00189         return (rVec[0] >= m_rMin[0] && rVec[0] <= m_rMax[0] && rVec[1] >= m_rMin[1] && rVec[1] <= m_rMax[1]);
00190     }
00191     
00192     inline
00193     bool
00194     BBox2C::contains( const BBox2C& rBBox ) const
00195     {
00196         return (contains( rBBox.m_rMin ) && contains( rBBox.m_rMax ));
00197     }
00198 
00199     inline
00200     Vector2C&
00201     BBox2C::operator[]( int i )
00202     {
00203         return (i == 0) ? m_rMin : m_rMax;
00204     }
00205     
00206     inline
00207     const Vector2C&
00208     BBox2C::operator[]( int i ) const
00209     {
00210         return (i == 0) ? m_rMin : m_rMax;
00211     }
00212     
00213     inline
00214     bool
00215     BBox2C::operator==( const BBox2C& rBBox ) const
00216     {
00217         return (m_rMin == rBBox.m_rMin && m_rMax == rBBox.m_rMax);
00218     }
00219     
00220     inline
00221     bool
00222     BBox2C::operator!=( const BBox2C& rBBox ) const
00223     {
00224         return (m_rMin != rBBox.m_rMin || m_rMax != rBBox.m_rMax);
00225     }
00226 
00227     inline
00228     BBox2C
00229     BBox2C::offset( const Vector2C& rOffset ) const
00230     {
00231         BBox2C  rRes( *this );
00232 
00233         rRes.m_rMin += rOffset;
00234         rRes.m_rMax += rOffset;
00235 
00236         return rRes;
00237     }
00238 
00239 
00240 
00241 };  // PajaTypes
00242 
00243 #endif // __DEMOPAJA_BBOX2C_H__

Moppi Demopaja SDK Documentation -- Copyright © 2000-2002 Moppi Productions