point: add scalar division operation

This commit is contained in:
Danny Robson 2015-01-15 14:04:51 +11:00
parent c931c718fe
commit 09f5894d0c
3 changed files with 19 additions and 2 deletions

View File

@ -53,6 +53,21 @@ util::point<S,T>::operator* (T f) const {
} }
//-----------------------------------------------------------------------------
template <size_t S, typename T>
util::point<S,T>
util::point<S,T>::operator/ (T f) const
{
point<S,T> out;
std::transform (std::begin (this->data),
std::end (this->data),
std::begin (out.data),
[f] (auto i) { return i / f; });
return out;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <size_t S, typename T> template <size_t S, typename T>
util::point<S,T> util::point<S,T>

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with libgim. If not, see <http://www.gnu.org/licenses/>. * along with libgim. If not, see <http://www.gnu.org/licenses/>.
* *
* Copyright 2011-14 Danny Robson <danny@nerdcruft.net> * Copyright 2011-2015 Danny Robson <danny@nerdcruft.net>
*/ */
#ifndef __UTIL_POINT_HPP #ifndef __UTIL_POINT_HPP
@ -46,6 +46,8 @@ namespace util {
// arithetic operators // arithetic operators
point<S,T>& operator*= (T); point<S,T>& operator*= (T);
point<S,T> operator* (T) const; point<S,T> operator* (T) const;
point<S,T> operator/ (T) const;
point<S,T> operator- (const point<S,T>&) const; point<S,T> operator- (const point<S,T>&) const;
point<S,T> operator- (const vector<S,T>&) const; point<S,T> operator- (const vector<S,T>&) const;

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with libgim. If not, see <http://www.gnu.org/licenses/>. * along with libgim. If not, see <http://www.gnu.org/licenses/>.
* *
* Copyright 2014 Danny Robson <danny@nerdcruft.net> * Copyright 2014-2015 Danny Robson <danny@nerdcruft.net>
*/ */
#include "maths.hpp" #include "maths.hpp"