Initial size handling

This commit is contained in:
IlyaShurupov 2024-10-10 11:17:03 +03:00 committed by Ilya Shurupov
parent 9f9dcd5882
commit 0b73f8037b
28 changed files with 543 additions and 135 deletions

View file

@ -88,18 +88,18 @@ void TopologyCache::updateCache() {
}
TransformedPoints.reserve(Source->Points.size());
for (auto idx : Range(TransformedPoints.size())) {
for (auto idx : IterRange(TransformedPoints.size())) {
TransformedPoints[idx] = Source->Basis.transform(Source->Points[idx]);
TransformedPoints[idx] += Source->Origin;
}
TransformedNormals.reserve(Source->Normals.size());
for (auto idx : Range(TransformedNormals.size())) {
for (auto idx : IterRange(TransformedNormals.size())) {
TransformedNormals[idx] = Source->Basis.transform(Source->Normals[idx]);
}
TrigCaches.reserve(Source->Indexes.size());
for (auto idx : Range(TrigCaches.size())) {
for (auto idx : IterRange(TrigCaches.size())) {
TrigCaches[idx].mP1 = Source->Indexes[idx].x;
TrigCaches[idx].mP2 = Source->Indexes[idx].y;
TrigCaches[idx].mP3 = Source->Indexes[idx].z;

39
Math/public/Range.hpp Normal file
View 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>;
}

View file

@ -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; }

View file

@ -226,8 +226,8 @@ namespace tp {
Type y;
Vec() :
x(0),
y(0) {}
x{},
y{} {}
// Initialization
template <typename TypeIn>