private static Vector4[] CalculateHemispherePointsAndWeights() { Binner binner = new Binner(RasterDim, Binner.Mode.Midpoints); Vector4[] pointsAndWeights = new Vector4[RasterDim * RasterDim]; for (int row = 0; row < RasterDim; ++row) { for (int col = 0; col < RasterDim; ++col) { int idx = row * RasterDim + col; float x = binner.IdxToFloat(col) * 2 - 1; float y = -(binner.IdxToFloat(row) * 2 - 1); float zSquared = 1 - x * x - y * y; if (zSquared < 0) { pointsAndWeights[idx] = Vector4.Zero; } else { float z = (float)-Math.Sqrt(zSquared); pointsAndWeights[idx] = new Vector4(x, y, z, 1); } } } return(pointsAndWeights); }
public void TestEndpointsFloatToIdx() { Binner binner = new Binner(5, Binner.Mode.Endpoints); //Test endpoints Assert.AreEqual(0, binner.FloatToIdx(0)); Assert.AreEqual(4, binner.FloatToIdx(1)); //Test ranges Assert.AreEqual(0, binner.FloatToIdx(0 / 8f + Acc)); Assert.AreEqual(0, binner.FloatToIdx(1 / 8f - Acc)); Assert.AreEqual(1, binner.FloatToIdx(1 / 8f + Acc)); Assert.AreEqual(1, binner.FloatToIdx(2 / 8f)); Assert.AreEqual(1, binner.FloatToIdx(3 / 8f - Acc)); Assert.AreEqual(2, binner.FloatToIdx(3 / 8f + Acc)); Assert.AreEqual(2, binner.FloatToIdx(4 / 8f)); Assert.AreEqual(2, binner.FloatToIdx(5 / 8f - Acc)); Assert.AreEqual(3, binner.FloatToIdx(5 / 8f + Acc)); Assert.AreEqual(3, binner.FloatToIdx(6 / 8f)); Assert.AreEqual(3, binner.FloatToIdx(7 / 8f - Acc)); Assert.AreEqual(4, binner.FloatToIdx(7 / 8f + Acc)); Assert.AreEqual(4, binner.FloatToIdx(8 / 8f - Acc)); //Test beyond endpoints Assert.AreEqual(0, binner.FloatToIdx(-1)); Assert.AreEqual(4, binner.FloatToIdx(2)); }
public void TestMidpointsIdxToFloat() { Binner indexer = new Binner(4, Binner.Mode.Midpoints); Assert.AreEqual(1 / 8f, indexer.IdxToFloat(0), Acc); Assert.AreEqual(3 / 8f, indexer.IdxToFloat(1), Acc); Assert.AreEqual(5 / 8f, indexer.IdxToFloat(2), Acc); Assert.AreEqual(7 / 8f, indexer.IdxToFloat(3), Acc); }
public void TestEndpointsIdxToFloat() { Binner binner = new Binner(5, Binner.Mode.Endpoints); Assert.AreEqual(0, binner.IdxToFloat(0), Acc); Assert.AreEqual(0.25f, binner.IdxToFloat(1), Acc); Assert.AreEqual(0.5f, binner.IdxToFloat(2), Acc); Assert.AreEqual(0.75f, binner.IdxToFloat(3), Acc); Assert.AreEqual(1, binner.IdxToFloat(4), Acc); }
public void Test_UtcToThree() { IList <OHLCV> data = UtcOneMinute; Periods period = Periods.ThreeMinutes; TimeZoneInfo timeZone = TimeZoneInfo.Utc; var expected = UtcThreeMinute; var source = new Mock <ISourceSpecification>(); source.Setup(x => x.DataStartTime).Returns(new TimeSpan(0, 0, 0)); source.Setup(x => x.TimeZoneInfo).Returns(TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time")); var target = new Binner(source.Object); var actual = target.Bin(data, period, timeZone); Assert.IsTrue(actual.SequenceEqual(expected)); }
public void TestCount() { Binner indexer = new Binner(4, Binner.Mode.Midpoints); Assert.AreEqual(4, indexer.Count); }