#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2013 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_GRAPHICS_BOX_H #define NUCLEX_GRAPHICS_BOX_H #include "Config.h" #include #include #undef min #undef max namespace Nuclex { namespace Graphics { // ------------------------------------------------------------------------------------------- // /// Integer box in 3D space class Box { /// An empty box initialized to zero public: NUCLEX_GRAPHICS_API static const Box Empty; /// Constructs an uninitialized box public: Box() {} /// Initializes a new box to the specified coordinates /// X coordinate of the rectangle's left border /// Y coordinate of the rectangle's top border /// Z coordinate of the rectangle's far border /// X coordinate of the rectangle's right border /// Y coordinate of the rectangle's bottom border /// Z coordinate of the rectangle's near border public: Box( std::size_t left, std::size_t top, std::size_t back, std::size_t right, std::size_t bottom, std::size_t front ) : Left(left), Top(top), Back(back), Right(right), Bottom(bottom), Front(front) {} /// Determines if the box is not covering any space /// True if the box has an area of zero public: bool IsEmpty() const { return (this->Left == this->Right) || (this->Top == this->Bottom) || (this->Back == this->Front); } /// Retrieves the box' width /// The width of the box public: std::size_t GetWidth() const { if(this->Left > this->Right) { return this->Left - this->Right; } else { return this->Right - this->Left; } } /// Retrieves the box' height /// The height of the box public: std::size_t GetHeight() const { if(this->Top > this->Bottom) { return this->Top - this->Bottom; } else { return this->Bottom - this->Top; } } /// Retrieves the box' depth /// The depth of the box public: std::size_t GetDepth() const { if(this->Back > this->Front) { return this->Back - this->Front; } else { return this->Front - this->Back; } } /// Merges another box into this box /// Other box that will be merged public: void Merge(const Box &other) { this->Left = std::min(this->Left, other.Left); this->Top = std::min(this->Top, other.Top); this->Back = std::min(this->Back, other.Back); this->Right = std::max(this->Right, other.Right); this->Bottom = std::max(this->Bottom, other.Bottom); this->Front = std::max(this->Front, other.Front); } /// Resets the rectangle to empty public: void Reset() { this->Left = 0; this->Top = 0; this->Back = 0; this->Right = 0; this->Bottom = 0; this->Front = 0; } /// X coordinate of the box' left border public: std::size_t Left; /// Y coordinate of the box' top border public: std::size_t Top; /// Z coordinate of the box' far border public: std::size_t Back; /// X coordinate of the box' right border public: std::size_t Right; /// Y coordinate of the box' bottom border public: std::size_t Bottom; /// Z coordinate of the box' near border public: std::size_t Front; }; // ------------------------------------------------------------------------------------------- // }} // namespace Nuclex::Graphics #endif // NUCLEX_GRAPHICS_BOX_H