mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2025-02-20 15:14:26 +01:00
Added expand_to to Rect2.
This commit is contained in:
parent
f50f52e593
commit
e74549776f
@ -83,6 +83,33 @@ void Rect2::shrink(const float by) {
|
|||||||
w -= by;
|
w -= by;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Taken from the Godot Engine (MIT License)
|
||||||
|
//Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.
|
||||||
|
//Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md).
|
||||||
|
void Rect2::expand_to(const Vector2 &p_vector) {
|
||||||
|
Vector2 begin = Vector2(x, y);
|
||||||
|
Vector2 end = Vector2(x, y) + Vector2(w, h);
|
||||||
|
|
||||||
|
if (p_vector.x < begin.x) {
|
||||||
|
begin.x = p_vector.x;
|
||||||
|
}
|
||||||
|
if (p_vector.y < begin.y) {
|
||||||
|
begin.y = p_vector.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p_vector.x > end.x) {
|
||||||
|
end.x = p_vector.x;
|
||||||
|
}
|
||||||
|
if (p_vector.y > end.y) {
|
||||||
|
end.y = p_vector.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
x = begin.x;
|
||||||
|
y = begin.y;
|
||||||
|
w = end.x - begin.x;
|
||||||
|
h = end.y - begin.y;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef SDL_AVAILABLE
|
#ifdef SDL_AVAILABLE
|
||||||
SDL_Rect Rect2::as_rect() const {
|
SDL_Rect Rect2::as_rect() const {
|
||||||
SDL_Rect r;
|
SDL_Rect r;
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "vector2.h"
|
||||||
|
|
||||||
class Rect2 {
|
class Rect2 {
|
||||||
public:
|
public:
|
||||||
float get_area() const;
|
float get_area() const;
|
||||||
@ -18,6 +20,8 @@ public:
|
|||||||
void grow(const float by);
|
void grow(const float by);
|
||||||
void shrink(const float by);
|
void shrink(const float by);
|
||||||
|
|
||||||
|
void expand_to(const Vector2 &p_vector);
|
||||||
|
|
||||||
#ifdef SDL_AVAILABLE
|
#ifdef SDL_AVAILABLE
|
||||||
SDL_Rect as_rect() const;
|
SDL_Rect as_rect() const;
|
||||||
SDL_FRect as_frect() const;
|
SDL_FRect as_frect() const;
|
||||||
|
Loading…
Reference in New Issue
Block a user