/*
* This file is part of libgim.
*
* libgim is free software: you can redistribute it and/or modify it under the
* 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.
*
* libgim is distributed in the hope that it will be useful, but WITHOUT ANY
* 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
* along with libgim. If not, see .
*
* Copyright 2011 Danny Robson
*/
#ifndef __UTIL_VECTOR_HPP
#define __UTIL_VECTOR_HPP
#include "json/tree.hpp"
#include "coord.hpp"
#include
#include
#include
namespace util {
template
struct vector : public coord::base {
using coord::base::base;
bool is_zero (void) const;
// vector operators
T magnitude (void) const;
T magnitude2 (void) const;
T difference (const vector&) const;
T difference2 (const vector&) const;
vector& normalise (void);
vector normalised [[gnu::warn_unused_result]] (void) const;
// size operations
template vector redim (void) const;
template vector redim (const util::vector &fill) const;
template vector redim (T fill) const;
// constants
static const vector ZERO;
void sanity (void) const;
};
// free vector operators
template vector<2,T> polar_to_cartesian (const vector<2,T>&);
template vector<3,T> cross (const vector<3,T>&, const vector<3,T>&);
template vector<3,T> spherical_to_cartesian (const vector<3,T>&);
template vector<3,T> cartesian_to_spherical (const vector<3,T>&);
// output and serialisation operators
template std::ostream& operator<< (std::ostream&, const vector&);
template
const json::tree::node& operator>> (const json::tree::node&, vector&);
// convenience typedefs
typedef vector<2,size_t> vector2u;
typedef vector<2,long> vector2i;
typedef vector<2,float> vector2f;
typedef vector<3,float> vector3f;
typedef vector<4,float> vector4f;
typedef vector<2,double> vector2d;
typedef vector<3,double> vector3d;
typedef vector<3,double> vector4d;
}
#include "vector.ipp"
#endif