/* * 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-2016 Danny Robson */ #ifndef __UTIL_POINT_HPP #define __UTIL_POINT_HPP #include "vector.hpp" #include "coord.hpp" #include namespace util { /// An n-dimensional position in space. /// /// \tparam S number of dimensions /// \tparam T the underlying per-dimension datatype template struct point : public coord::base { using coord::base::base; vector to (point) const; vector from (point) const; template point homog (void) const; static constexpr point origin (void); void sanity (void) const; }; /////////////////////////////////////////////////////////////////////////// // distance operators /// computes the exact euclidean distance between two points. template typename std::common_type::type distance (point, point); /// computes the squared euclidean distance between two points. /// /// useful if you just need to compare distances because it avoids a sqrt /// operation. template constexpr typename std::common_type::type distance2 (point, point); /// computes the octile distance between two points. that is, the shortest /// distance between `a' and `b' where travel is only allowed beween the 8 /// grid neighbours and cost for diagonals is proportionally larger than /// cardinal movement. see also: chebyshev. template typename std::common_type::type octile (point<2,T>, point<2,U>); /// computes the manhattan distance between two points. that is, the /// distance where travel is only allowed along cardinal directions. template constexpr typename std::common_type::type manhattan (point, point); /// computes the cheyvshev distance between two points. that is, the /// shortest distance between `a' and `b' where travel is only allowed /// between the 8 grid neighbours and cost for diagonals is the same as /// cardinal movement. see also: octile. template constexpr typename std::common_type::type chebyshev (point, point); // Convenience typedefs template using point1 = point<1,T>; template using point2 = point<2,T>; template using point3 = point<3,T>; template using point4 = point<4,T>; template using pointi = point; template using pointf = point; typedef point1 point1f; typedef point2 point2f; typedef point3 point3f; typedef point4 point4f; typedef point2 point2d; typedef point3 point3d; typedef point4 point4d; typedef point1 point1u; typedef point2 point2u; typedef point3 point3u; typedef point4 point4u; typedef point2 point2i; typedef point3 point3i; typedef point4 point4i; } #include "point.ipp" #endif // __UTIL_POINT_HPP