#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2021 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_PIXELS_RECTANGLE_H #define NUCLEX_PIXELS_RECTANGLE_H #include "Nuclex/Pixels/Config.h" #include // for std::size_t namespace Nuclex { namespace Pixels { // ------------------------------------------------------------------------------------------- // /// 2D rectangle using pixel coordinates struct NUCLEX_PIXELS_TYPE Rectangle { /// Constructs a new rectangle from a minimum and maximum point /// X coordinate of the rectangle's left side /// Y coordinate of the rectangle's lower side /// X coordinate of the rectangle's right side /// Y coordinate of the rectangle's upper side /// /// /// As a convention, the maximum (far) point is exclusive. Pixels in which /// one or both coordinates match with the maximum coordinates specified here /// are considered to be outside of the rectangle (i.e. a rectange (0,0)-(0,0) /// is empty and contains nothing, while (0,0)-(1,1) contains exactly one pixel). /// /// /// This library does not make any assumptions about whether you Y-axis is /// counting upwards or downwards, but documentation will treat the Y-axis as /// extending towards the top (the upside-down Y-axis common in 2D graphics /// is an artifact of ancient computer/TV design). /// /// public: NUCLEX_PIXELS_API static Rectangle FromMinAndMax( std::size_t minX, std::size_t minY, std::size_t maxX, std::size_t maxY ) { return Rectangle(minX, minY, maxX, maxY); } /// Constructs a new rectangle from a position and a size /// X coordinate of the rectangle's minor corner /// Y coordinate of the rectangle's minor corner /// Total width of the rectangle /// Total height of the rectangle public: NUCLEX_PIXELS_API static Rectangle FromPositionAndSize( std::size_t x, std::size_t y, std::size_t width, std::size_t height ) { return Rectangle(x, y, x + width, y + height); } /// Initializes a new rectangle size /// Width of the rectangle in pixels /// Height of the rectangle in pixels public: NUCLEX_PIXELS_API Rectangle( std::size_t minX, std::size_t minY, std::size_t maxX, std::size_t maxY ) : MinX(minX), MinY(minY), MaxX(maxX), MaxY(maxY) {} /// X coordinate of the rectangle's left side public: std::size_t MinX; /// X coordinate of the rectangle's lower side public: std::size_t MinY; /// Y coordinate of the rectangle's right side public: std::size_t MaxX; /// Y coordinate of the rectangle's upper side public: std::size_t MaxY; }; // ------------------------------------------------------------------------------------------- // }} // namespace Nuclex::Pixels #endif // NUCLEX_PIXELS_SIZE_H