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

segment_funcs.h

00001 // segment_funcs.h (line segment 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_SEGMENT_FUNCS_H
00027 #define WFMATH_SEGMENT_FUNCS_H
00028 
00029 #include <wfmath/const.h>
00030 #include <wfmath/point.h>
00031 #include <wfmath/segment.h>
00032 
00033 namespace WFMath {
00034 
00035 template<const int dim>
00036 bool Segment<dim>::isEqualTo(const Segment<dim>& s, double epsilon) const
00037 {
00038   return Equal(m_p1, s.m_p1, epsilon)
00039       && Equal(m_p2, s.m_p2, epsilon);
00040 }
00041 
00042 template<const int dim>
00043 bool Segment<dim>::operator< (const Segment& s) const
00044 {
00045   if(!Equal(m_p1, s.m_p1))
00046     return m_p1 < s.m_p1;
00047   else
00048     return m_p2 < s.m_p2;
00049 }
00050 
00051 template<const int dim>
00052 Segment<dim>& Segment<dim>::moveCornerTo(const Point<dim>& p, int corner)
00053 {
00054   assert(corner == 0 || corner == 1);
00055 
00056   Vector<dim> diff = m_p2 - m_p1;
00057 
00058   if(!corner) {
00059     m_p1 = p;
00060     m_p2 = p + diff;
00061   }
00062   else {
00063     m_p2 = p;
00064     m_p1 = p - diff;
00065   }
00066 
00067   return *this;
00068 }
00069 
00070 template<const int dim>
00071 Segment<dim>& Segment<dim>::rotateCorner(const RotMatrix<dim>& m, int corner)
00072 {
00073   assert(corner == 0 || corner == 1);
00074 
00075   if(corner)
00076     m_p1.rotate(m, m_p2);
00077   else
00078     m_p2.rotate(m, m_p1);
00079 
00080   return *this;
00081 }
00082 
00083 } // namespace WFMath
00084 
00085 #endif  // WFMATH_SEGMENT_FUNCS_H

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