using Arch.Core;
using TheLivingWorld.Core.Ecs;
using TheLivingWorld.Core.Geo;
using TheLivingWorld.Core.Worlds;
namespace TheLivingWorld.Core.Systems;
/// Fills every feature's cached world-space extent from the geometry it points at.
public sealed class ComputeBoundsSystem : IWorldSystem
{
private static readonly QueryDescription AreaFeatures = new QueryDescription().WithAll();
private static readonly QueryDescription LineFeatures = new QueryDescription().WithAll();
public string Name => nameof(ComputeBoundsSystem);
public void Execute(GameWorld world)
{
var shapes = world.Shapes;
// Holes are contained by their outline, so the outline alone determines the extent.
world.Ecs.Query(in AreaFeatures, (ref Outline outline, ref Bounds bounds) =>
{
bounds.Value = RectBounds.FromPoints(shapes.Get(outline.ShapeId));
});
world.Ecs.Query(in LineFeatures, (ref Polyline line, ref Bounds bounds) =>
{
bounds.Value = RectBounds.FromPoints(shapes.Get(line.ShapeId));
});
}
}