-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rectangle.hpp
56 lines (50 loc) · 1.88 KB
/
Rectangle.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once
#include <plugin/math/vec2.hpp>
#include <iostream>
namespace plugin::physics::bump
{
class Collision;
struct IntersectionIndicie
{
float ti1=0;
float ti2=1;
math::vec2 normalA;
math::vec2 normalB;
};
class Rectangle
{
public:
Rectangle(math::vec2 pos, math::vec2 scale){
this->pos = pos;
this->scale = scale;
};
Rectangle(float x, float y, float w, float h)
{
this->pos = math::vec2(x,y);
this->scale = math::vec2(w,h);
}
Rectangle(){
this->pos = math::vec2(0,0);
this->scale = math::vec2(0,0);
}
bool ContainsPoint(math::vec2 point) const;
bool IsIntersecting(const Rectangle& other) const;
float GetSquareDistance(const Rectangle& other) const;
math::vec2 GetNearestCorner(const math::vec2& other) const;
Rectangle GetDifference(const Rectangle& other) const;
bool GetSegmentIntersectionIndices(math::vec2 top, math::vec2 bottom, IntersectionIndicie& indicie) const;
bool DetectCollision(const Rectangle& other, Collision* collision) const
{return DetectCollision(other, collision, pos);}
bool DetectCollision(const Rectangle& other,Collision* collision, math::vec2 goal) const;
bool compare(const Rectangle& rhs){return (pos == rhs.pos and pos == rhs.scale);}
inline bool operator==(const Rectangle& rhs){ return compare(rhs); }
inline bool operator!=(const Rectangle& rhs){ return not compare(rhs); }
inline friend std::ostream& operator<<(std::ostream& out, const Rectangle& rect) {
out << "Rectangle(" << rect.pos.x << "," << rect.pos.y << "," << rect.scale.x << "," << rect.scale.y << ")";
return out;
}
public:
math::vec2 pos;
math::vec2 scale;
};
}