-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Height is computated by row & width is computed by column
Signed-off-by: Thomas ADAM <[email protected]>
- Loading branch information
Showing
15 changed files
with
1,015 additions
and
943 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...gram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/zonebygrid/Matrix.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* Copyright (c) 2023, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
package com.powsybl.sld.layout.zonebygrid; | ||
|
||
import com.powsybl.sld.model.graphs.*; | ||
|
||
import java.util.*; | ||
import java.util.stream.*; | ||
|
||
/** | ||
* @author Thomas Adam {@literal <tadam at neverhack.com>} | ||
*/ | ||
public class Matrix { | ||
// [row] [col] | ||
private final MatrixCell[][] cells; | ||
|
||
public Matrix(int rows, int cols) { | ||
cells = new MatrixCell[rows][cols]; | ||
} | ||
|
||
public Matrix set(int row, int col, MatrixCell cell) { | ||
cells[row][col] = cell; | ||
return this; | ||
} | ||
|
||
public MatrixCell get(int row, int col) { | ||
return cells[row][col]; | ||
} | ||
|
||
public Stream<MatrixCell> stream() { | ||
return Arrays.stream(cells).flatMap(Arrays::stream); | ||
} | ||
|
||
public double getMatrixCellHeight(int row) { | ||
return Stream.of(cells[row]).filter(cell -> !cell.isEmpty()).mapToDouble(cell -> cell.graph().getHeight()).max().orElse(0.0); | ||
} | ||
|
||
public double getMatrixCellWidth(int col) { | ||
double maxWidth = 0.0; | ||
for (int row = 0; row < rowCount(); row++) { | ||
BaseGraph graph = cells[row][col].graph(); | ||
if (graph != null) { | ||
maxWidth = Math.max(maxWidth, graph.getWidth()); | ||
} | ||
} | ||
return maxWidth; | ||
} | ||
|
||
public int rowCount() { | ||
return cells.length; | ||
} | ||
|
||
public int columnCount() { | ||
return cells[0].length; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.