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

rotbox_funcs.h

00001 // rotbox_funcs.h (line rotbox implementation)
00002 //
00003 //  The WorldForge Project
00004 //  Copyright (C) 2000, 2001  The WorldForge Project
00005 //
00006 //  This program is free software; you can redistribute it and/or modify
00007 //  it under the terms of the GNU General Public License as published by
00008 //  the Free Software Foundation; either version 2 of the License, or
00009 //  (at your option) any later version.
00010 //
00011 //  This program is distributed in the hope that it will be useful,
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //  GNU General Public License for more details.
00015 //
00016 //  You should have received a copy of the GNU General Public License
00017 //  along with this program; if not, write to the Free Software
00018 //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 //
00020 //  For information about WorldForge and its authors, please contact
00021 //  the Worldforge Web Site at http://www.worldforge.org.
00022 //
00023 
00024 // Author: Ron Steinke
00025 
00026 #ifndef WFMATH_ROT_BOX_FUNCS_H
00027 #define WFMATH_ROT_BOX_FUNCS_H
00028 
00029 #include <wfmath/const.h>
00030 #include <wfmath/vector.h>
00031 #include <wfmath/point.h>
00032 #include <wfmath/axisbox.h>
00033 #include <wfmath/ball.h>
00034 #include <wfmath/rotbox.h>
00035 
00036 namespace WFMath {
00037 
00038 template<const int dim>
00039 RotBox<dim>& RotBox<dim>::operator=(const RotBox<dim>& a)
00040 {
00041   m_corner0 = a.m_corner0;
00042   m_size = a.m_size;
00043   m_orient = a.m_orient;
00044 
00045   return *this;
00046 }
00047 
00048 template<const int dim>
00049 bool RotBox<dim>::isEqualTo(const RotBox<dim>& b, double epsilon) const
00050 {
00051   return Equal(m_corner0, b.m_corner0, epsilon)
00052       && Equal(m_size, b.m_size, epsilon)
00053       && Equal(m_orient, b.m_orient, epsilon);
00054 }
00055 
00056 // WARNING! This operator is for sorting only. It does not
00057 // reflect any property of the box.
00058 template<const int dim>
00059 bool RotBox<dim>::operator< (const RotBox<dim>& a) const
00060 {
00061   if(!Equal(m_corner0, a.m_corner0))
00062     return m_corner0 < a.m_corner0;
00063   if(!Equal(m_size, a.m_size))
00064     return m_size < a.m_size;
00065   return m_orient < a.m_orient;
00066 }
00067 
00068 template<const int dim>
00069 Point<dim> RotBox<dim>::getCorner(int i) const
00070 {
00071   assert(i >= 0 && i < (1 << dim));
00072 
00073   Vector<dim> dist;
00074 
00075   if(i == 0)
00076     return m_corner0;
00077 
00078   for(int j = 0; j < dim; ++j)
00079     dist[j] = (i & (1 << j)) ? m_size[j] : 0;
00080 
00081   dist.setValid(m_size.isValid());
00082 
00083   return m_corner0 + Prod(dist, m_orient);
00084 }
00085 
00086 template<const int dim>
00087 AxisBox<dim> RotBox<dim>::boundingBox() const
00088 {
00089   Point<dim> min = m_corner0, max = m_corner0;
00090 
00091 //  for(int i = 0; i < dim; ++i) {
00092 //    Vector<dim> edge;
00093 //    edge.zero();
00094 //    edge[i] = m_size[i];
00095 //    edge = Prod(edge, m_orient);
00096 //    // Edge now represents the i'th edge
00097 //    // pointing away from m_corner0
00098 //    for(int j = 0; j < dim; ++j) {
00099 //      if(edge[j] < 0)
00100 //        min[j] += edge[j];
00101 //      else
00102 //        max[j] += edge[j];
00103 //    }
00104 //  }
00105 
00106 // The following is equivalent to the above. The above is easier to understand,
00107 // so leave it in as a comment.
00108 
00109   for(int i = 0; i < dim; ++i) {
00110     for(int j = 0; j < dim; ++j) {
00111       CoordType value = m_orient.elem(j, i) * m_size[j];
00112       if(value < 0)
00113         min[i] += value;
00114       else
00115         max[i] += value;
00116     }
00117   }
00118 
00119   bool valid = isValid();
00120 
00121   min.setValid(valid);
00122   max.setValid(valid);
00123 
00124   return AxisBox<dim>(min, max, true);
00125 }
00126 
00127 } // namespace WFMath
00128 
00129 #endif  // WFMATH_ROT_BOX_FUNCS_H

Generated on Wed May 28 09:20:32 2003 for WFMath by doxygen1.3-rc3