WOWCube Docs logo
WOWCube Docs
Mission Control
Section Shortcuts
APIExamplesSourceWOWConnectChangelog
Filters
SDK and language defaults persist in cookies.
SDK version
Navigation Tree
Collapsed by default, focused on the active path.
Made byMcKay Seamons
GitHub
  1. Home
  2. Docs
  3. Source
  4. Rect2.h
Mission NodeSDK 6.3C++math

Rect2.h

SDK Source File: Rect2.h

Source / SDK 6.3 / C++ / math

Rect2.h

Rect2.h
CPP
1/* Copyright Statement:
2 *
3 * (C) 2021-2025 Cubios Inc. All rights reserved.
4 */
5#ifndef WASMLIBS_CPP_RECT2_H_
6#define WASMLIBS_CPP_RECT2_H_
7
8#include "Vec2.h"
9
10namespace Cubios
11{
12namespace Math
13{
14class Rect2
15{
16public:
17 /// default constructor
18 Rect2();
19 Rect2(const Vec2i& topLeft, const Vec2i& bottomRight);
20 Rect2(int16_t x, int16_t y, int16_t width, int16_t height);
21
22 void Set(const Vec2i& topLeft, const Vec2i& bottomRight);
23
24 bool IsInside(const Vec2i& p) const;
25
26 Vec2i Midpoint() const;
27
28 Vec2i v0;
29 Vec2i v1;
30 int16_t W;
31 int16_t H;
32};
33
34inline Rect2::Rect2():W(0),H(0)
35{
36}
37
38inline Rect2::Rect2(const Vec2i& topLeft, const Vec2i& bottomRight) :
39 v0(topLeft),
40 v1(bottomRight)
41{
42 this->W = this->v1.X - this->v0.X;
43 this->H = this->v1.Y - this->v0.Y;
44}
45
46inline Rect2::Rect2(int16_t x, int16_t y, int16_t width, int16_t height):
47 v0(x,y),
48 v1(x+width, y+height),W(width),H(height)
49{
50}
51
52inline void Rect2::Set(const Vec2i& topLeft, const Vec2i& bottomRight)
53{
54 this->v0 = topLeft;
55 this->v1 = bottomRight;
56
57 this->W = this->v1.X - this->v0.X;
58 this->H = this->v1.Y - this->v0.Y;
59}
60
61inline bool Rect2::IsInside(const Vec2i& p) const
62{
63 return ((this->v0.X <= p.X) && (p.X <= this->v1.X) &&
64 (this->v0.Y <= p.Y) && (p.Y <= this->v1.Y));
65}
66
67inline Vec2i Rect2::Midpoint() const
68{
69 return (this->v0 + this->v1) * 0.5f;
70}
71
72}
73}
74#endif /* WASMLIBS_CPP_RECT2_H_ */
75
76
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.
Context Rail

Related nodes

Color.h
Source / SDK 6.3 / C++ / math
Math.h
Source / SDK 6.3 / C++ / math
Transform.h
Source / SDK 6.3 / C++ / math
Vec2.h
Source / SDK 6.3 / C++ / math
Previous Node
Math.h
Source / SDK 6.3 / C++ / math
Next Node
Transform.h
Source / SDK 6.3 / C++ / math