Clementine
Rect2.h
1 // Copyright 2021 SMS
2 // License(Apache-2.0)
3 
4 #pragma once
5 
6 #include "Vector2.h"
7 
16 class Rect2
17 {
18 public:
19  Vector2 origin;
20  Size2 size;
21 
25  Rect2() = default;
26 
33  Rect2(const Point2& origin, const Size2& size);
34 
43  Rect2(float x, float y, float width, float height);
44 
48  float top() const;
49 
53  float bottom() const;
54 
58  float left() const;
59 
63  float right() const;
64 
68  Point2 tl() const;
69 
73  Point2 tr() const;
74 
78  Point2 bl() const;
79 
83  Point2 br() const;
84 
91  bool intersectsPoint(const Point2& point) const;
92 
99  bool intersectsRect(const Rect2& rect) const;
100 
101  bool intersectsX(float x) const;
102 
103  bool intersectsY(float y) const;
104 
105  bool isValid() const;
106 };
107 
Point2 br() const
获取右下角坐标.
Definition: Rect2.cpp:51
二维矩形, 单精度.
Definition: Rect2.h:16
Rect2()=default
默认构造函数.
bool intersectsPoint(const Point2 &point) const
检测是否与二维点发生相交.
Definition: Rect2.cpp:56
float top() const
获取上边的 y 坐标.
Definition: Rect2.cpp:16
Point2 tl() const
获取左上角坐标.
Definition: Rect2.cpp:36
float bottom() const
获取下底的 y 坐标.
Definition: Rect2.cpp:21
二维向量, 单精度浮点数.
Definition: Vector2.h:19
float right() const
获取右边的 x 坐标.
Definition: Rect2.cpp:31
Point2 bl() const
获取左下角坐标.
Definition: Rect2.cpp:46
float left() const
获取左边的 x 坐标.
Definition: Rect2.cpp:26
Point2 tr() const
获取右上角坐标.
Definition: Rect2.cpp:41
bool intersectsRect(const Rect2 &rect) const
检测是否与二维矩形发生相交.
Definition: Rect2.cpp:61