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>
158 std::stringstream out;
160 for (
size_t i = 0; i < N; ++i) {
175 template <
typename Vector>
186 template <
typename T,
int N>
187 class Extent :
public ExtentBase<T, N> {
188 typedef ExtentBase<T, N> Super;
203 template <
typename U>
205 template <
typename U>
222 template <
typename T>
239 template <
typename U>
241 template <
typename U>
264 template <
typename T>
281 template <
typename U>
283 template <
typename U>
293 explicit Extent(std::tuple<T, T, T>
const &xyz)
294 :
Super(
EigenVector(std::get<0>(xyz), std::get<1>(xyz), std::get<2>(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()));
340 typedef Extent<int, 2>
ExtentI;
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.
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 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 > gt(T scalar) const
Extent(T const xy[2])
Construct from a two-element array.
Extent< double, 2 > Extent2D
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)
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/(T scalar) const
Extent< int, 2 > Extent2I
constexpr Angle operator+(Angle a, Angle d) noexcept
Sum of two angles.
CoordinateExpr< N > gt(Extent< T, N > const &other) const
bool operator!=(Extent< T, N > const &other) const
Standard inequality comparison.
Extent< double, 2 > ExtentD
A CRTP base class for coordinate objects.
A coordinate class intended to represent absolute positions.
Extent< T, N > operator-() 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.
constexpr Angle operator/(Angle a, int d) noexcept
Ratio of an angle and a scalar.
void operator*=(ExtentBase< int, N > &lhs, double rhs)
T computeSquaredNorm() const
Return the squared L2 norm of the Extent (x^2 + y^2 + ...).
Extent< T, N > & operator*=(T scalar)
Extent< T, N > & operator/=(T scalar)
CoordinateExpr< N > lt(Extent< T, N > const &other) const
T computeSquaredNorm() const
Return the squared L2 norm of the Extent (x^2 + y^2 + ...).
double computeExtentNorm(Extent< double, N > const &s)
T computeNorm() const
Return the L2 norm of the Extent (sqrt(x^2 + y^2 + ...)).
Extent(EigenVector const &vector)
Construct an Extent from an Eigen vector.
std::string toString() const
CoordinateExpr< N > ge(T scalar) const
Eigen::Matrix< int, N, 1, Eigen::DontAlign > EigenVector
bool operator==(Extent< T, N > const &other) const
Standard equality comparison.
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)
void _swap(CoordinateBase &other)
Extent< double, 3 > Extent3D
CoordinateExpr< N > eq(T scalar) const
Extent< T, N > operator-(Extent< T, N > const &other) const
Super::EigenVector EigenVector
Point< T, N > asPoint() const
Cast this object to an Extent of the same numeric type and dimensionality.
CoordinateExpr< N > le(Extent< T, N > const &other) const
constexpr Angle operator*(Angle a, Angle d) noexcept
Product of two angles.
EigenVector const & asEigen() const
Return a fixed-size Eigen representation of the coordinate object.
constexpr Angle operator-(Angle a, Angle d) noexcept
Difference of two angles.
Extent< T, N > operator*(T scalar) const
CoordinateExpr< N > ne(T scalar) const
Extent(T x, T y, T z)
Construct from three scalars.
CoordinateExpr< N > ge(Extent< T, N > const &other) const
CoordinateExpr< N > lt(T scalar) const
Extent< T, N > operator+(Extent< T, N > const &other) const
Extent< int, 3 > Extent3I
CoordinateExpr< N > le(T scalar) const
CoordinateExpr< N > eq(Extent< T, N > const &other) const
Extent< double, N > & operator-=(Extent< double, N > &lhs, Extent< int, N > const &rhs)
T computeNorm() const
Return the L2 norm of the Extent (sqrt(x^2 + y^2 + ...)).
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< T, N > operator+() const
Extent(EigenVector const &vector)
Construct an Extent from an Eigen vector.
CoordinateExpr< N > ne(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). ...