move all the Game.Exts junk either down into FileFormats or into WorldUtils

This commit is contained in:
Chris Forbes
2011-03-12 19:33:16 +13:00
parent f4494d67b2
commit 1e3f365cf2
6 changed files with 55 additions and 78 deletions

View File

@@ -105,6 +105,42 @@ namespace OpenRA
public static bool Contains(this RectangleF r, int2 p)
{
return r.Contains(p.ToPointF());
}
}
public static bool HasModifier(this Modifiers k, Modifiers mod)
{
return (k & mod) == mod;
}
public static V GetOrAdd<K, V>(this Dictionary<K, V> d, K k)
where V : new()
{
return d.GetOrAdd(k, _ => new V());
}
public static V GetOrAdd<K, V>(this Dictionary<K, V> d, K k, Func<K, V> createFn)
{
V ret;
if (!d.TryGetValue(k, out ret))
d.Add(k, ret = createFn(k));
return ret;
}
public static T Random<T>(this IEnumerable<T> ts, Thirdparty.Random r)
{
var xs = ts.ToArray();
return xs[r.Next(xs.Length)];
}
public static float Product(this IEnumerable<float> xs)
{
return xs.Aggregate(1f, (a, x) => a * x);
}
public static IEnumerable<T> SymmetricDifference<T>(this IEnumerable<T> xs, IEnumerable<T> ys)
{
// this is probably a shockingly-slow way to do this, but it's concise.
return xs.Except(ys).Concat(ys.Except(xs));
}
}
}