public static IDominoShape[] AddRowColumn(IRowColumnAddableDeletable reference, bool column, PositionWrapper[] positions, int[][] shapes, out int[] inserted_positions) { int total_added = positions.Length; int new_width = reference.current_width + (column ? total_added : 0); int new_height = reference.current_height + (!column ? total_added : 0); int[] distinct = getDistinct(column, reference, positions); total_added = distinct.Sum(); IDominoShape[] new_shapes = reference.getNewShapes(new_width, new_height); int typicallength = reference.getLengthOfTypicalRowColumn(column); List <int> insertedPositions = new List <int>(); int added_counter = 0; for (int i = -1; i < distinct.Length; i++) { if (i != -1 && distinct[i] > 0) { for (int i2 = 0; i2 < distinct[i]; i2++) { reference.ReinsertRowColumn(shapes[added_counter + i2], column, i + added_counter + i2, new_shapes, new_width, new_height); insertedPositions.AddRange(getAllIndicesInRowColumn(reference, i + i2 + added_counter, column, new_shapes.Length, new_width, new_height)); } added_counter += distinct[i]; } copyColors(reference, new_shapes, -1, column ? reference.current_height : reference.current_width, i, i, 0, added_counter, new_width, new_height, column); } reference.current_width = new_width; reference.current_height = new_height; inserted_positions = insertedPositions.ToArray(); return(new_shapes); }
public static IDominoShape[] DeleteRowColumn(IRowColumnAddableDeletable reference, bool column, PositionWrapper[] positions, out PositionWrapper[] remaining_positions, out int[][] deleted_shapes) { int[] distinct = getDistinct(column, reference, positions); distinct[distinct.Length - 1] = 0; int total_deleted = distinct.Sum(x => x > 0 ? 1 : 0); if (total_deleted == 0) { throw new InvalidOperationException("Nothing to delete. Borders can't be deleted."); } int new_width = reference.current_width - (column ? total_deleted : 0); int new_height = reference.current_height - (!column ? total_deleted : 0); IDominoShape[] new_shapes = reference.getNewShapes(new_width, new_height); deleted_shapes = new int[total_deleted][]; remaining_positions = new PositionWrapper[total_deleted]; int deleted_counter = 0; int rowcollength = deleted_shapes.Length / total_deleted; for (int i = -1; i < distinct.Length; i++) { if (i != -1 && i != distinct.Length - 1 && distinct[i] > 0) { deleted_shapes[deleted_counter] = reference.ExtractRowColumn(column, i); remaining_positions[deleted_counter] = new PositionWrapper() { X = column ? (i - deleted_counter) : 0, Y = column ? 0 : (i - deleted_counter), CountInsideCell = 0 }; deleted_counter++; } else { copyColors(reference, new_shapes, -1, column ? reference.current_height : reference.current_width, i, i, 0, -deleted_counter, new_width, new_height, column); } } reference.current_width = new_width; reference.current_height = new_height; return(new_shapes); }