Kale
Loading...
Searching...
No Matches
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
20#include <Kale/Math/Ray/Ray.hpp>
23
24#include <stdexcept>
25
26using namespace Kale;
27
31RotatedRect::RotatedRect() : point1(0, 0), point2(0, 0), point3(0, 0), point4(0, 0) {
32 // Empty Body
33}
34
42RotatedRect::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
52RotatedRect::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
61 return (point1 + point3) / 2;
62}
63
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
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
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
105 return rectCollision(RotatedRect{rect.topLeft, rect.bottomRight});
106}
107
114 return circle.rectCollision(*this);
115}
116
123 return ray.rectCollision(*this);
124}
125
132 return line.rectCollision(*this);
133}
bool rectCollision(RotatedRect rect) const override
Definition Circle.cpp:67
bool rectCollision(RotatedRect rect) const override
Definition Line.cpp:117
bool rectCollision(RotatedRect rect) const override
Definition Ray.cpp:138
Vector2f bottomRight
Definition Rect.hpp:36
Vector2f topLeft
Definition Rect.hpp:31
bool circleCollision(Circle circle) const override
bool pointCollision(Vector2f point) const override
Vector2f center() const
bool rayCollision(Ray ray) const override
Rect getBoundingBox() const override
bool lineCollision(Line line) const override
bool rectCollision(RotatedRect rect) const override