From 1e67e7a9d462c7b8e67a28fd43969491f40962f7 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Sun, 2 Feb 2025 00:37:07 +0100 Subject: [PATCH] fix renderable multidoku max coords --- .../main/java/gui/RenderableMultidoku.java | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/gui/RenderableMultidoku.java b/app/src/main/java/gui/RenderableMultidoku.java index 9c7a711..5a16247 100644 --- a/app/src/main/java/gui/RenderableMultidoku.java +++ b/app/src/main/java/gui/RenderableMultidoku.java @@ -90,29 +90,23 @@ public class RenderableMultidoku { } private static Coordinate getMaxSudokuCoordinate(Map sudokusOffset) { - Coordinate maxCoordinate = null; - Sudoku maxSudoku = null; - float maxDistanceSquared = 0; + int maxX = 0; + int maxY = 0; + Sudoku lastSudoku = null; 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; - } + if (coordinate.getX() > maxX) + maxX = coordinate.getX(); + if (coordinate.getY() > maxY) + maxY = coordinate.getY(); + lastSudoku = entry.getKey(); } - int blockWidth = maxSudoku.getBlockWidth(); - int blockHeight = maxSudoku.getSize() / blockWidth; + Coordinate maxCoordinate = new Coordinate(maxX, maxY); + // tous les sudokus sont censés faire la même taille + int sudokuSize = lastSudoku.getSize(); - return new Coordinate(maxCoordinate.getX() + maxSudoku.getSize(), maxCoordinate.getY() + maxSudoku.getSize()); + return new Coordinate(maxCoordinate.getX() + sudokuSize, maxCoordinate.getY() + sudokuSize); } public static RenderableMultidoku fromMultidoku(MultiDoku doku) {