Positions and Bounds

template<class T>
class Position

Class for storing 2d position vectors in an (x, y) format.

Public Functions

inline Position()

Default Constructor = (0,0)

inline Position(const T xin, const T yin)

Constructor.

inline Position(const Position<T> &rhs)

Copy Constructor.

template<typename T2>
inline Position(const Position<T2> &rhs)
inline Position &operator=(const Position<T> &rhs)

Assignment.

template<typename T2>
inline Position &operator=(const Position<T2> &rhs)
template<typename T2>
inline Position<typename SelfPromotion<T, T2>::type> &operator+=(const Position<T2> &rhs)

Overloaded += operator, following standard vector algebra rules.

template<typename T2>
inline Position<typename SelfPromotion<T, T2>::type> &operator-=(const Position<T2> &rhs)

Overloaded -= operator, following standard vector algebra rules.

inline Position<T> &operator*=(const T rhs)

Overloaded *= operator for scalar multiplication.

inline Position<T> &operator/=(const T rhs)

Overloaded /= operator for scalar division.

inline Position<T> operator*(const T rhs) const

Overloaded * operator for scalar on rhs.

inline Position<T> operator/(const T rhs) const

Overloaded / operator for scalar on rhs.

inline Position<T> operator-() const

Unary negation (x, y) -> (-x, -y).

template<typename T2>
inline Position<typename Promotion<T, T2>::type> operator+(const Position<T2> &rhs) const

Overloaded vector + addition operator with a Position on the rhs.

template<typename T2>
inline Position<typename Promotion<T, T2>::type> operator-(const Position<T2> &rhs) const

Overloaded vector - subtraction operator with a Position on the rhs.

inline bool operator==(const Position<T> &rhs) const

Overloaded == relational equality operator.

inline bool operator!=(const Position<T> &rhs) const

Overloaded != relational non-equality operator.

inline void write(std::ostream &fout) const

Write (x, y) position to output stream.

inline void read(std::istream &fin)

Read (x, y) position from input istream.

Public Members

T x

Publicly visible x & y attributes of the position.

T y

Friends

inline friend Position<T> operator*(const T lhs, const Position<T> &rhs)

Allow T * Position as well.

template<class T>
class Bounds

Class for storing image bounds, essentially the vertices of a rectangle.

This is used to keep track of the bounds of catalogs and fields. You can set values, but generally you just keep including positions of each galaxy or the bounds of each catalog respectively using the += operators.

The bounds are stored as four numbers in each instance, (xmin, ymin, xmax, ymax), with an additional boolean switch to say whether or not the Bounds rectangle has been defined.

Rectangle is undefined if min>max in either direction.

Public Functions

inline Bounds(const T x1, const T x2, const T y1, const T y2)

Constructor using four scalar positions (xmin, xmax, ymin, ymax).

inline Bounds(const Position<T> &pos)

Constructor using a single Position vector x/ymin = x/ymax.

inline Bounds(const Position<T> &pos1, const Position<T> &pos2)

Constructor using two Positions, first for x/ymin, second for x/ymax.

inline Bounds()

Constructor for empty Bounds, .isDefined() method will return false.

inline ~Bounds()

Destructor.

inline Bounds<T> copy() const

Make a copy of this Bounds object.

inline void setXMin(const T x)

Set the xmin of the Bounds rectangle.

inline void setXMax(const T x)

Set the xmax of the Bounds rectangle.

inline void setYMin(const T y)

Set the ymin of the Bounds rectangle.

inline void setYMax(const T y)

Set the ymax of the Bounds rectangle.

inline T getXMin() const

Get the xmin of the Bounds rectangle.

inline T getXMax() const

Get the xmax of the Bounds rectangle.

inline T getYMin() const

Get the ymin of the Bounds rectangle.

inline T getYMax() const

Get the ymax of the Bounds rectangle.

inline bool isDefined() const

Query whether the Bounds rectangle is defined.

inline Position<T> origin() const

Return the origin of the image (xmin, ymin)

Position<T> center() const

Return the nominal center of the image.

This is the position of the pixel that is considered to be (0,0)

Position<double> trueCenter() const

Return the true center of the image.

For even-sized, integer bounds, this will not be an integer, since the center in that case falls between two pixels.

void operator+=(const Position<T> &pos)

expand bounds to include this point

inline Bounds<T> operator+(const Position<T> &pos) const
void operator+=(const Bounds<T> &rec)

expand bounds to include these bounds

inline Bounds<T> operator+(const Bounds<T> &rec) const
void addBorder(const T d)

add a border of size d around existing bounds

inline void operator+=(const T d)
inline Bounds<T> withBorder(const T d) const
inline Bounds<T> operator+(const T d) const
void expand(const double m)

expand bounds by a factor m around the current center.

inline Bounds<T> makeExpanded(const double m) const
const Bounds<T> operator&(const Bounds<T> &rhs) const

find the intersection of two bounds

inline void shift(const T dx, const T dy)

shift the bounding box by some amount.

inline void shift(const Position<T> &delta)
inline Bounds<T> makeShifted(const T dx, const T dy) const
inline Bounds<T> makeShifted(const Position<T> &delta) const
template<typename T2>
inline bool includes(const Position<T2> &pos) const

return whether the bounded region includes a given point

template<typename T2>
inline bool includes(const T2 x, const T2 y) const
inline bool includes(const Bounds<T> &rhs) const

return whether the bounded region includes all of the given bounds

inline bool operator==(const Bounds<T> &rhs) const

check equality of two bounds

inline bool operator!=(const Bounds<T> &rhs) const
inline bool isSameShapeAs(const Bounds<T> &rhs) const

Check if two bounds have same shape, but maybe different origin.

inline T area() const

Return the area of the enclosed region.

The area is a bit different for integer-type Bounds and float-type bounds. For floating point types, it is simply (xmax-xmin)*(ymax-ymin). However, for integer type, we need to add 1 to each size to correctly count the number of pixels being described by the bounding box.

std::vector<Bounds<T>> divide(int nx, int ny) const

divide the current bounds into (nx x ny) sub-regions

inline void write(std::ostream &fout) const

write out to a file

inline void read(std::istream &fin)

read in from a file

.