Faro Engine 0.0.0.b519570 (main)
Loading...
Searching...
No Matches
Rect.hpp
Go to the documentation of this file.
1#pragma once
2#include "../Containers/String.hpp"
3#include "Vector2.hpp"
4
5namespace Faro
6{
7 template <class T>
8 struct IRect
9 {
10 union
11 {
13#pragma warning(suppress: 4201)
15#pragma warning(suppress: 4201)
16 struct { T x1, y1, x2, y2; };
17 };
18
19 IRect() : x1(0), y1(0), x2(0), y2(0) { }
20
21 IRect(T x, T y, T w, T h) : x1(x), y1(y), x2(x + w), y2(y + h) {}
22
24
25 T Area() const { Vector2<T> size = Size(); return size.x * size.y; }
26
27 Vector2<T> Size() const { return bottomRight - topLeft; }
28
30 {
31 return topLeft + Size() / 2;
32 }
33
34 bool operator==(const IRect& other) const
35 {
36 return topLeft == other.topLeft && bottomRight == other.bottomRight;
37 }
38
39 bool operator!=(const Vector2<T>& other) const
40 {
41 return topLeft != other.topLeft || bottomRight != other.bottomRight;
42 }
43
44 IRect Lerp(const IRect& r, float fact) const { return IRect(topLeft.Lerp(r.topLeft, fact), Size().Lerp(r.Size()), fact); }
45
47 {
48 return "(x: " + Faro::ToString<T>(x1) + ", y: " + Faro::ToString<T>(y1) + ", w: " + Faro::ToString<T>(x2 - x1) + ", h: " + Faro::ToString<T>(y2 - y1) + ")";
49 }
50
51 template<class N>
53 {
54 return IRect<N>((N)x1, (N)y1, (N)(x2 - x1), (N)(y2 - y1));
55 }
56 };
57
60}
Definition String.hpp:12
Definition Array.hpp:8
IRect< float > FloatRect
Definition Rect.hpp:58
IRect< int32 > IntRect
Definition Rect.hpp:59
Definition Rect.hpp:9
T y1
Definition Rect.hpp:16
Vector2< T > points[2]
Definition Rect.hpp:12
T x2
Definition Rect.hpp:16
T x1
Definition Rect.hpp:16
Vector2< T > Center()
Definition Rect.hpp:29
T y2
Definition Rect.hpp:16
IRect(Vector2< T > topLeft, Vector2< T > extend)
Definition Rect.hpp:23
IRect< N > ToType()
Definition Rect.hpp:52
Vector2< T > bottomRight
Definition Rect.hpp:14
T Area() const
Definition Rect.hpp:25
Vector2< T > topLeft
Definition Rect.hpp:14
bool operator!=(const Vector2< T > &other) const
Definition Rect.hpp:39
IRect()
Definition Rect.hpp:19
String ToString()
Definition Rect.hpp:46
Vector2< T > Size() const
Definition Rect.hpp:27
IRect Lerp(const IRect &r, float fact) const
Definition Rect.hpp:44
IRect(T x, T y, T w, T h)
Definition Rect.hpp:21
bool operator==(const IRect &other) const
Definition Rect.hpp:34
Definition Vector2.hpp:9
T x
Definition Vector2.hpp:14
T y
Definition Vector2.hpp:14