public Image(T[,] pixels) { Xs = pixels.GetLength(1); Ys = pixels.GetLength(0); Rows = new RowIndexer <T>(this); Columns = new ColumnIndexer <T>(this); this.pixels = pixels; }
public LinkedListBasedSheetDataIndexer(SheetData sheetData) { if (sheetData == null) { throw new ArgumentNullException("sheetData"); } long rowIndex = 0; // Order this sucker first so we don't have to sort a Linked List. foreach (var row in sheetData.Descendants<Row>().OrderBy(x => (uint)x.RowIndex)) { var rowIndexer = new RowIndexer(row); rowIndex = rowIndexer.RowIndex; this.rows.AddLast(rowIndexer); } this.maxRowIndex = rowIndex; this.SheetData = sheetData; }
/// <summary> /// Inserts a row at the target index and shifts all the previous indices down by one. /// </summary> /// <param name="toInsert">The row to insert.</param> /// <param name="rowIndex">The index in which to insert it.</param> private void InsertAndShiftRowsDown(RowIndexer toInsert, long rowIndex) { // Start at the end, work our way backwards var current = this.rows.Last; while (current.Value.RowIndex >= rowIndex && current != this.rows.First) { current.Value.RowIndex++; SyncCellReferencesToRowIndex(current.Value); current = current.Previous; } // Inserting at the first row is a special case if (current == this.rows.First && rowIndex == 1) { this.rows.First.Value.RowIndex++; this.rows.AddFirst(toInsert); this.SheetData.InsertBefore<Row>(toInsert, current.Value); } else { this.rows.AddAfter(current, toInsert); this.SheetData.InsertAfter<Row>(toInsert, current.Value); } this.maxRowIndex++; }
/// <inheritdoc /> public void InsertRow(RowIndexer toInsert, long rowIndex, bool shiftRowsDown = false) { // Check for out of bounds and over capacity if (rowIndex < 1 || rowIndex > Capacity || this.Count + 1 > Capacity) { throw new IndexOutOfRangeException("The requested row index is out of bounds!"); } if (toInsert == null) { throw new ArgumentNullException("toInsert"); } // First, some housekeeping toInsert.RowIndex = (uint)rowIndex; SyncCellReferencesToRowIndex(toInsert); // Easy case. Just add it to the end. if (rowIndex > this.maxRowIndex) { this.rows.AddLast(toInsert); this.SheetData.AppendChild<Row>(toInsert); this.maxRowIndex = rowIndex; } else if (shiftRowsDown) { // Handle shift this.InsertAndShiftRowsDown(toInsert, rowIndex); } else { LinkedListNode<RowIndexer> afterOrAtIndex = this.FindElementAfterOrAt(rowIndex); if (afterOrAtIndex.Value.RowIndex == rowIndex) { // caught the node at the index, replace this.SheetData.ReplaceChild<Row>(toInsert, afterOrAtIndex.Value); afterOrAtIndex.Value = toInsert; } else { // caught the first node after the index, insert this.SheetData.InsertBefore<Row>(toInsert, afterOrAtIndex.Value); this.rows.AddBefore(afterOrAtIndex, toInsert); } } }
/// <inheritdoc /> public void AppendRow(RowIndexer toAppend) { if (toAppend != null) { this.InsertRow(toAppend, this.maxRowIndex + 1); } }