public void Test_GenericLeafSubGridTests_CellHasValue() { // Note: By definition, base generic cell has value behaviour is to assume the value exists var generic = new GenericLeafSubGrid <bool>(); SubGridUtilities.SubGridDimensionalIterator((x, y) => generic.CellHasValue((byte)x, (byte)y).Should().Be(true)); }
public void Test_GenericLeafSubGridTests_ForEach_FunctionDelegate() { var generic = new GenericLeafSubGrid <bool>(null, null, SubGridTreeConsts.SubGridTreeLevels); // All bools in generic are false.. // Iterate until completion... uint count = 0; generic.ForEach(b => { if (!b) { count++; } return(true); }); count.Should().Be(SubGridTreeConsts.CellsPerSubGrid); // Terminate iteration after first element count = 0; generic.ForEach(b => { if (!b) { count++; } return(false); }); count.Should().Be(1); }
/// <summary> /// Accept a sub grid response from the processing engine and incorporate into the result for the request. /// </summary> /// <param name="response"></param> /// <returns></returns> public override bool TransferResponse(object response) { // Log.InfoFormat("Received a SubGrid to be processed: {0}", (response as IClientLeafSubGrid).Moniker()); var result = false; if (base.TransferResponse(response)) { if (!(response is IClientLeafSubGrid[] subGridResponses) || subGridResponses.Length == 0) { Log.LogWarning("No sub grid responses returned"); } else { // Convert the ClientHeightLeafSubGrid into a GenericLeafSubGrid<float>... foreach (var subGrid in subGridResponses) { if (subGrid != null) { var originSubGrid = (ClientHeightLeafSubGrid)subGrid; var leaf = new GenericLeafSubGrid <float> { OriginX = originSubGrid.OriginX, OriginY = originSubGrid.OriginY, Items = originSubGrid.Clone2DArray(), Level = originSubGrid.Level }; SurfaceSubgrids.Add(leaf); } } result = true; } }
/// <summary> /// Implements convolution over a sub grid tree in <T> /// </summary> /// <param name="leaf"></param> /// <param name="smoothedLeaf"></param> /// <param name="convolver"></param> public override void Convolve(GenericLeafSubGrid <T> leaf, GenericLeafSubGrid <T> smoothedLeaf, IConvolver <T> convolver) { var context = new ConvolutionSubGridContext <GenericLeafSubGrid <T>, T>(leaf, convolver.Accumulator.NullValue); convolver.Convolve(SubGridTreeConsts.SubGridTreeDimension, SubGridTreeConsts.SubGridTreeDimension, (x, y) => context.Value(x, y), (x, y, v) => smoothedLeaf.Items[x, y] = v); }
public void Test_GenericLeafSubGridTests_Creation_WithItems() { var items = new bool[SubGridTreeConsts.SubGridTreeDimension, SubGridTreeConsts.SubGridTreeDimension]; var generic = new GenericLeafSubGrid <bool>(items); generic.Should().NotBeNull(); generic.Items.Should().BeEquivalentTo(items); }
public void Test_GenericLeafSubGridTests_Clear() { var generic = new GenericLeafSubGrid <bool>(null, null, SubGridTreeConsts.SubGridTreeLevels); generic.ForEach((x, y) => generic.Items[x, y] = true); generic.Clear(); generic.ForEach((x, y) => generic.Items[x, y].Should().BeFalse()); }
public void Test_GenericLeafSubGridTests_Creation_WithinTree() { var tree = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, GenericLeafSubGrid <bool> >()); var generic = new GenericLeafSubGrid <bool>(tree, null, SubGridTreeConsts.SubGridTreeLevels); generic.Should().NotBeNull(); generic.Owner.Should().Be(tree); generic.Parent.Should().Be(null); }
public static GenericLeafSubGrid <float> ConstructElevationSubGrid(float elevation) { var subGrid = new GenericLeafSubGrid <float> { Level = SubGridTreeConsts.SubGridTreeLevels }; subGrid.ForEach((x, y) => subGrid.Items[x, y] = elevation); return(subGrid); }
public void Test_GenericLeafSubGridTests_Write_BinaryWriter() { ISubGridTree tree = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, GenericLeafSubGrid <double> >()); GenericLeafSubGrid <double> subgrid = new GenericLeafSubGrid <double>(tree, null, SubGridTreeConsts.SubGridTreeLevels); // This is not implemented and should throw an exception. Override to implement... try { subgrid.Write(new BinaryWriter(new MemoryStream(Consts.TREX_DEFAULT_MEMORY_STREAM_CAPACITY_ON_CREATION))); Assert.True(false, "Read with BinaryWrite did not throw an exception"); } catch (Exception) { // As expected } }
public void Test_GenericLeafSubGridTests_ForEach_ActionFunctor() { var generic = new GenericLeafSubGrid <bool>(null, null, SubGridTreeConsts.SubGridTreeLevels); // All bools in generic are false.. // Test index based ForEach uint count = 0; generic.ForEach((x, y) => { if (!generic.Items[x, y]) { count++; } }); count.Should().Be(SubGridTreeConsts.CellsPerSubGrid); }
public static void ConstructElevationSubGrid(GenericLeafSubGrid <float> subGrid, float elevation) { subGrid.ForEach((x, y) => subGrid.Items[x, y] = elevation); }
public void Test_GenericLeafSubGridTests_Creation() { var generic = new GenericLeafSubGrid <bool>(); generic.Should().NotBeNull(); }
public virtual void Convolve(GenericLeafSubGrid <T> leaf, GenericLeafSubGrid <T> smoothedLeaf, IConvolver <T> convolver) { throw new NotImplementedException($"Convolve({nameof(GenericLeafSubGrid<T>)} leaf, ...) not implemented in this convolution tools class"); }