Claw
1.7.3
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
impl
coordinate_2d.tpp
Go to the documentation of this file.
1
/*
2
CLAW - a C++ Library Absolutely Wonderful
3
4
CLAW is a free library without any particular aim but being useful to
5
anyone.
6
7
Copyright (C) 2005-2011 Julien Jorge
8
9
This library is free software; you can redistribute it and/or
10
modify it under the terms of the GNU Lesser General Public
11
License as published by the Free Software Foundation; either
12
version 2.1 of the License, or (at your option) any later version.
13
14
This library is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
Lesser General Public License for more details.
18
19
You should have received a copy of the GNU Lesser General Public
20
License along with this library; if not, write to the Free Software
21
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
23
contact: julien.jorge@gamned.org
24
*/
30
#include <cmath>
31
32
/*----------------------------------------------------------------------------*/
36
template
<
typename
T>
37
claw::math::coordinate_2d<T>::coordinate_2d
()
38
{
39
40
}
// coordinate_2d::coordinate_2d() [constructor]
41
42
/*----------------------------------------------------------------------------*/
46
template
<
typename
T>
47
template
<
typename
U>
48
claw::math::coordinate_2d<T>::coordinate_2d
(
const
coordinate_2d<U>
& that)
49
: x(that.x), y(that.y)
50
{
51
52
}
// coordinate_2d::coordinate_2d() [copy constructor]
53
54
/*----------------------------------------------------------------------------*/
60
template
<
typename
T>
61
claw::math::coordinate_2d<T>::coordinate_2d
62
(
const
value_type
& _x,
const
value_type
& _y)
63
: x(_x), y(_y)
64
{
65
66
}
// coordinate_2d::coordinate_2d() [constructor whit values]
67
68
/*----------------------------------------------------------------------------*/
89
template
<
class
T>
90
template
<
typename
U>
91
claw::math::coordinate_2d<U>
92
claw::math::coordinate_2d<T>::cast_value_type_to
()
const
93
{
94
return
claw::math::coordinate_2d<U>
( (U)x, (U)y );
95
}
// coordinate_2d::cast_value_type_to()
96
97
/*----------------------------------------------------------------------------*/
103
template
<
typename
T>
104
void
105
claw::math::coordinate_2d<T>::set
(
const
value_type
& _x,
const
value_type
& _y)
106
{
107
x = _x;
108
y = _y;
109
}
// coordinate_2d::set()
110
111
/*----------------------------------------------------------------------------*/
116
template
<
typename
T>
117
typename
claw::math::coordinate_2d<T>::value_type
118
claw::math::coordinate_2d<T>::distance
(
const
self_type
& p)
const
119
{
120
return
(
value_type
)sqrt( (p.
x
- x)*(p.
x
- x) + (p.
y
- y)*(p.
y
- y) );
121
}
// coordinate_2d::distance()
122
123
/*----------------------------------------------------------------------------*/
129
template
<
typename
T>
130
void
131
claw::math::coordinate_2d<T>::rotate
(
const
self_type
& center,
double
angle )
132
{
133
self_type
result(center);
134
135
result.
x
+=
136
(x - center.
x
) * std::cos(angle) - (y - center.
y
) * std::sin(angle);
137
result.
y
+=
138
(x - center.
x
) * std::sin(angle) + (y - center.
y
) * std::cos(angle);
139
140
*
this
= result;
141
}
// coordinate_2d::rotate()
142
143
/*----------------------------------------------------------------------------*/
149
template
<
typename
T>
150
double
claw::math::coordinate_2d<T>::slope_angle
(
const
self_type
& to )
const
151
{
152
return
std::atan2( to.
y
- y, to.
x
- x );
153
}
// coordinate_2d::slope_angle()
154
155
/*----------------------------------------------------------------------------*/
160
template
<
typename
T>
161
bool
claw::math::coordinate_2d<T>::operator==
(
const
self_type
& that)
const
162
{
163
return
(x == that.
x
) && (y == that.
y
);
164
}
// coordinate_2d::operator==()
165
166
/*----------------------------------------------------------------------------*/
171
template
<
typename
T>
172
bool
claw::math::coordinate_2d<T>::operator!=
(
const
self_type
& that)
const
173
{
174
return
!(*
this
== that);
175
}
// coordinate_2d::operator!=()
176
177
/*----------------------------------------------------------------------------*/
182
template
<
typename
T>
183
claw::math::coordinate_2d<T>
184
claw::math::coordinate_2d<T>::operator+
(
const
self_type
& that)
const
185
{
186
return
self_type
( x + that.
x
, y + that.
y
);
187
}
// coordinate_2d::operator+()
188
189
/*----------------------------------------------------------------------------*/
194
template
<
typename
T>
195
claw::math::coordinate_2d<T>
196
claw::math::coordinate_2d<T>::operator-
(
const
self_type
& that)
const
197
{
198
return
self_type
( x - that.
x
, y - that.
y
);
199
}
// coordinate_2d::operator-()
200
201
/*----------------------------------------------------------------------------*/
206
template
<
typename
T>
207
claw::math::coordinate_2d<T>
&
208
claw::math::coordinate_2d<T>::operator+=
(
const
self_type
& that)
209
{
210
x += that.
x
;
211
y += that.
y
;
212
213
return
*
this
;
214
}
// coordinate_2d::operator+=()
215
216
/*----------------------------------------------------------------------------*/
221
template
<
typename
T>
222
claw::math::coordinate_2d<T>
&
223
claw::math::coordinate_2d<T>::operator-=
(
const
self_type
& that)
224
{
225
x -= that.
x
;
226
y -= that.
y
;
227
228
return
*
this
;
229
}
// coordinate_2d::operator-=()
230
231
/*----------------------------------------------------------------------------*/
236
template
<
typename
T>
237
claw::math::coordinate_2d<T>
238
claw::math::coordinate_2d<T>::operator*
(
const
value_type
& v)
const
239
{
240
return
self_type
( x * v, y * v );
241
}
// coordinate_2d::operator*()
242
243
/*----------------------------------------------------------------------------*/
248
template
<
typename
T>
249
claw::math::coordinate_2d<T>
250
claw::math::coordinate_2d<T>::operator/
(
const
value_type
& v)
const
251
{
252
return
self_type
( x / v, y / v );
253
}
// coordinate_2d::operator/()
254
255
/*----------------------------------------------------------------------------*/
260
template
<
typename
T>
261
claw::math::coordinate_2d<T>
&
262
claw::math::coordinate_2d<T>::operator*=
(
const
value_type
& v)
263
{
264
x *= v;
265
y *= v;
266
267
return
*
this
;
268
}
// coordinate_2d::operator*=()
269
270
/*----------------------------------------------------------------------------*/
275
template
<
typename
T>
276
claw::math::coordinate_2d<T>
&
277
claw::math::coordinate_2d<T>::operator/=
(
const
value_type
& v)
278
{
279
x /= v;
280
y /= v;
281
282
return
*
this
;
283
}
// coordinate_2d::operator/=()
284
285
/*----------------------------------------------------------------------------*/
290
template
<
typename
T>
291
claw::math::coordinate_2d<T>
292
claw::math::operator-
(
const
claw::math::coordinate_2d<T>
& that )
293
{
294
return
claw::math::coordinate_2d<T>
(-that.
x
, -that.
y
);
295
}
// operator-() [coordinate_2d]
296
297
/*----------------------------------------------------------------------------*/
303
template
<
typename
T,
typename
U>
304
claw::math::coordinate_2d<T>
305
claw::math::operator*
( U v,
const
coordinate_2d<T>
&
self
)
306
{
307
return
self
*
typename
coordinate_2d<T>::value_type
(v);
308
}
// operator*() [coordinate_2d]
Generated on Thu Mar 14 2013 22:09:24 for Claw by
1.8.1.2