Fill in missing Vector4 symbols
Add assignment and call operators, bool operators, etc
This commit is contained in:
parent
49d097a803
commit
620d5a5bc6
2 changed files with 87 additions and 0 deletions
|
@ -5,13 +5,19 @@
|
|||
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "basics/vector.hh"
|
||||
|
||||
#include "basics/util.hh"
|
||||
|
||||
|
||||
namespace charles {
|
||||
namespace basics {
|
||||
|
||||
#pragma mark Constructors and Assignment
|
||||
|
||||
/*
|
||||
* charles::basics::Vector4::Vector4 --
|
||||
*/
|
||||
|
@ -34,6 +40,17 @@ Vector4::Vector4(Double x,
|
|||
mData[3] = 1.0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::Vector4::operator= --
|
||||
*/
|
||||
Vector4&
|
||||
Vector4::operator=(const Vector4 &rhs)
|
||||
{
|
||||
memcpy(mData, rhs.mData, sizeof(Double) * 4);
|
||||
return *this;
|
||||
}
|
||||
|
||||
#pragma mark Component Access
|
||||
|
||||
/*
|
||||
|
@ -98,6 +115,70 @@ Vector4::Z()
|
|||
return mData[2];
|
||||
}
|
||||
|
||||
|
||||
Double&
|
||||
Vector4::operator()(UInt i)
|
||||
{
|
||||
if (i >= 4) {
|
||||
std::stringstream ss;
|
||||
ss << "vector index out of bounds: i = " << i;
|
||||
throw std::out_of_range(ss.str());
|
||||
}
|
||||
return mData[i];
|
||||
}
|
||||
|
||||
|
||||
Double
|
||||
Vector4::operator()(UInt i)
|
||||
const
|
||||
{
|
||||
if (i >= 4) {
|
||||
std::stringstream ss;
|
||||
ss << "vector index out of bounds: i = " << i;
|
||||
throw std::out_of_range(ss.str());
|
||||
}
|
||||
return mData[i];
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::Vector4::CArray --
|
||||
*/
|
||||
const Double*
|
||||
Vector4::CArray()
|
||||
const
|
||||
{
|
||||
return mData;
|
||||
}
|
||||
|
||||
#pragma mark Boolean Operators
|
||||
|
||||
/*
|
||||
* charles::basics::Vector4::operator== --
|
||||
*/
|
||||
bool
|
||||
Vector4::operator==(const Vector4 &rhs)
|
||||
const
|
||||
{
|
||||
for (UInt i = 0; i < 4; i++) {
|
||||
if (!NearlyEqual(mData[i], rhs.mData[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::Vector4::operator!= --
|
||||
*/
|
||||
bool
|
||||
Vector4::operator!=(const Vector4 &rhs)
|
||||
const
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
#pragma mark Maths
|
||||
|
||||
/*
|
||||
|
|
|
@ -33,6 +33,12 @@ struct Vector4
|
|||
Double Y() const;
|
||||
Double& Z();
|
||||
Double Z() const;
|
||||
|
||||
Double &operator()(UInt i);
|
||||
Double operator()(UInt i) const;
|
||||
|
||||
/** Get the underlying C array. */
|
||||
const Double *CArray() const;
|
||||
/** @} */
|
||||
|
||||
bool operator==(const Vector4 &rhs) const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue