2011-05-23 17:18:52 +10:00
|
|
|
/*
|
2011-06-21 20:26:32 +10:00
|
|
|
* This file is part of libgim.
|
2011-05-23 17:18:52 +10:00
|
|
|
*
|
2011-06-21 20:26:32 +10:00
|
|
|
* libgim is free software: you can redistribute it and/or modify it under the
|
2011-05-23 17:18:52 +10:00
|
|
|
* terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
* version.
|
|
|
|
*
|
2011-06-21 20:26:32 +10:00
|
|
|
* libgim is distributed in the hope that it will be useful, but WITHOUT ANY
|
2011-05-23 17:18:52 +10:00
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2011-06-21 20:26:32 +10:00
|
|
|
* along with libgim. If not, see <http://www.gnu.org/licenses/>.
|
2011-05-23 17:18:52 +10:00
|
|
|
*
|
2012-04-23 13:06:41 +10:00
|
|
|
* Copyright 2011 Danny Robson <danny@nerdcruft.net>
|
2011-05-23 17:18:52 +10:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __UTIL_VECTOR_HPP
|
|
|
|
#define __UTIL_VECTOR_HPP
|
|
|
|
|
2011-10-29 21:17:48 +11:00
|
|
|
#include "json.hpp"
|
2012-05-18 17:56:24 +10:00
|
|
|
#include "detail/coord.hpp"
|
2011-10-29 21:17:48 +11:00
|
|
|
|
2012-05-18 17:56:24 +10:00
|
|
|
#include <array>
|
2011-10-18 21:45:55 +11:00
|
|
|
#include <iostream>
|
2012-05-18 17:56:24 +10:00
|
|
|
#include <initializer_list>
|
2011-05-23 17:18:52 +10:00
|
|
|
|
2011-10-18 21:45:55 +11:00
|
|
|
namespace util {
|
2012-05-18 17:56:24 +10:00
|
|
|
template <size_t S>
|
|
|
|
struct vector : public detail::coord_data<S> {
|
|
|
|
static_assert (S > 0, "vector dimensions must be strictly positive");
|
2011-05-23 17:18:52 +10:00
|
|
|
|
2012-05-18 17:56:24 +10:00
|
|
|
vector ();
|
2011-05-23 17:18:52 +10:00
|
|
|
|
2012-05-18 17:56:24 +10:00
|
|
|
template <typename... T>
|
|
|
|
vector (T ...t): detail::coord_data<S> {std::forward<T> (t)...} { ; }
|
2011-05-23 17:18:52 +10:00
|
|
|
|
2012-05-18 17:56:24 +10:00
|
|
|
util::vector<S> operator* (double) const;
|
|
|
|
util::vector<S>& operator*=(double);
|
2012-05-22 14:13:34 +10:00
|
|
|
|
|
|
|
util::vector<S> operator/ (double) const;
|
|
|
|
util::vector<S>& operator/=(double);
|
|
|
|
|
|
|
|
util::vector<S> operator+ (double) const;
|
|
|
|
util::vector<S>& operator+=(double);
|
|
|
|
|
|
|
|
util::vector<S> operator- (double) const;
|
|
|
|
util::vector<S>& operator-=(double);
|
|
|
|
|
|
|
|
|
2012-05-18 17:56:24 +10:00
|
|
|
util::vector<S> operator* (const util::vector<S>&) const;
|
|
|
|
util::vector<S>& operator*=(const util::vector<S>&);
|
2011-05-23 17:18:52 +10:00
|
|
|
|
2012-05-18 17:56:24 +10:00
|
|
|
util::vector<S> operator+ (const util::vector<S>&) const;
|
|
|
|
util::vector<S>& operator+=(const util::vector<S>&);
|
2011-05-23 17:18:52 +10:00
|
|
|
|
2012-05-18 17:56:24 +10:00
|
|
|
util::vector<S> operator- (void) const;
|
|
|
|
util::vector<S> operator- (const util::vector<S>&) const;
|
|
|
|
util::vector<S>& operator-=(const util::vector<S>&);
|
|
|
|
|
|
|
|
util::vector<S>& operator =(const util::vector <S>&);
|
|
|
|
|
|
|
|
bool operator== (const util::vector <S>&) const;
|
2011-10-29 15:07:34 +11:00
|
|
|
|
2011-10-18 21:45:55 +11:00
|
|
|
double magnitude (void) const;
|
|
|
|
double magnitude2 (void) const;
|
2011-05-23 17:18:52 +10:00
|
|
|
|
2012-05-18 17:56:24 +10:00
|
|
|
double dot (const util::vector<S>&) const;
|
2011-05-23 17:18:52 +10:00
|
|
|
|
2012-05-18 17:56:24 +10:00
|
|
|
util::vector<S>& normalise (void);
|
|
|
|
util::vector<S> normalised (void) const;
|
2011-05-23 17:18:52 +10:00
|
|
|
|
2011-10-29 23:14:07 +11:00
|
|
|
|
2012-05-03 15:56:56 +10:00
|
|
|
bool is_zero (void) const;
|
|
|
|
|
2011-10-18 21:45:55 +11:00
|
|
|
void sanity (void) const;
|
2011-05-23 17:18:52 +10:00
|
|
|
};
|
2012-04-24 18:12:07 +10:00
|
|
|
|
2012-05-18 17:56:24 +10:00
|
|
|
vector<3> cross (const vector<3>&, const vector<3>&);
|
|
|
|
|
|
|
|
vector<3> spherical_to_cartesian (const util::vector <3>&);
|
|
|
|
vector<3> cartesian_to_spherical (const util::vector <3>&);
|
|
|
|
|
|
|
|
|
|
|
|
typedef vector<2> vector2;
|
|
|
|
typedef vector<3> vector3;
|
|
|
|
|
|
|
|
|
|
|
|
template <size_t S>
|
|
|
|
util::vector<S> operator* (double, const util::vector<S>&);
|
|
|
|
|
|
|
|
template <size_t S>
|
|
|
|
std::ostream& operator<< (std::ostream&, const util::vector<S>&);
|
2012-04-24 18:12:07 +10:00
|
|
|
|
2012-05-18 17:56:24 +10:00
|
|
|
template <size_t S>
|
|
|
|
const json::node& operator>> (const json::node&, util::vector<S>&);
|
2012-04-24 18:12:07 +10:00
|
|
|
|
2011-05-23 17:18:52 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
2011-10-18 21:45:55 +11:00
|
|
|
|