mirror of
https://github.com/jtgans/g13gui.git
synced 2025-06-20 08:23:50 -04:00
This is the first half of some major rework of the g13d codebase to make things a bit more manageable. This splits out a great deal of stuff from helper.h into separate translation units, and also breaks out a great deal of the g13.h header into separate translation units as well. Doing this saves in compilation time as we make changes to the system, and also helps to clean up a whole bunch of leaking symbols.
52 lines
896 B
C++
52 lines
896 B
C++
#ifndef BOUNDS_H
|
|
#define BOUNDS_H
|
|
|
|
#include <ostream>
|
|
|
|
#include "coord.h"
|
|
|
|
namespace G13 {
|
|
|
|
template <class T> class Bounds {
|
|
public:
|
|
Bounds(const Coord<T> &_tl, const Coord<T> &_br)
|
|
: tl(_tl), br(_br) {
|
|
}
|
|
|
|
Bounds(T x1, T y1, T x2, T y2) : tl(x1, y1), br(x2, y2) {
|
|
}
|
|
|
|
bool contains(const Coord<T> &pos) const {
|
|
return tl.x <= pos.x && tl.y <= pos.y && pos.x <= br.x && pos.y <= br.y;
|
|
}
|
|
|
|
void expand(const Coord<T> &pos) {
|
|
if (pos.x < tl.x)
|
|
tl.x = pos.x;
|
|
if (pos.y < tl.y)
|
|
tl.y = pos.y;
|
|
if (pos.x > br.x)
|
|
br.x = pos.x;
|
|
if (pos.y > br.y)
|
|
br.y = pos.y;
|
|
}
|
|
|
|
Coord<T> tl;
|
|
Coord<T> br;
|
|
};
|
|
|
|
template <class T>
|
|
std::ostream &operator<<(std::ostream &o, const Bounds<T> &b) {
|
|
o << "{ "
|
|
<< b.tl.x << " x " << b.tl.y
|
|
<< " / "
|
|
<< b.br.x << " x " << b.br.y
|
|
<< " }";
|
|
|
|
return o;
|
|
};
|
|
|
|
} // namespace G13
|
|
|
|
#endif // BOUNDS_H
|