88 lines
1.9 KiB
C#
88 lines
1.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Unity.Mathematics;
|
|
|
|
namespace DanieleMarotta.RiversongCodeShowcase
|
|
{
|
|
public struct TileRange : IEnumerable<int2>
|
|
{
|
|
public int2 Min;
|
|
|
|
public int2 Max;
|
|
|
|
private TileRange(int2 min, int2 max)
|
|
{
|
|
Min = min;
|
|
Max = max;
|
|
}
|
|
|
|
public static TileRange From(in TileRect rect)
|
|
{
|
|
return new TileRange(rect.Min, rect.Max);
|
|
}
|
|
|
|
public static TileRange From(int2 min, int2 max)
|
|
{
|
|
return From(new TileRect(min, max));
|
|
}
|
|
|
|
public Enumerator GetEnumerator()
|
|
{
|
|
return new Enumerator(Min, Max);
|
|
}
|
|
|
|
IEnumerator<int2> IEnumerable<int2>.GetEnumerator()
|
|
{
|
|
return GetEnumerator();
|
|
}
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
{
|
|
return GetEnumerator();
|
|
}
|
|
|
|
public struct Enumerator : IEnumerator<int2>
|
|
{
|
|
public int2 Min;
|
|
|
|
public int2 Max;
|
|
|
|
public int2 Current { get; private set; }
|
|
|
|
object IEnumerator.Current => Current;
|
|
|
|
public Enumerator(int2 min, int2 max) : this()
|
|
{
|
|
Min = min;
|
|
Max = max;
|
|
Reset();
|
|
}
|
|
|
|
public bool MoveNext()
|
|
{
|
|
if (Current.x < Max.x)
|
|
{
|
|
Current = new int2(Current.x + 1, Current.y);
|
|
return true;
|
|
}
|
|
|
|
if (Current.y < Max.y)
|
|
{
|
|
Current = new int2(Min.x, Current.y + 1);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
Current = new int2(Min.x - 1, Min.y);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
}
|
|
}
|
|
} |