Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public static IDominoShape[] AddRowColumn(IRowColumnAddableDeletable reference,
                                                  bool column, int position, bool southeast, int count, int color, out int[] inserted_positions)
        {
            int[][] shapes = new int[count][];
            for (int i = 0; i < count; i++)
            {
                shapes[i] = new int[reference.getLengthOfTypicalRowColumn(column)];
                for (int j = 0; j < shapes[i].Length; j++)
                {
                    shapes[i][j] = color;
                }
            }
            var pos   = reference.getPositionFromIndex(position);
            var res_y = southeast ? (pos.Y + (!column ? 1 : 0)) : pos.Y;
            var res_x = southeast ? (pos.X + (column ? 1 : 0)) : pos.X;

            if (!column && (res_y == -1 || res_y == reference.current_height + (column ? 0 : count)) ||
                column && (res_x == -1 || res_x == reference.current_width + (column ? count : 0)))
            {
                throw new InvalidOperationException("Can't insert row/column here, borders must remain borders");
            }
            return(AddRowColumn(reference, column, Enumerable.Repeat(new PositionWrapper()
            {
                X = res_x, Y = res_y, CountInsideCell = 0
            },
                                                                     count).ToArray(), shapes, out inserted_positions));
        }
Exemplo n.º 3
0
 public AddColumns(IRowColumnAddableDeletable reference, int position, int count, int color, bool right)
 {
     this.reference = reference;
     this.position  = position;
     this.count     = count;
     this.color     = color;
     this.right     = right;
 }
Exemplo n.º 4
0
 public AddRows(IRowColumnAddableDeletable reference, int position, int count, int color, bool below)
 {
     this.reference = reference;
     this.position  = position;
     this.count     = count;
     this.color     = color;
     this.below     = below;
 }
Exemplo n.º 5
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);
 }
Exemplo n.º 6
0
 public DeleteColumns(IRowColumnAddableDeletable reference, int[] position)
 {
     if (reference.current_height == 0)
     {
         throw new InvalidOperationException();
     }
     this.reference = reference;
     this.positions = position;
 }
Exemplo n.º 7
0
        public static int[] getDistinct(bool column, IRowColumnAddableDeletable reference, PositionWrapper[] positions)
        {
            int max_index = column ? reference.current_width : reference.current_height;

            int[] counts = new int[max_index + 1];
            for (int i = 0; i < positions.Length; i++)
            {
                var current = (column ? positions[i].X : positions[i].Y);
                if (current < 0 || current > max_index)
                {
                    continue;
                }
                counts[current]++;
            }
            return(counts);
        }
Exemplo n.º 8
0
 public static void copyColors(IRowColumnAddableDeletable reference, IDominoShape[] target,
                               int startX, int endX, int startY, int endY, int shiftX, int shiftY, int target_width, int target_height, bool swapCoords = false)
 {
     if (swapCoords)
     {
         int temp;
         temp = startX; startX = startY; startY = temp;
         temp = endX; endX = endY; endY = temp;
         temp = shiftX; shiftX = shiftY; shiftY = temp;
     }
     for (int x = startX; x <= endX; x++)
     {
         for (int y = startY; y <= endY; y++)
         {
             reference.copyGroup(target, x, y, x + shiftX, y + shiftY, target_width, target_height);
         }
     }
 }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        public static int[] getAllIndicesInRowColumn(IRowColumnAddableDeletable reference, int rowColumn, bool column, int maxindex, int current_width, int current_height)
        {
            int[] result   = new int[reference.getLengthOfTypicalRowColumn(column)];
            int   position = 0;

            for (int i = -1; i <= (column ? reference.current_height : reference.current_width); i++)
            {
                var(a, b) = reference.getIndicesOfCell(column ?  i : rowColumn, column ? rowColumn : i, current_width, current_height);
                for (int j = a; j <= b; j++)
                {
                    if (j >= 0 && j < maxindex && position < result.Length)
                    {
                        result[position] = j;
                        position++;
                    }
                    else
                    {
                    }
                }
            }
            return(result);
        }
Exemplo n.º 11
0
 public DeleteRows(IRowColumnAddableDeletable reference, int[] positions)
 {
     this.reference = reference;
     this.positions = positions;
 }