35 #ifndef NAV_CORE2_BOUNDS_H 36 #define NAV_CORE2_BOUNDS_H 51 template <
typename NumericType>
52 inline bool inRange(
const NumericType value,
const NumericType min_value,
const NumericType max_value)
54 return min_value <= value && value <= max_value;
61 template <
typename NumericType>
80 GenericBounds(NumericType x0, NumericType y0, NumericType x1, NumericType y1)
88 min_x_ =
min_y_ = std::numeric_limits<NumericType>::max();
89 max_x_ =
max_y_ = std::numeric_limits<NumericType>::lowest();
95 void touch(NumericType x, NumericType y)
110 void update(NumericType x0, NumericType y0, NumericType x1, NumericType y1)
174 return "(" + std::to_string(
min_x_) +
"," + std::to_string(
min_y_) +
"):(" +
175 std::to_string(
max_x_) +
"," + std::to_string(
max_y_) +
")";
179 return "(empty bounds)";
194 inline unsigned int getDimension(
unsigned int min_v,
unsigned int max_v)
196 return (min_v > max_v) ? 0 : max_v - min_v + 1;
209 #endif // NAV_CORE2_BOUNDS_H std::string toString() const
Returns a string representation of the bounds.
GenericBounds(NumericType x0, NumericType y0, NumericType x1, NumericType y1)
Constructor for a non-empty initial bounds.
GenericBounds()
Constructor for an empty bounds.
NumericType getMinX() const
bool operator==(const GenericBounds< NumericType > &other) const
comparison operator that requires all fields are equal
bool operator!=(const GenericBounds< NumericType > &other) const
unsigned int getWidth() const
unsigned int getHeight() const
NumericType getMaxX() const
NumericType getMaxY() const
void reset()
Reset the bounds to be empty.
unsigned int getDimension(unsigned int min_v, unsigned int max_v)
void touch(NumericType x, NumericType y)
Update the bounds to include the point (x, y)
void update(NumericType x0, NumericType y0, NumericType x1, NumericType y1)
Update the bounds to include points (x0, y0) and (x1, y1)
bool inRange(const NumericType value, const NumericType min_value, const NumericType max_value)
Templatized method for checking if a value falls inside a one-dimensional range.
NumericType getMinY() const
void merge(const GenericBounds< NumericType > &other)
Update the bounds to include the entirety of another bounds object.
Templatized class that represents a two dimensional bounds with ranges [min_x, max_x] [min_y...
bool isEmpty() const
Returns true if the range is empty.
bool contains(NumericType x, NumericType y) const
Returns true if the point is inside this range.
bool overlaps(const GenericBounds< NumericType > &other) const
returns true if the two bounds overlap each other