partial ConnectedComponents labeler; fixes bugs in Evaluator
This commit is contained in:
36
OpenRA.FileFormats/ConnectedComponents.cs
Normal file
36
OpenRA.FileFormats/ConnectedComponents.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenRA.FileFormats
|
||||
{
|
||||
public static class ConnectedComponents
|
||||
{
|
||||
static readonly int2[] Neighbors
|
||||
= { new int2(-1, -1), new int2(0, -1), new int2(1, -1), new int2(-1, 0) };
|
||||
|
||||
public static int[,] Extract(Map m, Func<int, int, int> f)
|
||||
{
|
||||
var result = new int[m.MapSize, m.MapSize];
|
||||
var types = new int[m.MapSize, m.MapSize];
|
||||
var d = new Dictionary<int,int>();
|
||||
var n = 1;
|
||||
|
||||
for( var j = m.YOffset; j < m.YOffset + m.Height; j++ )
|
||||
for (var i = m.XOffset; i < m.XOffset + m.Width; i++)
|
||||
{
|
||||
types[i, j] = f(i, j);
|
||||
|
||||
var k = n;
|
||||
foreach (var a in Neighbors)
|
||||
if (types[i + a.X, j + a.Y] == types[i, j] && result[i + a.X, j + a.Y] < k)
|
||||
k = result[i + a.X, j + a.Y];
|
||||
|
||||
// todo: finish this
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,10 +22,10 @@ namespace OpenRA.FileFormats
|
||||
{
|
||||
switch (t[0])
|
||||
{
|
||||
case '+': ApplyBinop(s, (x, y) => x + y); break;
|
||||
case '-': ApplyBinop(s, (x, y) => x - y); break;
|
||||
case '*': ApplyBinop(s, (x, y) => x * y); break;
|
||||
case '/': ApplyBinop(s, (x, y) => x / y); break;
|
||||
case '+': ApplyBinop(s, (x, y) => y + x); break;
|
||||
case '-': ApplyBinop(s, (x, y) => y - x); break;
|
||||
case '*': ApplyBinop(s, (x, y) => y * x); break;
|
||||
case '/': ApplyBinop(s, (x, y) => y / x); break;
|
||||
default: s.Push(int.Parse(t)); break;
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,7 @@ namespace OpenRA.FileFormats
|
||||
}
|
||||
|
||||
static readonly Dictionary<string, int> Prec
|
||||
= new Dictionary<string, int> { { "+", 0 }, { "-", 0 }, { "*", 1 }, { "/", 1 } };
|
||||
= new Dictionary<string, int> { { "+", 0 }, { "-", 0 }, { "*", 1 }, { "/", 1 }, { "(", -1 } };
|
||||
|
||||
static IEnumerable<string> Tokens(string expr, string ops)
|
||||
{
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
<Compile Include="BlowfishKeyProvider.cs" />
|
||||
<Compile Include="Cache.cs" />
|
||||
<Compile Include="Collections\Set.cs" />
|
||||
<Compile Include="ConnectedComponents.cs" />
|
||||
<Compile Include="DisposableAction.cs" />
|
||||
<Compile Include="Dune2ShpReader.cs" />
|
||||
<Compile Include="Evaluator.cs" />
|
||||
|
||||
Reference in New Issue
Block a user