28 #ifndef LSST_AFW_GEOM_EXTENT_H 29 #define LSST_AFW_GEOM_EXTENT_H 32 #include <type_traits> 34 #include "lsst/pex/exceptions.h" 51 throw LSST_EXCEPT(pex::exceptions::LogicError,
"Cannot compute norm of integer extent");
52 #if 1 // make compilers happy in non-void function 59 template <
typename T,
int N>
125 this->_vector += other.
_vector;
129 this->_vector -= other.
_vector;
144 this->_vector *= scalar;
149 this->_vector /= scalar;
158 std::stringstream out;
160 for (
size_t i = 0; i < N; ++i) {
172 explicit ExtentBase(T val = static_cast<T>(0)) : Super(val) {}
175 template <
typename Vector>
176 explicit ExtentBase(Eigen::MatrixBase<Vector>
const &vector) : Super(vector) {}
186 template <
typename T,
int N>
194 explicit Extent(T val = static_cast<T>(0)) : Super(val) {}
197 explicit Extent(EigenVector
const &vector) : Super(vector) {}
203 template <
typename U>
205 template <
typename U>
222 template <
typename T>
230 explicit Extent(T val = static_cast<T>(0)) : Super(val) {}
233 explicit Extent(EigenVector
const &vector) : Super(vector) {}
239 template <
typename U>
241 template <
typename U>
245 explicit Extent(T
x, T y) : Super(EigenVector(x, y)) {}
248 explicit Extent(T
const xy[2]) : Super(EigenVector(xy[0], xy[1])) {}
254 explicit Extent(std::tuple<T, T>
const &xy) : Super(EigenVector(
std::
get<0>(xy),
std::
get<1>(xy))) {}
264 template <
typename T>
272 explicit Extent(T val = static_cast<T>(0)) : Super(val) {}
275 explicit Extent(EigenVector
const &vector) : Super(vector) {}
281 template <
typename U>
283 template <
typename U>
287 explicit Extent(T
x, T y, T z) : Super(EigenVector(x, y, z)) {}
290 explicit Extent(T
const xyz[3]) : Super(EigenVector(xyz[0], xyz[1], xyz[2])) {}
293 explicit Extent(std::tuple<T, T, T>
const &xyz)
300 template <
typename T>
301 template <
typename U>
303 static_assert((!std::is_same<T, U>::value && std::is_integral<U>::value),
304 "can only construct from Extent of different but integral type");
305 this->setX(static_cast<T>(other.getX()));
306 this->setY(static_cast<T>(other.getY()));
309 template <
typename T>
310 template <
typename U>
312 static_assert((!std::is_same<T, U>::value && std::is_integral<U>::value),
313 "can only construct from Extent of different but integral type");
314 this->setX(static_cast<T>(other.getX()));
315 this->setY(static_cast<T>(other.getY()));
319 template <
typename T>
320 template <
typename U>
322 static_assert((!std::is_same<T, U>::value && std::is_integral<U>::value),
323 "can only construct from Extent of different but integral type");
324 this->setX(static_cast<T>(other.getX()));
325 this->setY(static_cast<T>(other.getY()));
326 this->setZ(static_cast<T>(other.getZ()));
330 template <
typename T>
331 template <
typename U>
333 static_assert((!std::is_same<T, U>::value && std::is_integral<U>::value),
334 "can only construct from Extent of different but integral type");
335 this->setX(static_cast<T>(other.getX()));
336 this->setY(static_cast<T>(other.getY()));
337 this->setZ(static_cast<T>(other.getZ()));
375 template <
typename T,
int N>
388 static_assert(N < 0,
"In-place multiplication of Extent<int,N> by double would truncate.");
399 static_assert(N < 0,
"In-place division of Extent<int,N> by double would truncate.");
Extent< T, N > & operator+=(Extent< T, N > const &other)
Extent< int, N > truncate(Extent< double, N > const &input)
Return the component-wise truncation (round towards zero).
Extent(std::tuple< T, T > const &xy)
Construct from std::tuple.
CoordinateExpr< N > ge(T scalar) const
Extent(std::pair< T, T > const &xy)
Construct from a std::pair.
A coordinate class intended to represent absolute positions (2-d specialization). ...
Extent(T x, T y)
Construct from two scalars.
Extent< T, N > operator*(T scalar) const
Extent(T val=static_cast< T >(0))
Construct an Extent with all elements set to the same scalar value.
bool all(CoordinateExpr< N > const &expr)
Return true if all elements are true.
CoordinateExpr< N > ne(T scalar) const
Extent(T const xy[2])
Construct from a two-element array.
CoordinateExpr< N > lt(T scalar) const
Extent< double, 2 > Extent2D
CoordinateExpr< N > eq(T scalar) const
Super::EigenVector EigenVector
Extent(EigenVector const &vector)
Construct an Extent from an Eigen vector.
Extent(std::tuple< T, T, T > const &xyz)
Construct from std::tuple.
void operator/=(ExtentBase< int, N > &lhs, double rhs)
bool operator==(Extent< T, N > const &other) const
Standard equality comparison.
A coordinate class intended to represent offsets and dimensions.
Extent(T const xyz[3])
Construct from a two-element array.
Extent< int, N > ceil(Extent< double, N > const &input)
Return the component-wise ceil (round towards more positive).
Super::EigenVector EigenVector
Extent< T, N > operator+() const
T computeNorm() const
Return the L2 norm of the Extent (sqrt(x^2 + y^2 + ...)).
T computeSquaredNorm() const
Return the squared L2 norm of the Extent (x^2 + y^2 + ...).
Extent< int, 2 > Extent2I
std::string toString() const
constexpr Angle operator+(Angle a, Angle d) noexcept
Sum of two angles.
CoordinateExpr< N > le(T scalar) const
Extent< double, 2 > ExtentD
A CRTP base class for coordinate objects.
A coordinate class intended to represent absolute positions.
T computeSquaredNorm() const
Return the squared L2 norm of the Extent (x^2 + y^2 + ...).
Extent< T, N > operator/(T scalar) const
Extent< int, N > floor(Extent< double, N > const &input)
Return the component-wise floor (round towards more negative).
bool any(CoordinateExpr< N > const &expr)
Return true if any elements are true.
EigenVector const & asEigen() const
Return a fixed-size Eigen representation of the coordinate object.
constexpr Angle operator/(Angle a, int d) noexcept
Ratio of an angle and a scalar.
void operator*=(ExtentBase< int, N > &lhs, double rhs)
A base class for image defects.
T computeNorm() const
Return the L2 norm of the Extent (sqrt(x^2 + y^2 + ...)).
Extent< T, N > & operator*=(T scalar)
Extent< T, N > & operator/=(T scalar)
double computeExtentNorm(Extent< double, N > const &s)
Extent(EigenVector const &vector)
Construct an Extent from an Eigen vector.
Eigen::Matrix< int, N, 1, Eigen::DontAlign > EigenVector
ExtentBase(Eigen::MatrixBase< Vector > const &vector)
Construct an Extent from an Eigen vector.
Extent< double, N > & operator+=(Extent< double, N > &lhs, Extent< int, N > const &rhs)
Extent< double, 3 > Extent3D
CoordinateExpr< N > gt(T scalar) const
Extent< T, N > operator-(Extent< T, N > const &other) const
Super::EigenVector EigenVector
constexpr Angle operator*(Angle a, Angle d) noexcept
Product of two angles.
constexpr Angle operator-(Angle a, Angle d) noexcept
Difference of two angles.
bool operator!=(Extent< T, N > const &other) const
Standard inequality comparison.
Extent(T x, T y, T z)
Construct from three scalars.
Extent< int, 3 > Extent3I
Extent< T, N > operator-() const
Extent< double, N > & operator-=(Extent< double, N > &lhs, Extent< int, N > const &rhs)
ExtentBase(T val=static_cast< T >(0))
Construct an Extent<T,N> with all elements set to the same scalar value.
Extent(T val=static_cast< T >(0))
Construct an Extent with all elements set to the same scalar value.
Extent< T, N > & operator-=(Extent< T, N > const &other)
Extent(EigenVector const &vector)
Construct an Extent from an Eigen vector.
Extent< T, N > operator+(Extent< T, N > const &other) const
Extent(T val=static_cast< T >(0))
Construct an Extent with all elements set to the same scalar value.
A coordinate class intended to represent absolute positions (3-d specialization). ...