Initial size handling
This commit is contained in:
parent
e028ad1a41
commit
b2c393d23a
28 changed files with 543 additions and 135 deletions
39
Math/public/Range.hpp
Normal file
39
Math/public/Range.hpp
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "Common.hpp"
|
||||
|
||||
namespace tp {
|
||||
template <typename Type>
|
||||
class Range {
|
||||
public:
|
||||
Range() = default;
|
||||
Range(Type v1, Type v2) : start(v1), end(v2) {}
|
||||
|
||||
Type mid() const { return (start + end) / 2.f; }
|
||||
Type size() const { return (end - start); }
|
||||
|
||||
void resizeFromCenter(Type newSize) {
|
||||
const auto middle = mid();
|
||||
const auto len = newSize / 2;
|
||||
start = middle - len;
|
||||
end = middle + len;
|
||||
}
|
||||
|
||||
void clamp(const Range& inside, const Range& outside) {
|
||||
start = tp::clamp(start, outside.start, inside.start);
|
||||
end = tp::clamp(end, inside.end, outside.end);
|
||||
}
|
||||
|
||||
void clamp(const Range& outside) {
|
||||
start = tp::clamp(start, outside.start, outside.end);
|
||||
end = tp::clamp(end, outside.start, outside.end);
|
||||
}
|
||||
|
||||
public:
|
||||
Type start{};
|
||||
Type end{};
|
||||
};
|
||||
|
||||
using RangeF = Range<halnf>;
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "Vec.hpp"
|
||||
#include "Range.hpp"
|
||||
|
||||
#include "Intersections.hpp"
|
||||
|
||||
|
|
@ -35,6 +36,11 @@ namespace tp {
|
|||
this->size = size;
|
||||
}
|
||||
|
||||
Rect(const Range<Type>& rx, const Range<Type>& ry) {
|
||||
this->pos = { rx.start, ry.start };
|
||||
this->size = { rx.size(), ry.size() };
|
||||
}
|
||||
|
||||
Rect(Type aPosX, Type posy, Type aSizeX, Type aSizeY) {
|
||||
pos.assign(aPosX, posy);
|
||||
size.assign(aSizeX, aSizeY);
|
||||
|
|
@ -64,7 +70,7 @@ namespace tp {
|
|||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(Rect<Type>& rect) const { return (pos == rect.pos && size == rect.size); }
|
||||
bool operator==(const Rect<Type>& rect) const { return (pos == rect.pos && size == rect.size); }
|
||||
|
||||
bool isEnclosedIn(const Rect<Type>& rect, bool aParent = false) const {
|
||||
if (aParent) {
|
||||
|
|
@ -102,6 +108,11 @@ namespace tp {
|
|||
|
||||
void invertY(Type scr_y) { pos.y = scr_y - pos.y - size.y; }
|
||||
|
||||
Rect& move(Vec2<Type> delta) {
|
||||
move(delta.x, delta.y);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void move(Type dx, Type dy) {
|
||||
pos.x += dx;
|
||||
pos.y += dy;
|
||||
|
|
@ -119,6 +130,9 @@ namespace tp {
|
|||
return *this;
|
||||
}
|
||||
|
||||
Range<Type> getRangeX() const { return { x, x + z }; }
|
||||
Range<Type> getRangeY() const { return { y, y + w }; }
|
||||
|
||||
// pos
|
||||
Vec2<Type> p1() const { return pos; }
|
||||
|
||||
|
|
|
|||
|
|
@ -226,8 +226,8 @@ namespace tp {
|
|||
Type y;
|
||||
|
||||
Vec() :
|
||||
x(0),
|
||||
y(0) {}
|
||||
x{},
|
||||
y{} {}
|
||||
|
||||
// Initialization
|
||||
template <typename TypeIn>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue