diff --git a/OpenRA.FileFormats/WRange.cs b/OpenRA.FileFormats/WRange.cs index 003e2d308a..fbcaa0eeed 100644 --- a/OpenRA.FileFormats/WRange.cs +++ b/OpenRA.FileFormats/WRange.cs @@ -10,6 +10,7 @@ using System; using System.Drawing; +using System.Linq; namespace OpenRA { @@ -34,6 +35,17 @@ namespace OpenRA public static bool operator ==(WRange me, WRange other) { return (me.Range == other.Range); } public static bool operator !=(WRange me, WRange other) { return !(me == other); } + // Sampled a N-sample probability density function in the range [-1024..1024] + // 1 sample produces a rectangular probability + // 2 samples produces a triangular probability + // ... + // N samples approximates a true gaussian + public static WRange FromPDF(Thirdparty.Random r, int samples) + { + return new WRange(Exts.MakeArray(samples, _ => r.Next(-1024, 1024)) + .Sum() / samples); + } + public static bool TryParse(string s, out WRange result) { s = s.ToLowerInvariant(); diff --git a/OpenRA.FileFormats/WVec.cs b/OpenRA.FileFormats/WVec.cs index 72b2df78b9..4039374384 100644 --- a/OpenRA.FileFormats/WVec.cs +++ b/OpenRA.FileFormats/WVec.cs @@ -69,6 +69,16 @@ namespace OpenRA return new WVec(ret.X, ret.Y, ret.Z + offset); } + // Sampled a N-sample probability density function in the range [-1024..1024, -1024..1024] + // 1 sample produces a rectangular probability + // 2 samples produces a triangular probability + // ... + // N samples approximates a true gaussian + public static WVec FromPDF(Thirdparty.Random r, int samples) + { + return new WVec(WRange.FromPDF(r, samples), WRange.FromPDF(r, samples), WRange.Zero); + } + public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode(); } public override bool Equals(object obj)