Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F81404184
vector.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
Thu, Sep 5, 21:03
Size
1 KB
Mime Type
text/x-c++
Expires
Sat, Sep 7, 21:03 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
20506696
Attached To
R7571 SP4E-TB-TL-FR
vector.hh
View Options
#ifndef __VECTOR__HH__
#define __VECTOR__HH__
/* -------------------------------------------------------------------------- */
#include "my_types.hh"
/* -------------------------------------------------------------------------- */
#include <array>
/**
* @brief 3D Vector class
*
* Note that no constructor is needed for this class
*/
class Vector {
public:
//! Dimension of vector
static const UInt dim = 3;
// Methods
public:
//! access given component
Real& operator[](UInt i);
//! access given component (const)
const Real& operator[](UInt i) const;
//! square of euclidian norm
Real squaredNorm() const;
// Operators that make sense for vectors
Vector& operator+=(const Vector& vec);
Vector& operator-=(const Vector& vec);
Vector& operator*=(Real val);
Vector& operator/=(Real val);
//! Copy operator
Vector& operator=(const Vector& vec);
//! Assign a value
Vector& operator=(Real val);
public:
//! Output to stream
friend std::ostream& operator<<(std::ostream& stream, const Vector& _this);
//! Initialize from stream
friend std::istream& operator>>(std::istream& stream, Vector& _this);
private:
//! Vector values (initilized to zero by default)
std::array<Real, dim> values = {0};
};
/* -------------------------------------------------------------------------- */
/* Separate function definitions */
/* -------------------------------------------------------------------------- */
/// standard output stream operator
std::ostream& operator<<(std::ostream& stream, const Vector& _this);
/// standard input stream operator
std::istream& operator>>(std::istream& stream, Vector& _this);
// We define the operators +, -, *, / with vectors and scalars
Vector operator+(const Vector & a, const Vector& b);
Vector operator-(const Vector & a, const Vector& b);
// Symmetry of multiplication
Vector operator*(const Vector & a, Real val);
Vector operator*(Real val, const Vector & a);
// For convenience
Vector operator/(const Vector & a, Real val);
#endif //__VECTOR__HH__
Event Timeline
Log In to Comment