LSST Applications g1653933729+34a971ddd9,g1a997c3884+34a971ddd9,g28da252d5a+32b12a4112,g2bbee38e9b+ffc559ee46,g2bc492864f+ffc559ee46,g2cdde0e794+704103fe75,g3156d2b45e+6e87dc994a,g347aa1857d+ffc559ee46,g35bb328faa+34a971ddd9,g3a166c0a6a+ffc559ee46,g3e281a1b8c+8ec26ec694,g4005a62e65+ba0306790b,g414038480c+9f5be647b3,g41af890bb2+686ab7cd58,g4e1a3235cc+1fd785b14f,g7b55021d1b+da0d0eec6b,g80478fca09+6e21f9dc20,g82479be7b0+6fa35d7547,g858d7b2824+356eaf3287,g9125e01d80+34a971ddd9,ga5288a1d22+ba1f9bb3ef,gae0086650b+34a971ddd9,gb4748cc0e8+fd26a265a0,gb4ec7eb0ab+356eaf3287,gb58c049af0+ace264a4f2,gc081298178+30f12d1e69,gc28159a63d+ffc559ee46,gcf0d15dbbd+4adb3139bd,gd6b7c0dfd1+aae9efebf5,gda3e153d99+356eaf3287,gda6a2b7d83+4adb3139bd,gdaeeff99f8+7774323b41,gdd5a9049c5+ea78b51778,ge2409df99d+fa478de0b0,ge33fd446bb+356eaf3287,ge79ae78c31+ffc559ee46,gf0baf85859+890af219f9,gf5289d68f6+e11c78aeea,w.2024.41
LSST Data Management Base Package
Loading...
Searching...
No Matches
Point.h
Go to the documentation of this file.
1/*
2 * Developed for the LSST Data Management System.
3 * This product includes software developed by the LSST Project
4 * (https://www.lsst.org).
5 * See the COPYRIGHT file at the top-level directory of this distribution
6 * for details of code ownership.
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22/*
23 * A coordinate class intended to represent absolute positions.
24 */
25#ifndef LSST_GEOM_POINT_H
26#define LSST_GEOM_POINT_H
27
28#include <tuple>
29
32#include "lsst/geom/Extent.h"
33
34namespace lsst {
35namespace geom {
36
37template <typename T, int N>
38class PointBase : public CoordinateBase<Point<T, N>, T, N> {
39 typedef CoordinateBase<Point<T, N>, T, N> Super;
40
41public:
42 PointBase(PointBase const &) = default;
43 PointBase(PointBase &&) = default;
44 PointBase &operator=(PointBase const &) = default;
46 ~PointBase() = default;
47
53 bool operator==(Point<T, N> const &other) const noexcept { return all(this->eq(other)); }
54
60 bool operator!=(Point<T, N> const &other) const noexcept { return any(this->ne(other)); }
61
75 CoordinateExpr<N> eq(Point<T, N> const &other) const noexcept;
76 CoordinateExpr<N> ne(Point<T, N> const &other) const noexcept;
77 CoordinateExpr<N> lt(Point<T, N> const &other) const noexcept;
78 CoordinateExpr<N> le(Point<T, N> const &other) const noexcept;
79 CoordinateExpr<N> gt(Point<T, N> const &other) const noexcept;
80 CoordinateExpr<N> ge(Point<T, N> const &other) const noexcept;
82 return this->eq(Point<T, N>(scalar));
83 }
85 return this->ne(Point<T, N>(scalar));
86 }
88 return this->lt(Point<T, N>(scalar));
89 }
91 return this->le(Point<T, N>(scalar));
92 }
94 return this->gt(Point<T, N>(scalar));
95 }
97 return this->ge(Point<T, N>(scalar));
98 }
100
108 return Extent<T, N>(this->_vector - other._vector);
109 }
111 return Point<T, N>(this->_vector + other.asEigen());
112 }
114 return Point<T, N>(this->_vector - other.asEigen());
115 }
117 this->_vector += other.asEigen();
118 return static_cast<Point<T, N> &>(*this);
119 }
121 this->_vector -= other.asEigen();
122 return static_cast<Point<T, N> &>(*this);
123 }
125
128 return Extent<T, N>(static_cast<Point<T, N> const &>(*this));
129 }
130
133 this->_vector += offset.asEigen();
134 }
135
136 void scale(double factor) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE) { this->_vector *= factor; }
137
139 // the cast to double is lame but Eigen seems to require they be the same type
140 return (this->asEigen() - other.asEigen()).squaredNorm();
141 }
142
145 out << "Point(";
146 for (size_t i = 0; i < N; ++i) {
147 if (i != 0) {
148 out << ",";
149 }
150 out << (*this)[i];
151 }
152 out << ")";
153 return out.str();
154 }
155
156protected:
157 explicit PointBase(T val = static_cast<T>(0)) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE) : Super(val) {}
158
159 template <typename Vector>
160 explicit PointBase(Eigen::MatrixBase<Vector> const &vector) : Super(vector) {}
161};
162
168template <typename T, int N>
169class Point : public PointBase<T, N> {
170 typedef PointBase<T, N> Super;
171
172public:
174
176 explicit Point(T val = static_cast<T>(0)) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE) : Super(val) {}
177
178 Point(Point const &) = default;
179 Point(Point &&) = default;
180 ~Point() = default;
181
182 Point &operator=(Point const &) = default;
183 Point &operator=(Point &&) = default;
184
192 template <typename U>
193 explicit Point(Point<U, N> const &other) noexcept(IS_NOTHROW_CONVERTIBLE<T, U>);
194
196 explicit Point(EigenVector const &vector) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE) : Super(vector) {}
197
200 : Super(other.asEigen()) {}
201
202 void swap(Point &other) noexcept { this->_swap(other); }
203};
204
210template <typename T>
211class Point<T, 2> : public PointBase<T, 2> {
212 typedef PointBase<T, 2> Super;
213
214public:
216
218 explicit Point(T val = static_cast<T>(0)) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE) : Super(val) {}
219
220 Point(Point const &) = default;
221 Point(Point &&) = default;
222 ~Point() = default;
223
224 Point &operator=(Point const &) = default;
225 Point &operator=(Point &&) = default;
226
234 template <typename U>
235 explicit Point(Point<U, 2> const &other) noexcept(IS_NOTHROW_CONVERTIBLE<T, U>);
236
238 explicit Point(EigenVector const &vector) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE) : Super(vector) {}
239
242 : Super(other.asEigen()) {}
243
246
248 explicit Point(T const xy[2]) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
249 : Super(EigenVector(xy[0], xy[1])) {}
250
253 : Super(EigenVector(xy.first, xy.second)) {}
254
257 : Super(EigenVector(std::get<0>(xy), std::get<1>(xy))) {}
258
259 void swap(Point &other) noexcept { this->_swap(other); }
260};
261
267template <typename T>
268class Point<T, 3> : public PointBase<T, 3> {
269 typedef PointBase<T, 3> Super;
270
271public:
273
275 explicit Point(T val = static_cast<T>(0)) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE) : Super(val) {}
276
277 Point(Point const &) = default;
278 Point(Point &&) = default;
279 ~Point() = default;
280
281 Point &operator=(Point const &) = default;
282 Point &operator=(Point &&) = default;
283
291 template <typename U>
292 explicit Point(Point<U, 3> const &other) noexcept(IS_NOTHROW_CONVERTIBLE<T, U>);
293
295 explicit Point(EigenVector const &vector) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE) : Super(vector) {}
296
299 : Super(other.asEigen()) {}
300
302 explicit Point(T x, T y, T z) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
303 : Super(EigenVector(x, y, z)) {}
304
306 explicit Point(T const xyz[3]) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
307 : Super(EigenVector(xyz[0], xyz[1], xyz[2])) {}
308
311 : Super(EigenVector(std::get<0>(xyz), std::get<1>(xyz), std::get<2>(xyz))) {}
312
313 void swap(Point &other) noexcept { this->_swap(other); }
314};
315
316// Hash functions
317template <typename T, int N>
318std::size_t hash_value(Point<T, N> const &point) noexcept;
319
326
327template <int N>
329 return lhs + Extent<double, N>(rhs);
330}
331
332template <int N>
334 return Point<double, N>(lhs) + rhs;
335}
336
337template <int N>
339 return lhs += Extent<double, N>(rhs);
340}
341
342template <int N>
344 return Point<double, N>(lhs) + rhs;
345}
346
347template <int N>
349 return lhs - Extent<double, N>(rhs);
350}
351
352template <int N>
354 return lhs -= Extent<double, N>(rhs);
355}
356
357template <int N>
359 return Point<double, N>(lhs) - rhs;
360}
361
362template <int N>
364 return lhs - Point<double, N>(rhs);
365}
366
367template <int N>
369 return Point<double, N>(lhs) - rhs;
370}
371
372} // namespace geom
373} // namespace lsst
374
375namespace std {
376template <typename T, int N>
382} // namespace std
383
384#endif
double z
Definition Match.cc:44
int y
Definition SpanSet.cc:48
A CRTP base class for coordinate objects.
void _swap(CoordinateBase &other) noexcept
Eigen::Matrix< T, N, 1, Eigen::DontAlign > EigenVector
EigenVector const & asEigen() const noexcept(IS_ELEMENT_NOTHROW_COPYABLE)
Return a fixed-size Eigen representation of the coordinate object.
A boolean coordinate.
A coordinate class intended to represent offsets and dimensions.
Definition Extent.h:210
Point(T val=static_cast< T >(0)) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Construct a Point with all elements set to the same scalar value.
Definition Point.h:218
Point(std::tuple< T, T > const &xy) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Construct from std::tuple.
Definition Point.h:256
Point(EigenVector const &vector) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Construct a Point from an Eigen vector.
Definition Point.h:238
Point(T x, T y) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Explicit constructor from a pair of doubles.
Definition Point.h:245
Super::EigenVector EigenVector
Definition Point.h:215
Point(std::pair< T, T > const &xy) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Construct from a std::pair.
Definition Point.h:252
Point & operator=(Point const &)=default
Point(T const xy[2]) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Construct from a two-element array.
Definition Point.h:248
void swap(Point &other) noexcept
Definition Point.h:259
Point(Point const &)=default
Point(Extent< T, 2 > const &other) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Explicit constructor from Extent.
Definition Point.h:241
Point & operator=(Point &&)=default
Point(Point &&)=default
Point(T const xyz[3]) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Construct from a two-element array.
Definition Point.h:306
Point(Point const &)=default
Point & operator=(Point const &)=default
Point(T val=static_cast< T >(0)) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Construct a Point with all elements set to the same scalar value.
Definition Point.h:275
Point(EigenVector const &vector) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Construct a Point from an Eigen vector.
Definition Point.h:295
Point(std::tuple< T, T, T > const &xyz) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Construct from std::tuple.
Definition Point.h:310
Point(Extent< T, 3 > const &other) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Explicit constructor from Extent.
Definition Point.h:298
Point & operator=(Point &&)=default
void swap(Point &other) noexcept
Definition Point.h:313
Super::EigenVector EigenVector
Definition Point.h:272
Point(T x, T y, T z) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Explicit constructor from a sequence of doubles.
Definition Point.h:302
Point(Point &&)=default
CoordinateExpr< N > ne(Point< T, N > const &other) const noexcept
Definition Point.cc:83
Point< T, N > operator-(Extent< T, N > const &other) const noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Cast this object to an Extent of the same numeric type and dimensionality.
Definition Point.h:113
CoordinateExpr< N > eq(T scalar) const noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Definition Point.h:81
double distanceSquared(PointBase< T, N > const &other) const noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Cast this object to an Extent of the same numeric type and dimensionality.
Definition Point.h:138
PointBase(PointBase &&)=default
CoordinateExpr< N > lt(Point< T, N > const &other) const noexcept
Definition Point.cc:90
Point< T, N > & operator+=(Extent< T, N > const &other) noexcept(Super::IS_ELEMENT_NOTHROW_ASSIGNABLE)
Cast this object to an Extent of the same numeric type and dimensionality.
Definition Point.h:116
CoordinateExpr< N > le(Point< T, N > const &other) const noexcept
Definition Point.cc:97
Point< T, N > & operator-=(Extent< T, N > const &other) noexcept(Super::IS_ELEMENT_NOTHROW_ASSIGNABLE)
Cast this object to an Extent of the same numeric type and dimensionality.
Definition Point.h:120
bool operator!=(Point< T, N > const &other) const noexcept
Standard inequality comparison.
Definition Point.h:60
PointBase & operator=(PointBase &&)=default
void scale(double factor) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Cast this object to an Extent of the same numeric type and dimensionality.
Definition Point.h:136
CoordinateExpr< N > ge(T scalar) const noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Definition Point.h:96
CoordinateExpr< N > ge(Point< T, N > const &other) const noexcept
Definition Point.cc:111
CoordinateExpr< N > le(T scalar) const noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Definition Point.h:90
CoordinateExpr< N > gt(Point< T, N > const &other) const noexcept
Definition Point.cc:104
PointBase(PointBase const &)=default
CoordinateExpr< N > lt(T scalar) const noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Definition Point.h:87
void shift(Extent< T, N > const &offset) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Shift the point by the given offset.
Definition Point.h:132
PointBase & operator=(PointBase const &)=default
PointBase(Eigen::MatrixBase< Vector > const &vector)
Cast this object to an Extent of the same numeric type and dimensionality.
Definition Point.h:160
bool operator==(Point< T, N > const &other) const noexcept
Standard equality comparison.
Definition Point.h:53
CoordinateExpr< N > gt(T scalar) const noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Definition Point.h:93
PointBase(T val=static_cast< T >(0)) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Cast this object to an Extent of the same numeric type and dimensionality.
Definition Point.h:157
Extent< T, N > asExtent() const noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Cast this object to an Extent of the same numeric type and dimensionality.
Definition Point.h:127
CoordinateExpr< N > eq(Point< T, N > const &other) const noexcept
Definition Point.cc:76
Point< T, N > operator+(Extent< T, N > const &other) const noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Cast this object to an Extent of the same numeric type and dimensionality.
Definition Point.h:110
CoordinateExpr< N > ne(T scalar) const noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Definition Point.h:84
std::string toString() const
Cast this object to an Extent of the same numeric type and dimensionality.
Definition Point.h:143
Extent< T, N > operator-(Point< T, N > const &other) const noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Cast this object to an Extent of the same numeric type and dimensionality.
Definition Point.h:107
A coordinate class intended to represent absolute positions.
Definition Point.h:169
Point(Point const &)=default
Point(Extent< T, N > const &other) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Explicit constructor from Extent.
Definition Point.h:199
Point(T val=static_cast< T >(0)) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Construct a Point with all elements set to the same scalar value.
Definition Point.h:176
Point & operator=(Point &&)=default
Super::EigenVector EigenVector
Definition Point.h:173
Point(EigenVector const &vector) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Construct a Point from an Eigen vector.
Definition Point.h:196
void swap(Point &other) noexcept
Definition Point.h:202
Point & operator=(Point const &)=default
Point(Point &&)=default
Extent< double, N > & operator+=(Extent< double, N > &lhs, Extent< int, N > const &rhs) noexcept
Definition Extent.h:470
Point< double, 2 > PointD
Definition Point.h:323
constexpr Angle operator+(Angle a, Angle d) noexcept
Sum of two angles.
Definition Angle.h:315
std::size_t hash_value(Extent< T, N > const &extent) noexcept
Definition Extent.cc:127
bool any(CoordinateExpr< N > const &expr) noexcept
Return true if any elements are true.
constexpr Angle operator-(Angle a, Angle d) noexcept
Difference of two angles.
Definition Angle.h:321
bool all(CoordinateExpr< N > const &expr) noexcept
Return true if all elements are true.
Point< int, 2 > PointI
Definition Point.h:320
Point< double, 3 > Point3D
Definition Point.h:325
Point< double, 2 > Point2D
Definition Point.h:324
Extent< double, N > & operator-=(Extent< double, N > &lhs, Extent< int, N > const &rhs) noexcept
Definition Extent.h:480
Point< int, 3 > Point3I
Definition Point.h:322
Point< int, 2 > Point2I
Definition Point.h:321
STL namespace.
decltype(sizeof(void *)) size_t
Definition doctest.h:524
ImageT val
Definition CR.cc:146
T str(T... args)
result_type operator()(argument_type const &x) const noexcept
Definition Point.h:380