32 #ifndef HERMES_GEOMETRY_POINT_H
33 #define HERMES_GEOMETRY_POINT_H
35 #include <initializer_list>
50 static_assert(std::is_same<T, f32>::value || std::is_same<T, f64>::value ||
52 "Point2 must hold a float type!");
106 #define ARITHMETIC_OP(OP) \
107 HERMES_DEVICE_CALLABLE Point2 &operator OP##= (const Vector2 <T> &v) { \
108 x OP##= v.x; y OP##= v.y; return *this; } \
109 HERMES_DEVICE_CALLABLE Point2 &operator OP##= (real_t f) { \
110 x OP##= f; y OP##= f; return *this; } \
111 HERMES_DEVICE_CALLABLE Point2 operator OP (const Vector2 <T> &v) const { \
112 return {x OP v.x, y OP v.y}; } \
113 HERMES_DEVICE_CALLABLE Point2 operator OP (real_t f) const { \
114 return {x OP f, y OP f}; }
124 #define RELATIONAL_OP(OP, CO) \
125 HERMES_DEVICE_CALLABLE bool operator OP (const Point2<T> &b) const { \
126 return x OP b.x CO y OP b.y; }
129 RELATIONAL_OP(<=, &&)
130 RELATIONAL_OP(>=, &&)
131 RELATIONAL_OP(!=, ||)
149 static_assert(std::is_same<T, f32>::value || std::is_same<T, f64>::value ||
151 "Size2 must hold an float type!");
177 template<
typename S,
typename C = T>
179 typename std::enable_if_t<
192 template<
typename S,
typename C = T>
194 typename std::enable_if_t<
197 x(vi.
x),
y(vi.
y),
z(vi.
z) {}
203 z{static_cast<T>(index.k)} {}
223 #define ARITHMETIC_OP(OP) \
224 HERMES_DEVICE_CALLABLE Point3 &operator OP##= (const Vector3 <T> &v) { \
225 x OP##= v.x; y OP##= v.y; z OP##= v.z; return *this; } \
226 HERMES_DEVICE_CALLABLE Point3 &operator OP##= (real_t f) { \
227 x OP##= f; y OP##= f; z OP##= f; return *this; } \
228 HERMES_DEVICE_CALLABLE Point3 operator OP (const Vector3 <T> &v) const { \
229 return {x OP v.x, y OP v.y, z OP v.z}; } \
230 HERMES_DEVICE_CALLABLE Point3 operator OP (T f) const { \
231 return {x OP f, y OP f, z OP f}; }
241 #define RELATIONAL_OP(OP, CO) \
242 HERMES_DEVICE_CALLABLE bool operator OP (const Point3<T> &b) const { \
243 return x OP b.x CO y OP b.y CO z OP b.z; }
246 RELATIONAL_OP(<=, &&)
247 RELATIONAL_OP(>=, &&)
248 RELATIONAL_OP(!=, ||)
296 return (a - b).length();
305 return (a - b).length2();
314 return (a - b).length();
323 return (a - b).length2();
326 #define MATH_OP(NAME, OP) \
327 template<typename T> \
328 HERMES_DEVICE_CALLABLE Point2<T> NAME(const Point2<T>& p) { \
329 return Point2<T>(OP(p.x), OP(p.y)); }
330 #ifdef HERMES_DEVICE_ENABLED
331 MATH_OP(floor, ::floor)
332 MATH_OP(ceil, ::ceil)
335 MATH_OP(floor, std::floor)
336 MATH_OP(ceil, std::ceil)
337 MATH_OP(abs, std::abs)
345 std::ostream &operator<<(std::ostream &os,
const Point2<T> &p) {
346 os <<
"Point2[" << p.x <<
" " << p.y <<
"]";
350 std::ostream &
operator<<(std::ostream &os,
const Point3<T> &p) {
351 os <<
"Point3[" << p.x <<
" " << p.y <<
" " << p.z <<
"]";
358 using point2 = Point2<real_t>;
359 using point2f = Point2<float>;
360 using point2d = Point2<double>;
361 using point3 = Point3<real_t>;
362 using point3f = Point3<float>;
363 using point3d = Point3<double>;
364 using point2i = Point2<Interval<real_t>>;
365 using point3i = Point3<Interval<real_t>>;
374 template<
typename T>
struct hash<hermes::Point2<T>> {
382 size_t h = hasher(v.
x);
383 h += 0x9e3779b9 + (s << 6) + (s >> 2);
387 h += 0x9e3779b9 + (s << 6) + (s >> 2);
395 template<
typename T>
struct hash<hermes::Point3<T>> {
403 size_t h = hasher(v.
x);
404 h += 0x9e3779b9 + (s << 6) + (s >> 2);
408 h += 0x9e3779b9 + (s << 6) + (s >> 2);
412 h += 0x9e3779b9 + (s << 6) + (s >> 2);
Interface used by all basic geometric entities.
Definition: math_element.h:44
Geometric 2-dimensional point (x, y)
Definition: point.h:49
HERMES_DEVICE_CALLABLE Point2(T f=T(0))
Constructs from single component value.
Definition: point.h:59
HERMES_DEVICE_CALLABLE Point2(const real_t *v)
Constructs from component array.
Definition: point.h:62
T y
1-th component
Definition: point.h:140
HERMES_DEVICE_CALLABLE Point2 & operator=(const Index2< U > &index)
Copy assigns from index 2.
Definition: point.h:89
HERMES_DEVICE_CALLABLE Point2(real_t _x, real_t _y)
Constructs from component values.
Definition: point.h:66
HERMES_DEVICE_CALLABLE T & operator[](int i)
Get i-th component reference.
Definition: point.h:104
HERMES_DEVICE_CALLABLE const T & operator[](int i) const
Get i-th component.
Definition: point.h:99
HERMES_DEVICE_CALLABLE Point2(const Index2< U > &index)
Constructs from index2.
Definition: point.h:71
T x
0-th component
Definition: point.h:139
Geometric 3-dimensional vector (x, y, z)
Definition: point.h:148
HERMES_DEVICE_CALLABLE T operator[](int i) const
Get i-th component.
Definition: point.h:216
HERMES_DEVICE_CALLABLE Point3()
Default constructor.
Definition: point.h:157
T x
0-th component
Definition: point.h:270
HERMES_DEVICE_CALLABLE Point3(T v)
Constructs from single component value.
Definition: point.h:160
HERMES_DEVICE_CALLABLE Point2< T > xz() const
Gets 2-dimensional swizzle (x, z)
Definition: point.h:266
HERMES_DEVICE_CALLABLE T & operator[](int i)
Get i-th component reference.
Definition: point.h:221
HERMES_DEVICE_CALLABLE Point3(const Point3< S > &c, const Vector3< S > &r, typename std::enable_if_t< std::is_same_v< C, Interval< f32 >>||std::is_same_v< C, Interval< f64 >>> *=nullptr)
Constructs from interval center and radius.
Definition: point.h:178
HERMES_DEVICE_CALLABLE Point2< T > xy() const
Gets 2-dimensional swizzle (x, y)
Definition: point.h:260
HERMES_DEVICE_CALLABLE Point2< T > yz() const
Gets 2-dimensional swizzle (y, z)
Definition: point.h:263
T y
1-th component
Definition: point.h:271
HERMES_DEVICE_CALLABLE Point3(const Index3< U > &index)
Constructs from index3.
Definition: point.h:202
HERMES_DEVICE_CALLABLE Point3(const Point3< Interval< S >> &vi, typename std::enable_if_t< !std::is_same_v< C, Interval< f32 >> &&!std::is_same_v< C, Interval< f64 >>> *=nullptr)
Constructs from interval point3.
Definition: point.h:193
HERMES_DEVICE_CALLABLE Point3(const real_t *v)
Constructs from component array.
Definition: point.h:171
HERMES_DEVICE_CALLABLE Point3(const Vector3< T > &v)
Constructs from vector.
Definition: point.h:187
HERMES_DEVICE_CALLABLE Point3(T _x, T _y, T _z)
Constructs from component values.
Definition: point.h:165
HERMES_DEVICE_CALLABLE Point3(const Point2< T > &p, T _z=0)
Constructs from point2.
Definition: point.h:168
T z
2-th component
Definition: point.h:272
Geometric 2-dimensional vector (x, y)
Definition: vector.h:54
Geometric 3-dimensional vector (x, y, z)
Definition: vector.h:166
std::ostream & operator<<(std::ostream &o, const LaunchInfo &info)
LaunchInfo support for std::ostream << operator.
Definition: cuda_utils.h:234
Debug, logging and assertion macros.
float real_t
default floating point type
Definition: defs.h:75
#define HERMES_DEVICE_CALLABLE
Specifies that the function can be called from both host and device sides.
Definition: defs.h:45
#define ARITHMETIC_OP(OP)
asd
Definition: index.h:408
HERMES_DEVICE_CALLABLE real_t distance2(const Point2< T > &a, const Point2< T > &b)
Computes the squared Euclidean distance between two points.
Definition: point.h:304
HERMES_DEVICE_CALLABLE real_t distance(const Point2< T > &a, const Point2< T > &b)
Computes the Euclidean distance between two points.
Definition: point.h:295
static constexpr HERMES_DEVICE_CALLABLE bool is_equal(T a, T b)
Checks if two numbers are at most 1e-8 apart.
Definition: numeric.h:847
Holds 2-dimensional integer index coordinates.
Definition: index.h:50
T i
0-th coordinate value
Definition: index.h:199
T j
1-th coordinate value
Definition: index.h:201
Holds 3-dimensional index coordinates.
Definition: index.h:362
size_t operator()(hermes::Point2< T > const &v) const
Computes hash for a given vector.
Definition: point.h:378
size_t operator()(hermes::Point3< T > const &v) const
Computes hash for a given vector.
Definition: point.h:399
Geometric vector classes.