Skip to content

Commit

Permalink
Center substation into own matrix cell
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas ADAM <[email protected]>
  • Loading branch information
tadam50 committed Jan 29, 2024
1 parent 06e25f0 commit 0e895c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,22 @@ protected void calculateCoordSubstations(LayoutParameters layoutParameters) {
// Zone size
int nbRows = matrix.rowCount();
int nbCols = matrix.columnCount();
// FIXME : padding diagram is canceled here !
double leftPadding = layoutParameters.getDiagramPadding().getLeft();
double topPadding = layoutParameters.getDiagramPadding().getTop();
// Move each substation into its matrix position
for (int row = 0; row < nbRows; row++) {
maxWidthCol = 0;
for (int col = 0; col < nbCols; col++) {
MatrixCell cell = matrix.get(row, col);
BaseGraph graph = cell.graph();
if (graph != null) {
// Compute delta in order to center substations into own matrix cell
int deltaX = (int)(matrix.getMatrixCellWidth(col) % graph.getWidth()) / 2;
int deltaY = (int)(matrix.getMatrixCellHeight(row) % graph.getHeight()) / 2;
double dx = maxWidthCol + (col + 1.0) * snakelineMargin;
double dy = maxHeightRow + (row + 1.0) * snakelineMargin;
move(graph, dx, dy);
move(graph, dx - leftPadding + deltaX, dy - topPadding + deltaY);
}
maxWidthCol += matrix.getMatrixCellWidth(col);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,23 @@ private void computeMatrixCellsAvailability(LayoutParameters layoutParameters) {
// Make empty cells available for snakeline computation
List<MatrixCell> allCells = matrix.stream().toList();
allCells.forEach(cell -> {
double matrixCellWidth = matrix.getMatrixCellWidth(cell.col());
double matrixCellHeight = matrix.getMatrixCellHeight(cell.row());
int matrixCellWidth = (int) matrix.getMatrixCellWidth(cell.col());
int matrixCellHeight = (int) matrix.getMatrixCellHeight(cell.row());
int ssX = getX(cell.col(), snakelineMargin);
int ssY = getY(cell.row(), snakelineMargin);

// Horizontal lines
int stepH = (int) layoutParameters.getHorizontalSnakeLinePadding();
int deltaH = (matrixCellHeight % stepH) / 2;
for (int x = ssX; x < ssX + matrixCellWidth; x++) {
for (int y = ssY; y < ssY + matrixCellHeight; y += layoutParameters.getHorizontalSnakeLinePadding()) {
for (int y = ssY + deltaH + stepH; y < ssY + matrixCellHeight - deltaH; y += stepH) {
pathFinderGrid.setAvailability(x, y, true);
}
}

for (int x = ssX; x < ssX + matrixCellWidth; x += layoutParameters.getVerticalSnakeLinePadding()) {
// Vertical lines
int stepV = (int) layoutParameters.getVerticalSnakeLinePadding();
int deltaV = (matrixCellWidth % stepV) / 2;
for (int x = ssX + deltaV + stepV; x < ssX + matrixCellWidth - deltaV; x += stepV) {
for (int y = ssY; y < ssY + matrixCellHeight; y++) {
pathFinderGrid.setAvailability(x, y, true);
}
Expand Down

0 comments on commit 0e895c5

Please sign in to comment.