/* * 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-2015 Danny Robson */ #ifndef __UTIL_POINT_HPP #define __UTIL_POINT_HPP #include "vector.hpp" #include "detail/coord.hpp" #include #include #include #include namespace util { /// An n-dimensional position in space. template struct point : public detail::coord { using detail::coord::coord; // point operators template typename std::common_type::type distance (const point &) const; template typename std::common_type::type distance2 (const point &) const; template typename std::common_type::type manhattan (const point &) const; vector to (const point&) const; // arithetic operators point& operator*= (T); point operator* (T) const; point& operator/= (T); point operator/ (T) const; vector operator- (const point&) const; point operator- (const vector&) const; point& operator-= (const vector&); point operator+ (const vector&) const; point& operator+= (const vector&); // logical operators bool operator== (const point&) const; template point redim (void) const; template point redim (const util::point &fill) const; static const point ORIGIN; template point cast (void) const; void sanity (void) const; }; // iostream operators template std::ostream& operator<< (std::ostream&, const point&); // Convenience typedefs typedef point<2,float> point2f; typedef point<3,float> point3f; typedef point<4,float> point4f; typedef point<2,double> point2d; typedef point<3,double> point3d; typedef point<2,size_t> point2u; } #include namespace std { template struct hash> { size_t operator() (const util::point &p) const { std::hash h; size_t k = 0; for (size_t i = 0; i < S; ++i) k = h (p.data[i] ^ k); return k; } }; } #include "point.ipp" #endif // __UTIL_POINT_HPP