bounds improvements
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user