/* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Copyright 2011-2015 Danny Robson */ #ifndef __UTIL_POINT_HPP #define __UTIL_POINT_HPP #include "extent.hpp" #include "vector.hpp" #include "coord.hpp" #include #include #include #include namespace util { /// An n-dimensional position in space. template struct point : public coord::base { using coord::base::base; // 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; vector from (const point&) const; template point homog (void) const; static const point ORIGIN; 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; typedef point<2,intmax_t> point2i; } #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