solve edge case
This commit is contained in:
parent
741d34a5e0
commit
0472bfe58e
15 changed files with 685 additions and 47 deletions
|
|
@ -5,29 +5,26 @@ using StitchATon2.Infra.Buffers;
|
|||
|
||||
namespace StitchATon2.Domain;
|
||||
|
||||
public sealed class TileManager : IDisposable
|
||||
public sealed class TileManager
|
||||
{
|
||||
private readonly IMemoryOwner<Tile> _tiles;
|
||||
private readonly Tile[] _tiles;
|
||||
|
||||
public Configuration Configuration { get; }
|
||||
|
||||
public TileManager(Configuration config)
|
||||
{
|
||||
Configuration = config;
|
||||
_tiles = MemoryAllocator.AllocateManaged<Tile>(config.TileCount);
|
||||
var tilesSpan = _tiles.Memory.Span;
|
||||
_tiles = new Tile[Configuration.TileCount];
|
||||
for (var id = 0; id < config.TileCount; id++)
|
||||
tilesSpan[id] = CreateTile(id);
|
||||
_tiles[id] = CreateTile(id);
|
||||
|
||||
Console.WriteLine("Tile manager created");
|
||||
}
|
||||
|
||||
~TileManager() => Dispose();
|
||||
|
||||
private Tile CreateTile(int id)
|
||||
{
|
||||
var (row, column) = int.DivRem(id, Configuration.Columns);
|
||||
var coordinate = $"{Utils.GetSBSNotation(++row)}{++column}";
|
||||
var coordinate = $"{Utils.GetSBSNotationRow(++row)}{++column}";
|
||||
return new Tile
|
||||
{
|
||||
Id = id,
|
||||
|
|
@ -47,7 +44,7 @@ public sealed class TileManager : IDisposable
|
|||
private int GetId(int column, int row) => column - 1 + (row - 1) * Configuration.Columns;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Tile GetTile(int id) => _tiles.Memory.Span[id];
|
||||
public Tile GetTile(int id) => _tiles[id];
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Tile GetTile(int column, int row) => GetTile(GetId(column, row));
|
||||
|
|
@ -99,10 +96,4 @@ public sealed class TileManager : IDisposable
|
|||
cropY,
|
||||
cropWidth,
|
||||
cropHeight);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_tiles.Dispose();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue