22 #ifndef ULTIMA8_MISC_BOX_H 23 #define ULTIMA8_MISC_BOX_H 25 #include "common/scummsys.h" 40 Box() : _x(0), _y(0), _z(0), _xd(0), _yd(0), _zd(0) {}
41 Box(
int nx,
int ny,
int nz,
int nxd,
int nyd,
int nzd)
42 : _x(nx), _y(ny), _z(nz), _xd(nxd), _yd(nyd), _zd(nzd) {}
45 bool isEmpty()
const {
46 return _xd <= 0 || _yd <= 0 || _zd <= 0;
50 bool isValid()
const {
51 return _xd >= 0 && _yd >= 0 && _zd >= 0;
55 bool contains(int32 px, int32 py, int32 pz)
const {
56 return px > _x - _xd && px <= _x &&
57 py > _y - _yd && py <= _y &&
58 pz >= _z && pz < _z + _zd;
62 bool containsXY(int32 px, int32 py)
const {
63 return px > _x - _xd && px <= _x &&
64 py > _y - _yd && py <= _y;
68 bool isBelow(int32 px, int32 py, int32 pz)
const {
69 return px > _x - _xd && px <= _x &&
70 py > _y - _yd && py <= _y &&
75 void translate(int32 dx, int32 dy, int32 dz) {
82 void moveTo(int32 nx, int32 ny, int32 nz) {
89 void resize(int32 nxd, int32 nyd, int32 nzd) {
95 bool overlaps(
const Box &o)
const {
96 if (_x <= o._x - o._xd || o._x <= _x - _xd)
98 if (_y <= o._y - o._yd || o._y <= _y - _yd)
100 if (_z + _zd <= o._z || o._z + o._zd <= _z)
105 bool overlapsXY(
const Box& o)
const {
106 if (_x <= o._x - o._xd || o._x <= _x - _xd)
108 if (_y <= o._y - o._yd || o._y <= _y - _yd)
113 void extend(
const Box &o) {
114 int32 x2 =
MIN(_x - _xd, o._x - o._xd);
115 int32 y2 =
MIN(_y - _yd, o._y - o._yd);
116 int32 z2 =
MAX(_z + _zd, o._z + o._zd);
126 bool operator==(
const Box &rhs)
const {
return equals(rhs); }
127 bool operator!=(
const Box &rhs)
const {
return !equals(rhs); }
129 bool equals(
const Box &o)
const {
130 return (_x == o._x && _y == o._y && _z == o._z &&
131 _xd == o._xd && _yd == o._yd && _zd == o._zd);
Definition: detection.h:27
T MIN(T a, T b)
Definition: util.h:59
T MAX(T a, T b)
Definition: util.h:62