#include "rays/bounds.h" namespace Rays { Bounds::Bounds (coord size) { set(size); } Bounds::Bounds (coord width, coord height, coord depth) { set(width, height, depth); } Bounds::Bounds (coord x, coord y, coord width, coord height) { set(x, y, width, height); } Bounds::Bounds ( coord x, coord y, coord z, coord width, coord height, coord depth) { set(x, y, z, width, height, depth); } Bounds Bounds::dup () const { return *this; } Bounds& Bounds::set (coord size) { return set(size, size, 0); } Bounds& Bounds::set (coord width, coord height, coord depth) { this->x = this->y = this->z = 0; this->width = width; this->height = height; this->depth = depth; return *this; } Bounds& Bounds::set (coord x, coord y, coord width, coord height) { return set(x, y, 0, width, height, 0); } Bounds& Bounds::set (coord x, coord y, coord z, coord width, coord height, coord depth) { this->x = x; this->y = y; this->z = z; this->width = width; this->height = height; this->depth = depth; return *this; } bool Bounds::get (coord* x, coord* y, coord* width, coord* height) const { return get(x, y, NULL, width, height, NULL); } bool Bounds::get ( coord* x, coord* y, coord* z, coord* width, coord* height, coord* depth) const { if (!x && !y && !z && !width && !height && !depth) return false; if (x) *x = this->x; if (y) *y = this->y; if (z) *z = this->z; if (width) *width = this->width; if (height) *height = this->height; if (depth) *depth = this->depth; return true; } void Bounds::set_left (coord left) { width -= left - x; x = left; } coord Bounds::left () const { return x; } void Bounds::set_right (coord right) { width = right - x + 1; } coord Bounds::right () const { return x + width - 1; } void Bounds::set_top (coord top) { height -= top - y; y = top; } coord Bounds::top () const { return y; } void Bounds::set_bottom (coord bottom) { height = bottom - y + 1; } coord Bounds::bottom () const { return y + height - 1; } void Bounds::set_back (coord back) { depth -= back - z; z = back; } coord Bounds::back () const { return z; } void Bounds::set_front (coord front) { depth = front - z + 1; } coord Bounds::front () const { return z + depth - 1; } Point& Bounds::position () { return ((Point*) this)[0]; } const Point& Bounds::position () const { return const_cast(this)->position(); } Point& Bounds::size () { return ((Point*) this)[1]; } const Point& Bounds::size () const { return const_cast(this)->size(); } coord* Bounds::array () { return (coord*) this; } const coord* Bounds::array () const { return const_cast(this)->array(); } Bounds::operator bool () const { return width >= 0 && height >= 0 && depth >= 0; } bool Bounds::operator ! () const { return !operator bool(); } bool operator == (const Bounds& lhs, const Bounds& rhs) { return lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z && lhs.width == rhs.width && lhs.height == rhs.height && lhs.depth == rhs.depth; } bool operator != (const Bounds& lhs, const Bounds& rhs) { return !operator==(lhs, rhs); } }// Rays