19#include <cuspatial/cuda_utils.hpp>
22#include <thrust/device_reference.h>
39template <
typename T,
typename Vertex = cuspatial::vec_2d<T>>
47 segment<T> CUSPATIAL_HOST_DEVICE
translate(Vertex
const& v)
const
49 return segment<T>{v1 + v, v2 + v};
56 T CUSPATIAL_HOST_DEVICE
length2()
const {
return dot(v2 - v1, v2 - v1); }
59 T CUSPATIAL_HOST_DEVICE
slope() {
return (v2.y - v1.y) / (v2.x - v1.x); }
62 Vertex CUSPATIAL_HOST_DEVICE
lower_left() {
return v1 < v2 ? v1 : v2; }
67 bool CUSPATIAL_HOST_DEVICE
collinear(segment<T>
const& other)
69 return (v1.x - v2.x) * (other.v1.y - other.v2.y) == (v1.y - v2.y) * (other.v1.x - other.v2.x);
73 friend std::ostream& operator<<(std::ostream& os, segment<T>
const& seg)
75 return os << seg.v1 <<
" -> " << seg.v2;
81segment(vec_2d<T> a, vec_2d<T> b) -> segment<T, vec_2d<T>>;
84segment(thrust::device_reference<vec_2d<T>> a, thrust::device_reference<vec_2d<T>> b)
85 -> segment<T, vec_2d<T>>;
T CUSPATIAL_HOST_DEVICE length2() const
Return the length squared of segment.
bool CUSPATIAL_HOST_DEVICE collinear(segment< T > const &other)
vec_2d< T > CUSPATIAL_HOST_DEVICE midpoint(vec_2d< T > const &first, vec_2d< T > const &second)
Compute the midpoint of first and second.
Vertex CUSPATIAL_HOST_DEVICE lower_left()
Return the lower left vertex of segment.
T CUSPATIAL_HOST_DEVICE dot(vec_2d< T > const &a, vec_2d< T > const &b)
Compute dot product of two 2D vectors.
Vertex CUSPATIAL_HOST_DEVICE center() const
Return the geometric center of segment.
T CUSPATIAL_HOST_DEVICE slope()
Return slope of segment.
segment< T > CUSPATIAL_HOST_DEVICE translate(Vertex const &v) const
Return a copy of segment, translated by v.