forked from OpenRA/OpenRA
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
154 changed files
with
2,079 additions
and
1,178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#region Copyright & License Information | ||
/* | ||
* Copyright (c) The OpenRA Developers and Contributors | ||
* This file is part of OpenRA, which is free software. It is made | ||
* available to you under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation, either version 3 of | ||
* the License, or (at your option) any later version. For more | ||
* information, see COPYING. | ||
*/ | ||
#endregion | ||
|
||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
namespace OpenRA | ||
{ | ||
public readonly struct CellCoordsRegion : IEnumerable<CPos> | ||
{ | ||
public struct CellCoordsEnumerator : IEnumerator<CPos> | ||
{ | ||
readonly CellCoordsRegion r; | ||
|
||
public CellCoordsEnumerator(CellCoordsRegion region) | ||
: this() | ||
{ | ||
r = region; | ||
Reset(); | ||
} | ||
|
||
public bool MoveNext() | ||
{ | ||
var x = Current.X + 1; | ||
var y = Current.Y; | ||
|
||
// Check for column overflow. | ||
if (x > r.BottomRight.X) | ||
{ | ||
y++; | ||
x = r.TopLeft.X; | ||
|
||
// Check for row overflow. | ||
if (y > r.BottomRight.Y) | ||
return false; | ||
} | ||
|
||
Current = new CPos(x, y); | ||
return true; | ||
} | ||
|
||
public void Reset() | ||
{ | ||
Current = new CPos(r.TopLeft.X - 1, r.TopLeft.Y); | ||
} | ||
|
||
public CPos Current { get; private set; } | ||
|
||
readonly object IEnumerator.Current => Current; | ||
public readonly void Dispose() { } | ||
} | ||
|
||
public CellCoordsRegion(CPos topLeft, CPos bottomRight) | ||
{ | ||
TopLeft = topLeft; | ||
BottomRight = bottomRight; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return $"{TopLeft}->{BottomRight}"; | ||
} | ||
|
||
public CellCoordsEnumerator GetEnumerator() | ||
{ | ||
return new CellCoordsEnumerator(this); | ||
} | ||
|
||
IEnumerator<CPos> IEnumerable<CPos>.GetEnumerator() | ||
{ | ||
return GetEnumerator(); | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
return GetEnumerator(); | ||
} | ||
|
||
public CPos TopLeft { get; } | ||
public CPos BottomRight { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.