bounds improvements

This commit is contained in:
Connor
2026-02-21 09:45:30 +09:00
parent 88e33be91b
commit 6a57e689ac
2 changed files with 11 additions and 16 deletions

View File

@@ -24,21 +24,16 @@ struct Bounds
{ {
Vector2 Min; Vector2 Min;
Vector2 Max; 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 struct Level
{ {
Level() = default; Level() = default;

View File

@@ -54,7 +54,7 @@ struct WorldNodeParameters
Tile GetTile(int x, int y) const Tile GetTile(int x, int y) const
{ {
auto bounds = GetGenerationBounds(); auto bounds = GetGenerationBounds();
if (!BoundsHasPoint(bounds, x, y)) if (!bounds.HasPoint(x, y))
return {}; return {};
return (*GeneratedTiles)[(y - bounds.Min.Y) * PaddedChunkSide + (x - bounds.Min.X)]; return (*GeneratedTiles)[(y - bounds.Min.Y) * PaddedChunkSide + (x - bounds.Min.X)];
} }
@@ -66,7 +66,7 @@ struct WorldNodeParameters
Bounds GetGenerationBounds() const Bounds GetGenerationBounds() const
{ {
return BoundsGrow(ChunkInfo.GetBounds(), MaxQueryOffset); return ChunkInfo.GetBounds().Grow(MaxQueryOffset);
} }
}; };
@@ -326,7 +326,7 @@ private:
public: public:
virtual NodeValue Evaluate(const WorldNodeParameters& params) const override 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); return NodeValue(16384.f);
int maxRangeSQ = 16384; int maxRangeSQ = 16384;