DGtal  1.5.beta
StraightLineFrom2Points.ih
1 /**
2  * This program is free software: you can redistribute it and/or modify
3  * it under the terms of the GNU Lesser General Public License as
4  * published by the Free Software Foundation, either version 3 of the
5  * License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program. If not, see <http://www.gnu.org/licenses/>.
14  *
15  **/
16 
17 /**
18  * @file StraightLineFrom2Points.ih
19  * @author Tristan Roussillon (\c tristan.roussillon@liris.cnrs.fr )
20  * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
21  *
22  * @date 2010/10/27
23  *
24  * Implementation of inline methods defined in StraightLineFrom2Points.h
25  *
26  * This file is part of the DGtal library.
27  */
28 
29 
30 //////////////////////////////////////////////////////////////////////////////
31 #include <cstdlib>
32 //////////////////////////////////////////////////////////////////////////////
33 
34 ///////////////////////////////////////////////////////////////////////////////
35 // IMPLEMENTATION of inline methods.
36 ///////////////////////////////////////////////////////////////////////////////
37 
38 ///////////////////////////////////////////////////////////////////////////////
39 // ----------------------- Standard services ------------------------------
40 
41 template <typename TPoint>
42 inline
43 DGtal::StraightLineFrom2Points<TPoint>::~StraightLineFrom2Points()
44 {
45 }
46 
47 template <typename TPoint>
48 inline
49 DGtal::StraightLineFrom2Points<TPoint>::StraightLineFrom2Points()
50 {
51 }
52 
53 template <typename TPoint>
54 inline
55 void
56 DGtal::StraightLineFrom2Points<TPoint>::init(
57  const Point& aFirstPoint,
58  const Point& aSecondPoint)
59 {
60  myP = aFirstPoint;
61  myQ = aSecondPoint;
62 }
63 
64 
65 template <typename TPoint>
66 inline
67 DGtal::StraightLineFrom2Points<TPoint>::StraightLineFrom2Points(
68  const Point& aFirstPoint,
69  const Point& aSecondPoint):
70  myP(aFirstPoint),
71  myQ(aSecondPoint)
72 {
73 }
74 
75 
76 template <typename TPoint>
77 inline
78 DGtal::StraightLineFrom2Points<TPoint>::StraightLineFrom2Points(
79  const StraightLineFrom2Points & other):
80  myP(other.myP),
81  myQ(other.myQ)
82 {
83 }
84 
85 
86 template <typename TPoint>
87 inline
88 DGtal::StraightLineFrom2Points<TPoint>&
89 DGtal::StraightLineFrom2Points<TPoint>::operator=(
90  const StraightLineFrom2Points & other)
91 {
92  myP = other.myP;
93  myQ = other.myQ;
94  return *this;
95 }
96 
97 
98 
99 template <typename TPoint>
100 inline
101 typename DGtal::StraightLineFrom2Points<TPoint>::Distance
102 DGtal::StraightLineFrom2Points<TPoint>::signedDistance(const Point& aP) const
103 {
104  Vector pq = myQ - myP;
105  Vector pr = aP - myP;
106  //computation of det(pq, pr)
107  //(= twice the parallelogram area)
108  return ((pq[0] * pr[1]) - (pq[1] * pr[0]));
109 }
110 
111 
112 ///////////////////////////////////////////////////////////////////////////////
113 // Interface - public :
114 
115 template <typename TPoint>
116 inline
117 std::string
118 DGtal::StraightLineFrom2Points<TPoint>::className() const
119 {
120  return "StraightLineFrom2Points";
121 }
122 
123 template <typename TPoint>
124 inline
125 void
126 DGtal::StraightLineFrom2Points<TPoint>::selfDisplay ( std::ostream & out ) const
127 {
128  out << "[StraightLineFrom2Points] passing through:\n";
129  out << myP << myQ;
130 }
131 
132 template <typename TPoint>
133 inline
134 bool
135 DGtal::StraightLineFrom2Points<TPoint>::isValid() const
136 {
137  return true;
138 }
139 
140