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>
moveCornerTo(const Point<dim> & p,size_t corner)36 inline Segment<dim>& Segment<dim>::moveCornerTo(const Point<dim>& p, size_t corner)
37 {
38 assert(corner == 0 || corner == 1);
39
40 Vector<dim> diff = m_p2 - m_p1;
41
42 if(!corner) {
43 m_p1 = p;
44 m_p2 = p + diff;
45 }
46 else {
47 m_p2 = p;
48 m_p1 = p - diff;
49 }
50
51 return *this;
52 }
53
54 template<int dim>
rotateCorner(const RotMatrix<dim> & m,size_t corner)55 inline Segment<dim>& Segment<dim>::rotateCorner(const RotMatrix<dim>& m, size_t corner)
56 {
57 assert(corner == 0 || corner == 1);
58
59 if(corner)
60 m_p1.rotate(m, m_p2);
61 else
62 m_p2.rotate(m, m_p1);
63
64 return *this;
65 }
66
67 template<>
rotateCorner(const Quaternion & q,size_t corner)68 inline Segment<3>& Segment<3>::rotateCorner(const Quaternion& q, size_t corner)
69 {
70 assert(corner == 0 || corner == 1);
71
72 if(corner)
73 m_p1.rotate(q, m_p2);
74 else
75 m_p2.rotate(q, m_p1);
76
77 return *this;
78 }
79
80 } // namespace WFMath
81
82 #endif // WFMATH_SEGMENT_FUNCS_H
83