Main Page
Namespaces
Classes
Files
File List
File Members
vec2.hpp
Go to the documentation of this file.
1
/*
2
** TP CPE Lyon
3
** Copyright (C) 2013 Damien Rohmer
4
**
5
** This program is free software: you can redistribute it and/or modify
6
** it under the terms of the GNU General Public License as published by
7
** the Free Software Foundation, either version 3 of the License, or
8
** (at your option) any later version.
9
**
10
** This program is distributed in the hope that it will be useful,
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
** GNU General Public License for more details.
14
**
15
** You should have received a copy of the GNU General Public License
16
** along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
20
21
#ifndef VEC2_HPP
22
#define VEC2_HPP
23
24
#include <string>
25
#include <iostream>
26
27
#include <
exception_cpe.hpp
>
28
29
namespace
cpe
30
{
31
33
class
vec2
34
{
35
public
:
36
37
// ********************************************* //
38
// ********************************************* //
39
// CONSTRUCTORS
40
// ********************************************* //
41
// ********************************************* //
42
44
vec2
();
46
vec2
(
float
x
,
float
y
);
47
48
// ********************************************* //
49
// ********************************************* //
50
// Get/set
51
// ********************************************* //
52
// ********************************************* //
53
55
float
x
()
const
;
57
float
&
x
();
59
float
y
()
const
;
61
float
&
y
();
62
63
65
float
operator[]
(
const
size_t
& k)
const
;
67
float
&
operator[]
(
const
size_t
& k);
69
float
operator()
(
const
size_t
& k)
const
;
71
float
&
operator()
(
const
size_t
& k);
72
74
void
set_zero
();
75
76
79
const
float
*
pointer
()
const
;
80
81
// ********************************************* //
82
// ********************************************* //
83
// Math operation
84
// ********************************************* //
85
// ********************************************* //
86
88
float
dot
(
const
vec2
& p)
const
;
89
91
float
norm
()
const
;
93
float
norm2
()
const
;
95
vec2
normalized
()
const
;
96
97
98
99
100
// ********************************************* //
101
// ********************************************* //
102
// Operator +-*/
103
// ********************************************* //
104
// ********************************************* //
105
107
vec2
operator+
(
const
vec2
& p2)
const
;
109
vec2
operator+
(
float
s)
const
;
110
112
vec2
operator-
(
const
vec2
& p2)
const
;
114
vec2
operator-
(
float
s)
const
;
115
116
118
vec2
operator*
(
float
s)
const
;
120
vec2
operator/
(
float
s)
const
;
121
123
vec2
&
operator+=
(
const
vec2
& p);
125
vec2
&
operator+=
(
float
s);
127
vec2
&
operator-=
(
const
vec2
& p);
129
vec2
&
operator-=
(
float
s);
131
vec2
&
operator*=
(
float
s);
133
vec2
&
operator/=
(
float
s);
134
136
vec2
operator-
()
const
;
137
141
vec2
product_compontentwise
(
const
vec2
& p)
const
;
146
vec2
&
product_compontentwise_internal
(
const
vec2
& p);
148
void
scale
(
float
sx,
float
sy);
149
150
151
// ********************************************* //
152
// ********************************************* //
153
// Output
154
// ********************************************* //
155
// ********************************************* //
156
158
std::string
to_string
()
const
;
159
160
161
162
private
:
163
164
165
// ********************************************* //
166
// ********************************************* //
167
// Internal parameters
168
// ********************************************* //
169
// ********************************************* //
170
172
float
internal_x
;
174
float
internal_y
;
175
176
177
// ********************************************* //
178
// ********************************************* //
179
// Helper
180
// ********************************************* //
181
// ********************************************* //
182
184
void
assert_size
(
const
size_t
& k)
const
;
185
186
};
187
189
vec2
operator+
(
float
s,
const
vec2
& p);
191
vec2
operator-
(
float
s,
const
vec2
& p);
193
vec2
operator*
(
float
s,
const
vec2
& p);
194
195
// ********************************************* //
196
// ********************************************* //
197
// Output
198
// ********************************************* //
199
// ********************************************* //
200
202
std::ostream&
operator<<
(std::ostream& stream,
const
vec2
& p);
203
204
206
class
exception_vec2
:
public
exception_cpe
207
{
208
public
:
209
211
exception_vec2
():
exception_cpe
(){}
213
exception_vec2
(
const
std::string& msg_param,
const
std::string& file_param,
const
std::string& caller_param,
const
int
& line_param):
exception_cpe
(msg_param,file_param,caller_param,line_param){}
214
};
215
216
}
217
218
219
220
#endif
lib3d
vec2.hpp
Generated on Fri Mar 29 2013 22:45:31 by
1.8.3.1