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

aabb2.inl

Go to the documentation of this file.
00001 /*
00002     Sheep - A Rigid Body Dynamics Engine
00003     Copyright (C) 2001-2004 Francois Beaune
00004     Contact: http://toxicengine.sourceforge.net/
00005 
00006     This file is part of Sheep.
00007 
00008     Sheep is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     Sheep 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 General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with Sheep; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 */
00022 
00023 inline
00024 AABB2::AABB2() {
00025     Invalidate();
00026 }
00027 
00028 inline
00029 AABB2::AABB2(const AABB2 &aabb) :
00030     m_min(aabb.m_min),
00031     m_max(aabb.m_max) {}
00032 
00033 inline
00034 AABB2::AABB2(const Point2 &min, const Point2 &max) :
00035     m_min(min),
00036     m_max(max) {}
00037 
00038 inline
00039 AABB2 AABB2::Biggest() {
00040     return AABB2(
00041         Point2(-std::numeric_limits<Real>::max()),
00042         Point2(std::numeric_limits<Real>::max()));
00043 }
00044 
00045 inline
00046 void AABB2::Invalidate() {
00047     m_min = Point2(std::numeric_limits<Real>::max());
00048     m_max = Point2(-std::numeric_limits<Real>::max());
00049 }
00050 
00051 inline
00052 bool AABB2::IsValid() const {
00053     return
00054         m_min.m_x <= m_max.m_x &&
00055         m_min.m_y <= m_max.m_y;
00056 }
00057 
00058 inline
00059 void AABB2::Include(const Point2 &point) {
00060     if(point.m_x < m_min.m_x) m_min.m_x = point.m_x;
00061     if(point.m_x > m_max.m_x) m_max.m_x = point.m_x;
00062     if(point.m_y < m_min.m_y) m_min.m_y = point.m_y;
00063     if(point.m_y > m_max.m_y) m_max.m_y = point.m_y;
00064 }
00065 
00066 inline
00067 void AABB2::Include(const AABB2 &aabb) {
00068     if(aabb.m_min.m_x < m_min.m_x) m_min.m_x = aabb.m_min.m_x;
00069     if(aabb.m_min.m_y < m_min.m_y) m_min.m_y = aabb.m_min.m_y;
00070     if(aabb.m_max.m_x > m_max.m_x) m_max.m_x = aabb.m_max.m_x;
00071     if(aabb.m_max.m_y > m_max.m_y) m_max.m_y = aabb.m_max.m_y;
00072 }
00073 
00074 inline
00075 void AABB2::Intersect(const AABB2 &aabb) {
00076     if(aabb.m_min.m_x > m_min.m_x) m_min.m_x = aabb.m_min.m_x;
00077     if(aabb.m_min.m_y > m_min.m_y) m_min.m_y = aabb.m_min.m_y;
00078     if(aabb.m_max.m_x < m_max.m_x) m_max.m_x = aabb.m_max.m_x;
00079     if(aabb.m_max.m_y < m_max.m_y) m_max.m_y = aabb.m_max.m_y;
00080 }
00081 
00082 inline
00083 bool AABB2::Overlaps(const AABB2 &aabb) const {
00084     return !(
00085         aabb.m_max.m_x <= m_min.m_x ||
00086         aabb.m_min.m_x >= m_max.m_x ||
00087         aabb.m_max.m_y <= m_min.m_y ||
00088         aabb.m_min.m_y >= m_max.m_y);
00089 }
00090 
00091 inline
00092 bool AABB2::Contains(const Point2 &point) const {
00093     return
00094         point.m_x >= m_min.m_x &&
00095         point.m_x <= m_max.m_x &&
00096         point.m_y >= m_min.m_y &&
00097         point.m_y <= m_max.m_y;
00098 }
00099 
00100 inline
00101 Point2 AABB2::GetCenter() const {
00102     return 0.5 * (m_min + m_max);
00103 }
00104 
00105 inline
00106 Vector2 AABB2::GetSize() const {
00107     return m_max - m_min;
00108 }
00109 
00110 inline
00111 void AABB2::Scale(const Vector2 &scale) {
00112     const Point2 center = 0.5 * (m_min + m_max);
00113     const Vector2 delta = m_max - center;
00114 
00115     const Vector2 shift(
00116         scale.m_x * delta.m_x,
00117         scale.m_y * delta.m_y);
00118 
00119     m_min = center - shift;
00120     m_max = center + shift;
00121 }
00122 
00123 inline
00124 void AABB2::Extend(const Vector2 &ext) {
00125     m_min -= ext;
00126     m_max += ext;
00127 }

Generated on Tue May 11 01:31:49 2004 for toxic by doxygen 1.3.6