#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_RECTANGLE_H #define NUCLEX_GRAPHICS_RECTANGLE_H #include "Config.h" #include #include #undef min #undef max namespace Nuclex { namespace Graphics { // ------------------------------------------------------------------------------------------- // /// Integer rectangle in 2D space class Rectangle { /// An empty rectangle initialized to zero public: NUCLEX_GRAPHICS_API static const Rectangle Empty; /// Constructs an uninitialized rectangle public: Rectangle() {} /// Initializes a new rectangle to the specified coordinates /// X coordinate of the rectangle's left border /// Y coordinate of the rectangle's top border /// X coordinate of the rectangle's right border /// Y coordinate of the rectangle's bottom border public: Rectangle( std::size_t left, std::size_t top, std::size_t right, std::size_t bottom ) : Left(left), Top(top), Right(right), Bottom(bottom) {} /// Determines if the rectangle is not covering any space /// True if the rectangle has an area of zero public: bool IsEmpty() const { return (this->Left == this->Right) || (this->Top == this->Bottom); } /// Retrieves the rectangle's width /// The width of the rectangle public: std::size_t GetWidth() const { if(this->Left > this->Right) { return this->Left - this->Right; } else { return this->Right - this->Left; } } /// Retrieves the rectangle's height /// The height of the rectangle public: std::size_t GetHeight() const { if(this->Top > this->Bottom) { return this->Top - this->Bottom; } else { return this->Bottom - this->Top; } } /// Merges another rectangle into this rectangle /// Other rectangle that will be merged public: void Merge(const Rectangle &other) { this->Left = std::min(this->Left, other.Left); this->Top = std::min(this->Top, other.Top); this->Right = std::max(this->Right, other.Right); this->Bottom = std::max(this->Bottom, other.Bottom); } /// Resets the rectangle to empty public: void Reset() { this->Left = 0; this->Top = 0; this->Right = 0; this->Bottom = 0; } /// X coordinate of the rectangle's left border public: std::size_t Left; /// Y coordinate of the rectangle's top border public: std::size_t Top; /// X coordinate of the rectangle's right border public: std::size_t Right; /// Y coordinate of the rectangle's bottom border public: std::size_t Bottom; }; // ------------------------------------------------------------------------------------------- // }} // namespace Nuclex::Graphics #endif // NUCLEX_GRAPHICS_RECTANGLE_H