Add subtraction operators for point - vector

This commit is contained in:
Danny Robson 2013-08-06 14:31:46 +10:00
parent d6c0a821f4
commit 4e8d9e793b
2 changed files with 24 additions and 0 deletions

View File

@ -87,6 +87,27 @@ util::point<S>::operator* (double f) const {
}
//-----------------------------------------------------------------------------
template <size_t S>
util::point<S>
util::point<S>::operator- (const util::vector<S> &rhs) const {
util::point<S> out;
for (size_t i = 0; i < S; ++i)
out.data[i] = this->data[i] - rhs.data[i];
return out;
}
template <size_t S>
util::point<S>&
util::point<S>::operator-= (const util::vector<S> &rhs) {
for (size_t i = 0; i < S; ++i)
this->data[i] -= rhs.data[i];
return *this;
}
//-----------------------------------------------------------------------------
template <size_t S>
util::point<S>
util::point<S>::operator+ (const util::vector<S> &rhs) const {
@ -107,6 +128,7 @@ util::point<S>::operator+= (const util::vector<S> &rhs) {
}
//-----------------------------------------------------------------------------
template <size_t S>
util::point<S>
util::point<S>::operator- (const util::point<S> &rhs) const {

View File

@ -46,6 +46,8 @@ namespace util {
point<S> operator* (double) const;
point<S> operator- (const point<S>&) const;
point<S> operator- (const util::vector<S>&) const;
point<S>& operator-= (const util::vector<S>&);
point<S> operator+ (const util::vector<S>&) const;
point<S>& operator+= (const util::vector<S>&);