19#include <cuspatial/cuda_utils.hpp>
20#include <cuspatial/detail/utility/floating_point.cuh>
52 friend std::ostream&
operator<<(std::ostream& os, cuspatial::vec_2d<T>
const& vec)
54 return os <<
"(" << vec.x <<
"," << vec.y <<
")";
60 friend bool CUSPATIAL_HOST_DEVICE
operator==(vec_2d<T>
const& lhs, vec_2d<T>
const& rhs)
62 return detail::float_equal<T>(lhs.x, rhs.x) && detail::float_equal(lhs.y, rhs.y);
68 friend vec_2d<T> CUSPATIAL_HOST_DEVICE
operator+(vec_2d<T>
const& a, vec_2d<T>
const& b)
70 return vec_2d<T>{a.x + b.x, a.y + b.y};
76 friend vec_2d<T> CUSPATIAL_HOST_DEVICE
operator-(vec_2d<T>
const& a, vec_2d<T>
const& b)
78 return vec_2d<T>{a.x - b.x, a.y - b.y};
84 friend vec_2d<T> CUSPATIAL_HOST_DEVICE
operator-(vec_2d<T>
const& a)
86 return vec_2d<T>{-a.x, -a.y};
92 friend vec_2d<T> CUSPATIAL_HOST_DEVICE
operator*(vec_2d<T> vec, T
const& r)
94 return vec_2d<T>{vec.x * r, vec.y * r};
100 friend vec_2d<T> CUSPATIAL_HOST_DEVICE
operator*(T
const& r, vec_2d<T> vec) {
return vec * r; }
105 friend vec_2d<T>& CUSPATIAL_HOST_DEVICE
operator+=(vec_2d<T>& a, vec_2d<T>
const& b)
115 friend vec_2d<T>& CUSPATIAL_HOST_DEVICE
operator-=(vec_2d<T>& a, vec_2d<T>
const& b)
125 friend bool CUSPATIAL_HOST_DEVICE
operator<(vec_2d<T>
const& lhs, vec_2d<T>
const& rhs)
129 else if (lhs.x == rhs.x)
130 return lhs.y < rhs.y;
137 friend bool CUSPATIAL_HOST_DEVICE
operator>(vec_2d<T>
const& lhs, vec_2d<T>
const& rhs)
145 friend bool CUSPATIAL_HOST_DEVICE
operator<=(vec_2d<T>
const& lhs, vec_2d<T>
const& rhs)
153 friend bool CUSPATIAL_HOST_DEVICE
operator>=(vec_2d<T>
const& lhs, vec_2d<T>
const& rhs)
161vec_2d(T x, T y) -> vec_2d<T>;
167T CUSPATIAL_HOST_DEVICE
dot(vec_2d<T>
const& a, vec_2d<T>
const& b)
169 return a.x * b.x + a.y * b.y;
176T CUSPATIAL_HOST_DEVICE
det(vec_2d<T>
const& a, vec_2d<T>
const& b)
178 return a.x * b.y - a.y * b.x;
185vec_2d<T> CUSPATIAL_HOST_DEVICE
box_min(vec_2d<T>
const& a, vec_2d<T>
const& b)
188 return vec_2d<T>{::min(a.x, b.x), ::min(a.y, b.y)};
190 return vec_2d<T>{std::min(a.x, b.x), std::min(a.y, b.y)};
198vec_2d<T> CUSPATIAL_HOST_DEVICE
box_max(vec_2d<T>
const& a, vec_2d<T>
const& b)
201 return vec_2d<T>{::max(a.x, b.x), ::max(a.y, b.y)};
203 return vec_2d<T>{std::max(a.x, b.x), std::max(a.y, b.y)};
211vec_2d<T> CUSPATIAL_HOST_DEVICE
midpoint(vec_2d<T>
const& first, vec_2d<T>
const& second)
213 return (first + second) * T{0.5};
A generic 2D vector type.
friend bool CUSPATIAL_HOST_DEVICE operator>(vec_2d< T > const &lhs, vec_2d< T > const &rhs)
Greater than operator for two 2D points.
friend bool CUSPATIAL_HOST_DEVICE operator>=(vec_2d< T > const &lhs, vec_2d< T > const &rhs)
Greater than or equal to operator for two 2D points.
friend vec_2d< T > CUSPATIAL_HOST_DEVICE operator-(vec_2d< T > const &a, vec_2d< T > const &b)
Element-wise subtraction of two 2D vectors.
friend vec_2d< T > &CUSPATIAL_HOST_DEVICE operator-=(vec_2d< T > &a, vec_2d< T > const &b)
Translate a 2D point.
friend vec_2d< T > CUSPATIAL_HOST_DEVICE operator*(vec_2d< T > vec, T const &r)
Scale a 2D vector by a factor r.
friend vec_2d< T > CUSPATIAL_HOST_DEVICE operator-(vec_2d< T > const &a)
Invert a 2D vector.
friend vec_2d< T > CUSPATIAL_HOST_DEVICE operator*(T const &r, vec_2d< T > vec)
Scale a 2d vector by ratio r.
friend bool CUSPATIAL_HOST_DEVICE operator==(vec_2d< T > const &lhs, vec_2d< T > const &rhs)
Compare two 2D vectors for equality.
friend vec_2d< T > CUSPATIAL_HOST_DEVICE operator+(vec_2d< T > const &a, vec_2d< T > const &b)
Element-wise addition of two 2D vectors.
friend bool CUSPATIAL_HOST_DEVICE operator<=(vec_2d< T > const &lhs, vec_2d< T > const &rhs)
Less than or equal to operator for two 2D points.
friend bool CUSPATIAL_HOST_DEVICE operator<(vec_2d< T > const &lhs, vec_2d< T > const &rhs)
Less than operator for two 2D points.
friend vec_2d< T > &CUSPATIAL_HOST_DEVICE operator+=(vec_2d< T > &a, vec_2d< T > const &b)
Translate a 2D point.
friend std::ostream & operator<<(std::ostream &os, cuspatial::vec_2d< T > const &vec)
Output stream operator for vec_2d<T> for human-readable formatting.
T CUSPATIAL_HOST_DEVICE det(vec_2d< T > const &a, vec_2d< T > const &b)
Compute 2D determinant of a 2x2 matrix with column vectors a and b.
vec_2d< T > CUSPATIAL_HOST_DEVICE midpoint(vec_2d< T > const &first, vec_2d< T > const &second)
Compute the midpoint of first and second.
vec_2d< T > CUSPATIAL_HOST_DEVICE box_max(vec_2d< T > const &a, vec_2d< T > const &b)
Return a new vec_2d made up of the minimum x- and y-components of two input vec_2d values.
T CUSPATIAL_HOST_DEVICE dot(vec_2d< T > const &a, vec_2d< T > const &b)
Compute dot product of two 2D vectors.
vec_2d< T > CUSPATIAL_HOST_DEVICE box_min(vec_2d< T > const &a, vec_2d< T > const &b)
Return a new vec_2d made up of the minimum x- and y-components of two input vec_2d values.