WFMath  1.0.2
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/segment.h>
00030 
00031 #include <cassert>
00032 
00033 namespace WFMath {
00034 
00035 template<int dim>
00036 inline Segment<dim>& Segment<dim>::moveCornerTo(const Point<dim>& p, size_t corner)
00037 {
00038   assert(corner == 0 || corner == 1);
00039 
00040   Vector<dim> diff = m_p2 - m_p1;
00041 
00042   if(!corner) {
00043     m_p1 = p;
00044     m_p2 = p + diff;
00045   }
00046   else {
00047     m_p2 = p;
00048     m_p1 = p - diff;
00049   }
00050 
00051   return *this;
00052 }
00053 
00054 template<int dim>
00055 inline Segment<dim>& Segment<dim>::rotateCorner(const RotMatrix<dim>& m, size_t corner)
00056 {
00057   assert(corner == 0 || corner == 1);
00058 
00059   if(corner)
00060     m_p1.rotate(m, m_p2);
00061   else
00062     m_p2.rotate(m, m_p1);
00063 
00064   return *this;
00065 }
00066 
00067 template<>
00068 inline Segment<3>& Segment<3>::rotateCorner(const Quaternion& q, size_t corner)
00069 {
00070   assert(corner == 0 || corner == 1);
00071 
00072   if(corner)
00073     m_p1.rotate(q, m_p2);
00074   else
00075     m_p2.rotate(q, m_p1);
00076 
00077   return *this;
00078 }
00079 
00080 } // namespace WFMath
00081 
00082 #endif  // WFMATH_SEGMENT_FUNCS_H