private bool IsAnyNeighbourCellFree(int[,] matrix, IMatrixCell currentCell) { int[] directionsRows = { 1, 1, 1, 0, -1, -1, -1, 0 }; int[] directionsCols = { 1, 0, -1, -1, -1, 0, 1, 1 }; for (int i = 0; i < 8; i++) { if (currentCell.Row + directionsRows[i] >= matrix.GetLength(0) || currentCell.Row + directionsRows[i] < 0) { directionsRows[i] = 0; } if (currentCell.Col + directionsCols[i] >= matrix.GetLength(0) || currentCell.Col + directionsCols[i] < 0) { directionsCols[i] = 0; } } for (int i = 0; i < 8; i++) { if (matrix[currentCell.Row + directionsRows[i], currentCell.Col + directionsCols[i]] == 0) { return(true); } } return(false); }
private IMatrixCell FindNearestFreeCell(int[,] arr, IMatrixCell currentCell) { for (int currentRow = 0; currentRow < arr.GetLength(0); currentRow++) { for (int currentCol = 0; currentCol < arr.GetLength(0); currentCol++) { if (arr[currentRow, currentCol] == 0) { currentCell.Row = currentRow; currentCell.Col = currentCol; return(currentCell); } } } return(null); }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { IMatrixCell cell = values[0] as IMatrixCell; if (cell == null) { return(DependencyProperty.UnsetValue); } IMatrix matrix = null; if (values.Length > 1) { matrix = values[1] as IMatrix; } if (cell.CellType == MatrixCellType.DataCell) { if (matrix != null) { if (matrix.Size.Width - 1 == cell.GridColumn) { return(new Thickness(0d, 0d, 2d, 1d)); } } return(new Thickness(0d, 0d, 1d, 1d)); } IMatrixHeader header = cell as IMatrixHeader; IMatrixSummaryCell summaryCell = cell as IMatrixSummaryCell; if (header != null) { if (header.CellType == MatrixCellType.Empty) { return(new Thickness(0d, 0d, 2d, 2d)); } if (header.CellType == MatrixCellType.ColumnHeader || header.CellType == MatrixCellType.ColumnsGroupHeader) { if (header.GridRow == 0) { if (header.ChildrenCount == 0) { return(new Thickness(0d, 2d, 1d, 2d)); } else { return(new Thickness(0d, 2d, 1d, 1d)); } } else { if (header.ChildrenCount == 0) { return(new Thickness(0d, 0d, 1d, 2d)); } else { return(new Thickness(0d, 0d, 1d, 1d)); } } } if (header.CellType == MatrixCellType.RowHeader || header.CellType == MatrixCellType.RowsGroupHeader) { if (header.GridColumn == 0) { if (header.ChildrenCount == 0) { return(new Thickness(2d, 0d, 2d, 1d)); } else { return(new Thickness(2d, 0d, 1d, 1d)); } } else { if (header.ChildrenCount == 0) { return(new Thickness(0d, 0d, 2d, 1d)); } else { return(new Thickness(0d, 0d, 1d, 1d)); } } } if (header.CellType == MatrixCellType.ColumnSummaryHeader) { if (header.GridRow == 0) { return(new Thickness(1d, 2d, 2d, 2d)); } return(new Thickness(0d, 1d, 1d, 1d)); } if (header.CellType == MatrixCellType.RowSummaryHeader) { if (header.GridColumn == 0) { return(new Thickness(2d, 1d, 2d, 2d)); } return(new Thickness(0d, 1d, 1d, 1d)); } } if (summaryCell != null) { if (summaryCell.SummaryType == MatrixSummaryType.RowSummary || summaryCell.SummaryType == MatrixSummaryType.RowsGroupSummary) { return(new Thickness(2d, 0d, 2d, 2d)); } if (summaryCell.SummaryType == MatrixSummaryType.ColumnSummary || summaryCell.SummaryType == MatrixSummaryType.ColumnsGroupSummary) { return(new Thickness(0d, 2d, 2d, 2d)); } if (summaryCell.SummaryType == MatrixSummaryType.TotalGroupSummary) { return(new Thickness(0d, 0d, 1d, 1d)); } if (summaryCell.SummaryType == MatrixSummaryType.TotalSummary) { return(new Thickness(0d, 0d, 2d, 2d)); } } return(DependencyProperty.UnsetValue); }