//--------------------------------------------------------------------- public uint this[Location location] { get { uint?rowOffset = Interval.Search(location.Row, rowIntervals, 0, rowIntervals.Count); if (rowOffset == null) { return(this.count); } ActiveRow activeRow = activeRows[(int)rowOffset.Value]; uint? colOffset = Interval.Search(location.Column, columnIntervals, (int)activeRow.FirstIntervalOffset, (int)activeRow.IntervalCount); if (colOffset == null) { return(this.count); } else { return(colOffset.Value); } } }
//--------------------------------------------------------------------- public IEnumerator <Entry> GetEnumerator() { foreach (Interval rowInterval in this.rowIntervals) { for (uint row = rowInterval.Start; row <= rowInterval.End; ++row) { int activeRowOffset = (int)(rowInterval.StartOffset + (row - rowInterval.Start)); ActiveRow activeRow = this.activeRows[activeRowOffset]; for (int colIntervalIndex = 0; colIntervalIndex < activeRow.IntervalCount; ++colIntervalIndex) { int colIntervalOffset = (int) (activeRow.FirstIntervalOffset + colIntervalIndex); Interval columnInterval = this.columnIntervals[ colIntervalOffset]; uint index = columnInterval.StartOffset; for (uint column = columnInterval.Start; column <= columnInterval.End; ++column) { yield return(new Entry(new Location(row, column), index)); index++; } } } } }
//--------------------------------------------------------------------- public uint this[Location location] { get { uint?rowOffset = Interval.Search(rowIntervals, location.Row); if (rowOffset == null) { return(this.count); } ActiveRow activeRow = activeRows[(int)rowOffset.Value]; List <Interval> colIntervalsInRow = columnIntervals.GetRange((int) activeRow.FirstIntervalOffset, (int)activeRow.IntervalCount); uint?colOffset = Interval.Search(colIntervalsInRow, location.Column); if (colOffset == null) { return(this.count); } else { return(colOffset.Value); } } }
public void OnRowActivated(Guid rowId) { if (!ActiveRow.Equals(rowId)) { ActiveRow = rowId; StateHasChanged(); } }
//--------------------------------------------------------------------- private void Initialize(IInputGrid <bool> activeSites) { this.firstActive = null; this.firstInactive = null; this.rowIntervals = new List <Interval>(); this.activeRows = new List <ActiveRow>(); this.columnIntervals = new List <Interval>(); bool inRowInterval = false; Interval rowInterval = new Interval(); for (uint row = 1; row <= activeSites.Rows; ++row) { uint colIntervalCount = 0; uint firstColIntervalIndex = 0; bool inColumnInterval = false; Interval columnInterval = new Interval(); for (uint column = 1; column <= activeSites.Columns; ++column) { if (activeSites.ReadValue()) { this.count++; if (!this.firstActive.HasValue) { this.firstActive = new Location(row, column); } if (inColumnInterval) { // extend column interval columnInterval.End = column; } else { // start a new column interval columnInterval = new Interval(column, column, count - 1); inColumnInterval = true; colIntervalCount++; if (colIntervalCount == 1) { firstColIntervalIndex = (uint) columnIntervals.Count; } } } else { // current site is inactive if (!this.firstInactive.HasValue) { this.firstInactive = new Location(row, column); } if (inColumnInterval) { // end of current column interval this.columnIntervals.Add(columnInterval); inColumnInterval = false; } } } // for each column // at end of current row if (colIntervalCount > 0) { // current row is an active row if (inColumnInterval) { // last column was active, so add its interval this.columnIntervals.Add(columnInterval); } this.activeRows.Add(new ActiveRow(colIntervalCount, firstColIntervalIndex)); if (inRowInterval) { // extend row interval rowInterval.End = row; } else { // start a new row interval rowInterval = new Interval(row, row, (uint)(activeRows.Count - 1)); inRowInterval = true; } } else { // current row is not an active row if (inRowInterval) { this.rowIntervals.Add(rowInterval); inRowInterval = false; } } } // for each row if (inRowInterval) { // last row was an active row, so add its row interval this.rowIntervals.Add(rowInterval); } if (logger.IsDebugEnabled) { LogDebug("Active Site Map"); LogDebug(""); LogDebug("Input Grid: {0}", activeSites.Dimensions); LogDebug(""); LogDebug("Row Intervals"); LogDebug(" index: start to end (index of start row in active rows"); for (int i = 0; i < rowIntervals.Count; i++) { Interval interval = rowIntervals[i]; LogDebug(" {0}: {1} to {2} ({3})", i, interval.Start, interval.End, interval.StartOffset); } LogDebug(""); LogDebug("Active Rows"); LogDebug(" index: # column intervals, index of 1st column interval"); for (int i = 0; i < activeRows.Count; i++) { ActiveRow activeRow = ActiveRows[i]; LogDebug(" {0}: {1}, {2}", i, activeRow.IntervalCount, activeRow.FirstIntervalOffset); } LogDebug(""); LogDebug("Column Intervals"); LogDebug(" index: start to end (data index of start column"); for (int i = 0; i < columnIntervals.Count; i++) { Interval interval = columnIntervals[i]; LogDebug(" {0}: {1} to {2} ({3})", i, interval.Start, interval.End, interval.StartOffset); } } }