diff --git a/include/Components/Misc.hpp b/include/Components/Misc.hpp index e950940..88bb38c 100644 --- a/include/Components/Misc.hpp +++ b/include/Components/Misc.hpp @@ -24,21 +24,16 @@ struct Bounds { Vector2 Min; Vector2 Max; + + bool HasPoint(int x, int y) const { return x >= Min.X && x < Max.X && y >= Min.Y && y < Max.Y; } + Bounds Grow(int32_t amount) const { + return Bounds{ + Vector2{Min.X - amount, Min.Y - amount}, + Vector2{Max.X + amount, Max.Y + amount} + }; + } }; -inline bool BoundsHasPoint(const Bounds& b, int x, int y) -{ - return x >= b.Min.X && x < b.Max.X && y >= b.Min.Y && y < b.Max.Y; -} - -inline Bounds BoundsGrow(const Bounds& b, int32_t amount) -{ - return Bounds{ - Vector2{b.Min.X - amount, b.Min.Y - amount}, - Vector2{b.Max.X + amount, b.Max.Y + amount} - }; -} - struct Level { Level() = default; diff --git a/include/Types/WorldGraph/WorldGraphNode.h b/include/Types/WorldGraph/WorldGraphNode.h index 88c391f..668099c 100644 --- a/include/Types/WorldGraph/WorldGraphNode.h +++ b/include/Types/WorldGraph/WorldGraphNode.h @@ -54,7 +54,7 @@ struct WorldNodeParameters Tile GetTile(int x, int y) const { auto bounds = GetGenerationBounds(); - if (!BoundsHasPoint(bounds, x, y)) + if (!bounds.HasPoint(x, y)) return {}; return (*GeneratedTiles)[(y - bounds.Min.Y) * PaddedChunkSide + (x - bounds.Min.X)]; } @@ -66,7 +66,7 @@ struct WorldNodeParameters Bounds GetGenerationBounds() const { - return BoundsGrow(ChunkInfo.GetBounds(), MaxQueryOffset); + return ChunkInfo.GetBounds().Grow(MaxQueryOffset); } }; @@ -326,7 +326,7 @@ private: public: virtual NodeValue Evaluate(const WorldNodeParameters& params) const override { - if (!BoundsHasPoint(params.ChunkInfo.GetBounds(), params.X, params.Y)) + if (!params.ChunkInfo.GetBounds().HasPoint(params.X, params.Y)) return NodeValue(16384.f); int maxRangeSQ = 16384;