public void Grid5x3True() { bool[,] array = new bool[, ] { { true, true, true }, { true, true, true }, { true, true, true }, { true, true, true }, { true, true, true } }; DataGrid <bool> grid = new DataGrid <bool>(array); ActiveSiteMap map = new ActiveSiteMap(grid); Assert.AreEqual(grid.Count, map.Count); int index = 0; Location location = new Location(1, 1); foreach (LocationAndIndex entry in map) { index++; Assert.IsTrue(index <= map.Count); Assert.AreEqual(location, entry.Location); Assert.AreEqual((uint)index, entry.Index); location = RowMajor.Next(location, grid.Columns); } Assert.AreEqual(map.Count, index); Assert.AreEqual(new Location(1, 1), map.FirstActive.Location); Assert.AreEqual(1, map.FirstActive.Index); Assert.IsNull(map.FirstInactive); }
public void Test01_NextWith1Col() { Assert.AreEqual(Loc(2, 1), RowMajor.Next(Loc(1, 1), 1)); Assert.AreEqual(Loc(3, 1), RowMajor.Next(Loc(2, 1), 1)); Assert.AreEqual(Loc(790, 1), RowMajor.Next(Loc(789, 1), 1)); }
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public override bool MoveNext() { if (CurrentState == State.AfterLast) { return(false); } if (CurrentState == State.BeforeFirst) { if (locations.ActiveLocationCount == 0 && locations.InactiveLocationCount == 0) { return(MoveNextReachedEnd()); } CurrentLocation = new Location(1, 1); } else { // CurrentState == State.InCollection CurrentLocation = RowMajor.Next(CurrentLocation, Columns); } if (CurrentLocation.Row <= Rows) { CurrentDataIndex = locations.indexes[CurrentLocation.Row - 1, CurrentLocation.Column - 1]; return(MoveNextSucceeded()); } ResetLocationAndIndex(); return(MoveNextReachedEnd()); }
//--------------------------------------------------------------------- public void ReadBufferPixel() { IncrementPixelsRead(); currentPixelLoc = RowMajor.Next(currentPixelLoc, Dimensions.Columns); pixel.MapCode.Value = convertToUShort(data[currentPixelLoc.Row - 1, currentPixelLoc.Column - 1]); }
//--------------------------------------------------------------------- public Pixel ReadPixel() { IncrementPixelsRead(); currentPixelLoc = RowMajor.Next(currentPixelLoc, (uint)Dimensions.Columns); pixel.Band0 = convertToUShort(data[currentPixelLoc.Row - 1, currentPixelLoc.Column - 1]); return(pixel); }
//--------------------------------------------------------------------- public TPixel ReadPixel() { IncrementPixelsRead(); currentPixelLoc = RowMajor.Next(currentPixelLoc, Dimensions.Columns); pixel.Band0 = data[currentPixelLoc.Row - 1, currentPixelLoc.Column - 1]; return(pixel); }
public void SiteEnumerator_Reuse() { SiteEnumerator allSites = landscape.GetSiteEnumerator(); for (int passes = 1; passes <= 3; passes++) { int index = 0; Location?nextActiveSite; if (index < activeSites.Count) { nextActiveSite = activeSites[index]; } else { nextActiveSite = null; } Location expectedLocation = new Location(1, 0); // so next in row-major order is (1,1) int siteCount = 0; foreach (Site site in allSites) { siteCount++; Assert.AreEqual(landscape, site.Landscape); Assert.IsTrue(site.IsMutable); expectedLocation = RowMajor.Next(expectedLocation, grid.Columns); Assert.AreEqual(expectedLocation, site.Location); if (nextActiveSite != null && nextActiveSite == expectedLocation) { Assert.AreEqual(index + 1, site.DataIndex); Assert.AreEqual(true, site.IsActive); index++; if (index < activeSites.Count) { nextActiveSite = activeSites[index]; } else { nextActiveSite = null; } } else { // Inactive site Assert.AreEqual(landscape.InactiveSiteDataIndex, site.DataIndex); Assert.AreEqual(false, site.IsActive); } } Assert.AreEqual(grid.Count, siteCount); } }
public void Test02_NextWith89Cols() { Assert.AreEqual(Loc(1, 2), RowMajor.Next(Loc(1, 1), 89)); Assert.AreEqual(Loc(1, 3), RowMajor.Next(Loc(1, 2), 89)); Assert.AreEqual(Loc(1, 89), RowMajor.Next(Loc(1, 88), 89)); Assert.AreEqual(Loc(2, 1), RowMajor.Next(Loc(1, 89), 89)); Assert.AreEqual(Loc(45, 89), RowMajor.Next(Loc(45, 88), 89)); Assert.AreEqual(Loc(46, 1), RowMajor.Next(Loc(45, 89), 89)); }
//--------------------------------------------------------------------- public TData ReadValue() { if (disposed) { throw new System.ObjectDisposedException(GetType().FullName); } currentLocation = RowMajor.Next(currentLocation, Columns); if (currentLocation.Row > Rows) { throw new System.IO.EndOfStreamException(); } return(data[currentLocation]); }
//--------------------------------------------------------------------- public bool MoveNext() { if (CurrentState == State.AfterLast) { return(false); } if (CurrentState == State.BeforeFirst) { if (landscape.SiteCount == 0) { return(MoveNextReachedEnd()); } currentSite = landscape.GetSite(1, 1); nextActiveSite = GetNext(activeSiteEtor); // If the first active site is (1, 1), then get the next // active site. if (nextActiveSite == currentSite) { nextActiveSite = GetNext(activeSiteEtor); } return(MoveNextSucceeded()); } // CurrentState == State.InCollection Location nextLocation = RowMajor.Next(currentSite.Location, landscape.Columns); if (nextLocation.Row > landscape.Rows) { currentSite = new Site(); return(MoveNextReachedEnd()); } // We have a valid site location; is the site active or not? if (nextLocation == nextActiveSite.Location) { currentSite = nextActiveSite; nextActiveSite = GetNext(activeSiteEtor); } else { currentSite = InactiveSite.Create(landscape, nextLocation); } return(MoveNextSucceeded()); }
//--------------------------------------------------------------------- public bool ReadValue() { if (disposed) { throw new System.InvalidOperationException("Object has been disposed."); } Pixel pixel = raster.ReadPixel(); pixelLocation = RowMajor.Next(pixelLocation, raster.Dimensions.Columns); ushort mapCode = pixel.Band0; IEcoregion ecoregion = ecoregions.Find(mapCode); if (ecoregion != null) { return(ecoregion.Active); } string mesg = string.Format("Error at map site {0}", pixelLocation); string innerMesg = string.Format("Unknown map code for ecoregion: {0}", mapCode); throw new MultiLineException(mesg, innerMesg); }
public void Grid1x1True() { bool[,] array = new bool[, ] { { true } }; DataGrid <bool> grid = new DataGrid <bool>(array); ActiveSiteMap map = new ActiveSiteMap(grid); Assert.AreEqual(grid.Count, map.Count); int index = 0; Location location = new Location(1, 1); foreach (ActiveSiteMap.Entry entry in map) { Assert.IsTrue(index < map.Count); Assert.AreEqual(location, entry.Location); Assert.AreEqual((uint)index, entry.Index); index++; location = RowMajor.Next(location, grid.Columns); } Assert.AreEqual(map.Count, index); }
//--------------------------------------------------------------------- public bool ReadValue() { if (disposed) { throw new System.InvalidOperationException("Object has been disposed."); } EcoregionPixel pixel = raster.BufferPixel; raster.ReadBufferPixel(); pixelLocation = RowMajor.Next(pixelLocation, raster.Dimensions.Columns); ushort mapCode = (ushort)pixel.MapCode.Value; IEcoregion ecoregion = ecoregions.Find(mapCode); //Console.WriteLine(" reading in ecoregion {0} which is {1}", ecoregion.Name, ecoregion.Active); if (ecoregion != null) { return(ecoregion.Active); } string mesg = string.Format("Error at map site {0}", pixelLocation); string innerMesg = string.Format("Unknown map code for ecoregion: {0}", mapCode); throw new MultiLineException(mesg, innerMesg); }