-
Notifications
You must be signed in to change notification settings - Fork 513
Rectangle
A 2D rectangle class modeled after the XNA Game Studio math library
For Universal Windows Platform and Xbox One, similar functionality is provided by the Windows::Foundation::Rect Windows Runtime structure
#include <SimpleMath.h>
using namespace DirectX::SimpleMath;
Rectangle r; // Creates an empty rectangle [0, 0, 0, 0]
Rectangle r(10, 20, 100, 200); // Creates a rectangle with upper-left [10,20], 100 width, and 200 height
For Windows desktop apps, you may find that
Rectangle
conflicts with the GDI function of the same name. You can resolve this three ways: Use#define NOGDI
before you include<windows.h>
; useSimpleMath::Rectangle
, or in local scope useusing Rectangle = SimpleMath::Rectangle;
.
- x location of the upper-left corner
- y location of the upper-left corner
- width of the rectangle
- height of the rectangle
-
Comparison operators:
==
and!=
-
Assignment operator:
=
-
Location, Center: Returns the rectangle position as a Vector2
-
IsEmpty: Returns true if the rectangle is [0, 0, 0, 0]
-
Contains: Tests to see if a point or rectangle is contained by the rectangle
-
Inflate: Grows the rectangle by a specified amount in the horizontal and vertical dimensions
-
Intersects: Tests to see if another rectangle intersects with this rectangle
-
Offset: Moves or offsets the rectangle by moving the upper-left position
-
Intersect: Computes the intersection of two rectangles or the empty rectangle [0, 0, 0, 0] if there is no intersection
-
Union: Computes the union of two rectangles
Rectangle will freely convert to and from a RECT
. In UWP and Xbox One apps, you can also convert it to a Windows::Foundation::Rect
.
All content and source code for this package are subject to the terms of the MIT License.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
- Universal Windows Platform apps
- Windows desktop apps
- Windows 11
- Windows 10
- Windows 8.1
- Xbox One
- x86
- x64
- ARM64
- Visual Studio 2022
- Visual Studio 2019 (16.11)
- clang/LLVM v12 - v18
- MinGW 12.2, 13.2
- CMake 3.20