19#include <cuspatial/cuda_utils.hpp>
22#include <thrust/device_reference.h>
39template <
typename T,
typename Vertex = cuspatial::vec_2d<T>>
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; }
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;
T CUSPATIAL_HOST_DEVICE length2() const
返回线段的长度平方。
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)
计算 first 和 second 的中点。
Vertex CUSPATIAL_HOST_DEVICE lower_left()
返回线段的左下角顶点。
T CUSPATIAL_HOST_DEVICE dot(vec_2d< T > const &a, vec_2d< T > const &b)
计算两个二维向量的点积。
Vertex CUSPATIAL_HOST_DEVICE center() const
返回线段的几何中心。
T CUSPATIAL_HOST_DEVICE slope()
返回线段的斜率。
segment< T > CUSPATIAL_HOST_DEVICE translate(Vertex const &v) const
返回线段的副本,由 v 向量平移。