Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91925319
vector_inline.hh
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Nov 15, 19:01
Size
2 KB
Mime Type
text/x-c
Expires
Sun, Nov 17, 19:01 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22348423
Attached To
R9490 Homework_sp4e_Peruzzo_SáezUribe
vector_inline.hh
View Options
#include "vector.hh"
inline
Real
&
Vector
::
operator
[](
UInt
i
)
{
return
values
[
i
];
}
inline
const
Real
&
Vector
::
operator
[](
UInt
i
)
const
{
return
values
[
i
];
}
inline
Real
Vector
::
squaredNorm
()
const
{
Real
res
=
0
;
for
(
auto
&
val
:
values
)
{
res
+=
val
*
val
;
}
return
res
;
}
/* -------------------------------------------------------------------------- */
inline
Vector
&
Vector
::
operator
+=
(
const
Vector
&
vec
)
{
for
(
UInt
i
=
0
;
i
<
dim
;
++
i
)
values
[
i
]
+=
vec
[
i
];
return
*
this
;
}
inline
Vector
&
Vector
::
operator
-=
(
const
Vector
&
vec
)
{
for
(
UInt
i
=
0
;
i
<
dim
;
++
i
)
values
[
i
]
-=
vec
[
i
];
return
*
this
;
}
inline
Vector
&
Vector
::
operator
*=
(
Real
val
)
{
for
(
auto
&
v
:
values
)
v
*=
val
;
return
*
this
;
}
inline
Vector
&
Vector
::
operator
/=
(
Real
val
)
{
for
(
auto
&
v
:
values
)
v
/=
val
;
return
*
this
;
}
/* -------------------------------------------------------------------------- */
inline
Vector
&
Vector
::
operator
=
(
const
Vector
&
vec
)
{
std
::
copy
(
vec
.
values
.
begin
(),
vec
.
values
.
end
(),
values
.
begin
());
return
*
this
;
}
inline
Vector
&
Vector
::
operator
=
(
Real
val
)
{
std
::
fill
(
values
.
begin
(),
values
.
end
(),
val
);
return
*
this
;
}
/* -------------------------------------------------------------------------- */
inline
Vector
operator
+
(
const
Vector
&
a
,
const
Vector
&
b
)
{
Vector
res
(
a
);
res
+=
b
;
return
res
;
}
inline
Vector
operator
-
(
const
Vector
&
a
,
const
Vector
&
b
)
{
Vector
res
(
a
);
res
-=
b
;
return
res
;
}
inline
Vector
operator
*
(
const
Vector
&
a
,
Real
val
)
{
Vector
res
(
a
);
res
*=
val
;
return
res
;
}
inline
Vector
operator
*
(
Real
val
,
const
Vector
&
a
)
{
return
a
*
val
;
}
inline
Vector
operator
/
(
const
Vector
&
a
,
Real
val
)
{
Vector
res
(
a
);
res
/=
val
;
return
res
;
}
/* -------------------------------------------------------------------------- */
/// standard output stream operator
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
stream
,
const
Vector
&
_this
)
{
for
(
auto
&
v
:
_this
.
values
)
stream
<<
v
<<
" "
;
return
stream
;
}
/* -------------------------------------------------------------------------- */
/// standard input stream operator
inline
std
::
istream
&
operator
>>
(
std
::
istream
&
stream
,
Vector
&
_this
)
{
for
(
auto
&
v
:
_this
.
values
)
stream
>>
v
;
return
stream
;
}
Event Timeline
Log In to Comment