WFMath 0.3.12
|
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 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<int dim> 00043 inline Segment<dim>& Segment<dim>::moveCornerTo(const Point<dim>& p, int corner) 00044 { 00045 assert(corner == 0 || corner == 1); 00046 00047 Vector<dim> diff = m_p2 - m_p1; 00048 00049 if(!corner) { 00050 m_p1 = p; 00051 m_p2 = p + diff; 00052 } 00053 else { 00054 m_p2 = p; 00055 m_p1 = p - diff; 00056 } 00057 00058 return *this; 00059 } 00060 00061 template<int dim> 00062 inline Segment<dim>& Segment<dim>::rotateCorner(const RotMatrix<dim>& m, int corner) 00063 { 00064 assert(corner == 0 || corner == 1); 00065 00066 if(corner) 00067 m_p1.rotate(m, m_p2); 00068 else 00069 m_p2.rotate(m, m_p1); 00070 00071 return *this; 00072 } 00073 00074 template<> 00075 inline Segment<3>& Segment<3>::rotateCorner(const Quaternion& q, int corner) 00076 { 00077 assert(corner == 0 || corner == 1); 00078 00079 if(corner) 00080 m_p1.rotate(q, m_p2); 00081 else 00082 m_p2.rotate(q, m_p1); 00083 00084 return *this; 00085 } 00086 00087 } // namespace WFMath 00088 00089 #endif // WFMATH_SEGMENT_FUNCS_H