Skip to content

Commit

Permalink
Add LocalTilesIntersecting for circles (#5262)
Browse files Browse the repository at this point in the history
* Add LocalTilesIntersecting for circles

* Update Robust.Shared/GameObjects/Systems/SharedMapSystem.Grid.cs

Co-authored-by: Tayrtahn <[email protected]>

---------

Co-authored-by: Tayrtahn <[email protected]>
  • Loading branch information
metalgearsloth and Tayrtahn authored Jun 29, 2024
1 parent 2c6fb95 commit a0c069f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Robust.Shared/GameObjects/Systems/SharedMapSystem.Grid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,26 @@ public IEnumerable<TileRef> GetTilesIntersecting(EntityUid uid, MapGridComponent
}
}

public IEnumerable<TileRef> GetLocalTilesIntersecting(EntityUid uid, MapGridComponent grid, Circle localCircle, bool ignoreEmpty = true,
Predicate<TileRef>? predicate = null)
{
var aabb = new Box2(localCircle.Position.X - localCircle.Radius, localCircle.Position.Y - localCircle.Radius,
localCircle.Position.X + localCircle.Radius, localCircle.Position.Y + localCircle.Radius);

var tileEnumerator = GetLocalTilesEnumerator(uid, grid, aabb, ignoreEmpty, predicate);

while (tileEnumerator.MoveNext(out var tile))
{
var tileCenter = tile.GridIndices + grid.TileSizeHalfVector;
var direction = tileCenter - localCircle.Position;

if (direction.IsShorterThanOrEqualTo(localCircle.Radius))
{
yield return tile;
}
}
}

public IEnumerable<TileRef> GetTilesIntersecting(EntityUid uid, MapGridComponent grid, Circle worldArea, bool ignoreEmpty = true,
Predicate<TileRef>? predicate = null)
{
Expand Down

0 comments on commit a0c069f

Please sign in to comment.