WFMath  0.3.12
segment_funcs.h
1 // segment_funcs.h (line segment implementation)
2 //
3 // The WorldForge Project
4 // Copyright (C) 2000, 2001 The WorldForge Project
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 //
20 // For information about WorldForge and its authors, please contact
21 // the Worldforge Web Site at http://www.worldforge.org.
22 //
23 
24 // Author: Ron Steinke
25 
26 #ifndef WFMATH_SEGMENT_FUNCS_H
27 #define WFMATH_SEGMENT_FUNCS_H
28 
29 #include <wfmath/segment.h>
30 
31 #include <cassert>
32 
33 namespace WFMath {
34 
35 template<int dim>
36 inline bool Segment<dim>::isEqualTo(const Segment<dim>& s, double epsilon) const
37 {
38  return Equal(m_p1, s.m_p1, epsilon)
39  && Equal(m_p2, s.m_p2, epsilon);
40 }
41 
42 template<int dim>
43 inline Segment<dim>& Segment<dim>::moveCornerTo(const Point<dim>& p, int corner)
44 {
45  assert(corner == 0 || corner == 1);
46 
47  Vector<dim> diff = m_p2 - m_p1;
48 
49  if(!corner) {
50  m_p1 = p;
51  m_p2 = p + diff;
52  }
53  else {
54  m_p2 = p;
55  m_p1 = p - diff;
56  }
57 
58  return *this;
59 }
60 
61 template<int dim>
62 inline Segment<dim>& Segment<dim>::rotateCorner(const RotMatrix<dim>& m, int corner)
63 {
64  assert(corner == 0 || corner == 1);
65 
66  if(corner)
67  m_p1.rotate(m, m_p2);
68  else
69  m_p2.rotate(m, m_p1);
70 
71  return *this;
72 }
73 
74 template<>
75 inline Segment<3>& Segment<3>::rotateCorner(const Quaternion& q, int corner)
76 {
77  assert(corner == 0 || corner == 1);
78 
79  if(corner)
80  m_p1.rotate(q, m_p2);
81  else
82  m_p2.rotate(q, m_p1);
83 
84  return *this;
85 }
86 
87 } // namespace WFMath
88 
89 #endif // WFMATH_SEGMENT_FUNCS_H
bool Equal(const C &c1, const C &c2, double epsilon=WFMATH_EPSILON)
Test for equality up to precision epsilon.
Definition: const.h:103