加载中...
搜索中...
无匹配项
segment.cuh
前往此文件的文档。
1/*
2 * 版权所有 (c) 2022-2023, NVIDIA CORPORATION。
3 *
4 * 根据 Apache 许可证 2.0 版(“许可证”)获得许可;
5 * 除非遵守许可证,否则您不得使用此文件。
6 * 您可在以下网址获得许可证的副本
7 *
8 * https://apache.ac.cn/licenses/LICENSE-2.0
9 *
10 * 除非适用法律要求或书面同意,否则软件
11 * 根据许可证分发时,按“原样”分发,
12 * 不附带任何明示或暗示的保证或条件。
13 * 请参阅许可证,了解管辖权和
14 * 限制条件的特定语言。
15 */
16
17#pragma once
18
19#include <cuspatial/cuda_utils.hpp>
21
22#include <thrust/device_reference.h>
23
24#include <iostream>
25namespace cuspatial {
26
31
38
39template <typename T, typename Vertex = cuspatial::vec_2d<T>>
40class alignas(sizeof(Vertex)) segment {
41 public
42 using value_type = T;
43 Vertex v1;
44 Vertex v2;
45
47 segment<T> CUSPATIAL_HOST_DEVICE translate(Vertex const& v) const
48 {
49 return segment<T>{v1 + v, v2 + v};
50 }
51
53 Vertex CUSPATIAL_HOST_DEVICE center() const { return midpoint(v1, v2); }
54
56 T CUSPATIAL_HOST_DEVICE length2() const { return dot(v2 - v1, v2 - v1); }
57
59 T CUSPATIAL_HOST_DEVICE slope() { return (v2.y - v1.y) / (v2.x - v1.x); }
60
62 Vertex CUSPATIAL_HOST_DEVICE lower_left() { return v1 < v2 ? v1 : v2; }
63
67 bool CUSPATIAL_HOST_DEVICE collinear(segment<T> const& other)
68 {
69 return (v1.x - v2.x) * (other.v1.y - other.v2.y) == (v1.y - v2.y) * (other.v1.x - other.v2.x);
70 }
71
72 private
73 friend std::ostream& operator<<(std::ostream& os, segment<T> const& seg)
74 {
75 return os << seg.v1 << " -> " << seg.v2;
76 }
77};
78
79// deduction guide, enables CTAD
80template <typename T>
82
83template <typename T>
84segment(thrust::device_reference<vec_2d<T>> a, thrust::device_reference<vec_2d<T>> b)
86} // namespace cuspatial
一个通用的线段类型。
一个通用的二维向量类型。
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 向量平移。