Kale
Loading...
Searching...
No Matches
src
Kale
Math
RotatedRect
RotatedRect.cpp
Go to the documentation of this file.
1
/*
2
Copyright 2022 Rishi Challa
3
4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7
8
http://www.apache.org/licenses/LICENSE-2.0
9
10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16
17
#include "
RotatedRect.hpp
"
18
19
#include <
Kale/Math/Rect/Rect.hpp
>
20
#include <
Kale/Math/Ray/Ray.hpp
>
21
#include <
Kale/Math/Line/Line.hpp
>
22
#include <
Kale/Math/Circle/Circle.hpp
>
23
24
#include <stdexcept>
25
26
using namespace
Kale
;
27
31
RotatedRect::RotatedRect
() : point1(0, 0), point2(0, 0), point3(0, 0), point4(0, 0) {
32
// Empty Body
33
}
34
42
RotatedRect::RotatedRect
(
const
Vector2f
&point1,
const
Vector2f
&point2,
const
Vector2f
&point3,
const
Vector2f
&point4) :
43
point1(point1), point2(point2), point3(point3), point4(point4) {
44
// Empty Body
45
}
46
52
RotatedRect::RotatedRect
(
const
Vector2f
&point1,
const
Vector2f
&point3) : point1(point1), point2(point3.x, point1.y), point3(point3), point4(point1.x, point3.y) {
53
// Empty Body
54
}
55
60
Vector2f
RotatedRect::center
()
const
{
61
return
(
point1
+
point3
) / 2;
62
}
63
68
Rect
RotatedRect::getBoundingBox
()
const
{
69
return
{
70
{std::min({
point1
.
x
,
point2
.
x
,
point3
.
x
,
point4
.
x
}), std::max({
point1
.
y
,
point2
.
y
,
point3
.
y
,
point4
.
y
})},
71
{std::max({
point1
.
x
,
point2
.
x
,
point3
.
x
,
point4
.
x
}), std::min({
point1
.
y
,
point2
.
y
,
point3
.
y
,
point4
.
y
})}
72
};
73
}
74
80
bool
RotatedRect::pointCollision
(
Vector2f
point)
const
{
81
return
(
point1
-
point2
).dot(point -
point2
) > 0.0f &&
82
(
point3
-
point4
).dot(point -
point4
) > 0.0f &&
83
(
point1
-
point4
).dot(point -
point4
) > 0.0f &&
84
(
point3
-
point2
).dot(point -
point2
) > 0.0f;
85
}
86
92
bool
RotatedRect::rectCollision
(
RotatedRect
rect)
const
{
93
return
(
point2
-
point1
).dot(rect.
point3
-
point1
) > 0.0f &&
94
(
point4
-
point1
).dot(rect.
point3
-
point1
) > 0.0f &&
95
(rect.
point2
- rect.
point1
).dot(
point3
- rect.
point1
) > 0.0f &&
96
(rect.
point4
- rect.
point1
).dot(
point3
- rect.
point1
) > 0.0f;
97
}
98
104
bool
RotatedRect::rectCollision
(
Rect
rect)
const
{
105
return
rectCollision
(
RotatedRect
{rect.
topLeft
, rect.
bottomRight
});
106
}
107
113
bool
RotatedRect::circleCollision
(
Circle
circle)
const
{
114
return
circle.
rectCollision
(*
this
);
115
}
116
122
bool
RotatedRect::rayCollision
(
Ray
ray)
const
{
123
return
ray.
rectCollision
(*
this
);
124
}
125
131
bool
RotatedRect::lineCollision
(
Line
line)
const
{
132
return
line.
rectCollision
(*
this
);
133
}
Circle.hpp
Line.hpp
Ray.hpp
Rect.hpp
RotatedRect.hpp
Kale::Vector2< float >
Kale::Vector2::y
T y
Definition
Vector.hpp:43
Kale::Vector2::x
T x
Definition
Vector.hpp:43
Kale
Definition
Application.hpp:38
Kale::Circle
Definition
Circle.hpp:26
Kale::Circle::rectCollision
bool rectCollision(RotatedRect rect) const override
Definition
Circle.cpp:67
Kale::Line
Definition
Line.hpp:26
Kale::Line::rectCollision
bool rectCollision(RotatedRect rect) const override
Definition
Line.cpp:117
Kale::Ray
Definition
Ray.hpp:28
Kale::Ray::rectCollision
bool rectCollision(RotatedRect rect) const override
Definition
Ray.cpp:138
Kale::Rect
Definition
Rect.hpp:26
Kale::Rect::bottomRight
Vector2f bottomRight
Definition
Rect.hpp:36
Kale::Rect::topLeft
Vector2f topLeft
Definition
Rect.hpp:31
Kale::RotatedRect
Definition
RotatedRect.hpp:26
Kale::RotatedRect::circleCollision
bool circleCollision(Circle circle) const override
Definition
RotatedRect.cpp:113
Kale::RotatedRect::RotatedRect
RotatedRect()
Definition
RotatedRect.cpp:31
Kale::RotatedRect::pointCollision
bool pointCollision(Vector2f point) const override
Definition
RotatedRect.cpp:80
Kale::RotatedRect::center
Vector2f center() const
Definition
RotatedRect.cpp:60
Kale::RotatedRect::rayCollision
bool rayCollision(Ray ray) const override
Definition
RotatedRect.cpp:122
Kale::RotatedRect::point1
Vector2f point1
Definition
RotatedRect.hpp:31
Kale::RotatedRect::getBoundingBox
Rect getBoundingBox() const override
Definition
RotatedRect.cpp:68
Kale::RotatedRect::lineCollision
bool lineCollision(Line line) const override
Definition
RotatedRect.cpp:131
Kale::RotatedRect::rectCollision
bool rectCollision(RotatedRect rect) const override
Definition
RotatedRect.cpp:92
Kale::RotatedRect::point2
Vector2f point2
Definition
RotatedRect.hpp:36
Kale::RotatedRect::point3
Vector2f point3
Definition
RotatedRect.hpp:41
Kale::RotatedRect::point4
Vector2f point4
Definition
RotatedRect.hpp:46
Generated on Tue Mar 12 2024 00:05:56 for Kale by
1.10.0