GigaPasjans
Loading...
Searching...
No Matches
Box.h
1// Wykonane przez Piotra ChudziƄskiego w dniu 11.04.2025
2#pragma once
3
4#include "Int2.h"
5
10struct Box
11{
12 const static Box Zero;
13
14 union
15 {
16 struct
17 {
18 int32 X, Y;
19 int32 Width, Height;
20 };
21
22 int32 Raw[4];
23 };
24
30 Int2 GetCenter() const { return {X + Width / 2, Y + Height / 2}; }
31
36 Int2 GetPosition() const { return {X, Y}; }
37
42 Int2 GetSize() const { return {Width, Height}; }
43
48 bool operator==(const Box &box) const
49 {
50 return box.X == X && box.Y == Y && box.Width == Width && box.Height == Height;
51 }
52
53 constexpr Box() : X(0), Y(0), Width(0), Height(0) {};
54
55 constexpr Box(int32 x, int32 y, int32 width, int32 height) : X(x), Y(y), Width(width), Height(height) {};
56
57 constexpr Box(Int2 position, Int2 size) : X(position.X), Y(position.Y), Width(size.X), Height(size.Y) {};
58
59 bool Intersects(const Int2 &ray) const
60 {
61 return ray.X >= X && ray.Y >= Y && ray.X <= X + Width && ray.Y <= Y + Height;
62 }
63};
Represents a rectangular area defined by a position and size, using signed 32-bit integers.
Definition Box.h:11
Int2 GetPosition() const
Gets the position (top-left corner) of the box.
Definition Box.h:36
Int2 GetCenter() const
Calculates and returns the center point of the box.
Definition Box.h:30
Int2 GetSize() const
Gets the size (width and height) of the box.
Definition Box.h:42
bool operator==(const Box &box) const
Compares this box with another for equality.
Definition Box.h:48
Represents a two component vector. Components are 32-bit and they are signed.
Definition Int2.h:11