CLAM-Development
1.4.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
src
Standard
PointTmplDec.hxx
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3
* UNIVERSITAT POMPEU FABRA
4
*
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
*
20
*/
21
22
23
#ifndef _PointTmplDec_
24
#define _PointTmplDec_
25
26
#include <iosfwd>
27
#include "
CLAM_Math.hxx
"
28
29
namespace
CLAM
30
{
31
32
template
<
typename
TX = TData,
typename
TY = TX>
class
PointTmpl
33
{
34
public
:
35
/*Constructors*/
36
PointTmpl
() :
mX
(0),
mY
(0)
37
{};
38
39
PointTmpl
(TX xValue,TY yValue)
40
{
41
mX
=xValue;
42
mY
=yValue;
43
}
44
45
/*Getting Values*/
46
const
TX&
GetX
()
const
{
return
mX
;}
47
const
TY&
GetY
()
const
{
return
mY
;}
48
49
/*Setting Values*/
50
void
SetX
(TX xValue){
mX
=xValue;}
51
void
SetY
(TY yValue){
mY
=yValue;}
52
53
/*Member operators*/
54
const
PointTmpl<TX,TY>
&
operator=
(
const
PointTmpl<TX,TY>
& newPoint)
55
{
56
mX
=newPoint.
mX
;
57
mY
=newPoint.
mY
;
58
return
*
this
;
59
}
60
const
PointTmpl<TX,TY>
&
operator+=
(
const
PointTmpl<TX,TY>
& newPoint)
61
{
62
mX
+=newPoint.
mX
;
63
mY
+=newPoint.
mY
;
64
return
*
this
;
65
}
66
const
PointTmpl<TX,TY>
&
operator-=
(
const
PointTmpl<TX,TY>
& newPoint)
67
{
68
mX
-=newPoint.
mX
;
69
mY
-=newPoint.
mY
;
70
return
*
this
;
71
}
72
bool
operator<(const PointTmpl<TX,TY>& newPoint)
const
{
return
mX
<newPoint.GetX();}
73
bool
operator<=(const PointTmpl<TX,TY>& newPoint)
const
{
return
mX
<=newPoint.GetX();}
74
bool
operator>
(
const
PointTmpl<TX,TY>
& newPoint)
const
{
return
mX
>newPoint.
GetX
();}
75
bool
operator>=
(
const
PointTmpl<TX,TY>
& newPoint)
const
{
return
mX
>=newPoint.
GetX
();}
76
bool
operator!=
(
const
PointTmpl<TX,TY>
& newPoint)
const
{
return
(
mX
!=newPoint.
GetX
());}
77
bool
operator==
(
const
PointTmpl<TX,TY>
& newPoint)
const
{
return
(
mX
==newPoint.
GetX
());}
78
79
/*member funtion, euclidian distance*/
80
double
Distance
(
const
PointTmpl<TX,TY>
& newPoint)
const
81
{
82
return
CLAM_pow
((
TData
)
CLAM_pow
((
TData
)(
mX
-newPoint.
mX
),(
TData
)2)+
CLAM_pow
((
TData
)(
mY
-newPoint.
mY
),(
TData
)2),(
TData
)0.5);
83
}
84
85
/*non-member operators*/
86
PointTmpl<TX,TY>
operator-
(
const
PointTmpl<TX,TY>
& otherPoint)
87
{
88
PointTmpl<TX,TY>
result(
mX
-otherPoint.
mX
,
mY
-otherPoint.
mY
);
89
return
result;
90
}
91
PointTmpl<TX,TY>
operator+
(
const
PointTmpl<TX,TY>
& otherPoint)
92
{
93
PointTmpl<TX,TY>
result(
mX
+otherPoint.
mX
,
mY
+otherPoint.
mY
);
94
return
result;
95
}
96
97
protected
:
98
99
/*member variables, x and y values*/
100
TX
mX
;
101
TY
mY
;
102
};
103
104
template
<
class
TX,
class
TY>
105
std::istream&
operator >>
(std::istream & stream,
PointTmpl<TX,TY>
& a);
106
107
template
<
class
TX,
class
TY>
108
std::ostream& operator << (std::ostream & stream, const PointTmpl<TX,TY> & a);
109
110
}
// namespace CLAM
111
112
#endif // _PointTmplDec_
113
Generated by
1.8.1