partial ConnectedComponents labeler; fixes bugs in Evaluator

This commit is contained in:
Chris Forbes
2010-03-15 19:14:55 +13:00
parent f18028e309
commit 024f10cfbd
3 changed files with 42 additions and 5 deletions

View 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;
}
}
}

View File

@@ -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)
{

View File

@@ -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" />