This commit is contained in:
@@ -79,8 +79,39 @@ public class RenderableMultidoku {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Coordinate getMinSudokuOffset(Map<Sudoku, Coordinate> sudokusOffset) {
|
private static Coordinate getMinSudokuOffset(Map<Sudoku, Coordinate> sudokusOffset) {
|
||||||
// TODO
|
Coordinate minCoordinate = null;
|
||||||
return null;
|
for (Coordinate coordinate : sudokusOffset.values()) {
|
||||||
|
if (minCoordinate == null)
|
||||||
|
minCoordinate = coordinate;
|
||||||
|
minCoordinate = new Coordinate(Math.min(minCoordinate.getX(), coordinate.getX()), Math.min(minCoordinate.getY(), coordinate.getY()));
|
||||||
|
}
|
||||||
|
return minCoordinate;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Coordinate getMaxSudokuCoordinate(Map<Sudoku, Coordinate> sudokusOffset) {
|
||||||
|
Coordinate maxCoordinate = null;
|
||||||
|
Sudoku maxSudoku = null;
|
||||||
|
float maxDistanceSquared = 0;
|
||||||
|
for (var entry : sudokusOffset.entrySet()) {
|
||||||
|
Coordinate coordinate = entry.getValue();
|
||||||
|
float distanceSquared = coordinate.getX() * coordinate.getX() + coordinate.getY() * coordinate.getY();
|
||||||
|
if (maxCoordinate == null) {
|
||||||
|
maxCoordinate = coordinate;
|
||||||
|
maxDistanceSquared = distanceSquared;
|
||||||
|
maxSudoku = entry.getKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (distanceSquared > maxDistanceSquared) {
|
||||||
|
maxDistanceSquared = distanceSquared;
|
||||||
|
maxSudoku = entry.getKey();
|
||||||
|
maxCoordinate = coordinate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int blockWidth = maxSudoku.getBlockWidth();
|
||||||
|
int blockHeight = maxSudoku.getSize() / blockWidth;
|
||||||
|
|
||||||
|
return new Coordinate((maxCoordinate.getX() + blockHeight) * blockWidth, (maxCoordinate.getY() + blockWidth) * blockHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RenderableMultidoku fromMultidoku(MultiDoku doku) {
|
public static RenderableMultidoku fromMultidoku(MultiDoku doku) {
|
||||||
@@ -126,9 +157,21 @@ public class RenderableMultidoku {
|
|||||||
List<Block> blocks = new ArrayList<>();
|
List<Block> blocks = new ArrayList<>();
|
||||||
List<Cell> cells = new ArrayList<>();
|
List<Cell> cells = new ArrayList<>();
|
||||||
|
|
||||||
// TODO: dernière étape
|
for (Sudoku sudoku : doku.getSubGrids()) {
|
||||||
|
for (Block block : sudoku.getBlocks()) {
|
||||||
|
if (!blocks.contains(block)) {
|
||||||
|
blocks.add(block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Cell cell : sudoku.getCells()) {
|
||||||
|
if (!cells.contains(cell))
|
||||||
|
cells.add(cell);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new RenderableMultidoku(blocks, cells, 0, 0);
|
Coordinate maxCoordinate = getMaxSudokuCoordinate(sudokusOffset);
|
||||||
|
|
||||||
|
return new RenderableMultidoku(blocks, cells, maxCoordinate.getX(), maxCoordinate.getY());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user