Esempio n. 1
0
 public static PositionWrapper[] IndicesToPositions(IRowColumnAddableDeletable reference, int[] positions)
 {
     PositionWrapper[] wrapper = new PositionWrapper[positions.Length];
     for (int i = 0; i < positions.Length; i++)
     {
         wrapper[i] = reference.getPositionFromIndex(positions[i]);
     }
     return(wrapper);
 }
Esempio n. 2
0
        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);
        }