-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] Fix another ELK rounded coordinates problem
Problem is described here eclipse-elk/elk#1126. There is no simple reproduction use case because the issue was observed in a complex customer diagram. Change-Id: Ib70266ce1039040a19a1d09e2d93283c500c53ea
- Loading branch information
Showing
4 changed files
with
116 additions
and
3 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
63 changes: 63 additions & 0 deletions
63
plugins/org.eclipse.sirius.diagram.elk/src/org/eclipse/sirius/diagram/elk/SiriusElkUtil.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,63 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.diagram.elk; | ||
|
||
import org.eclipse.draw2d.geometry.Dimension; | ||
import org.eclipse.draw2d.geometry.PrecisionPoint; | ||
import org.eclipse.elk.core.math.KVector; | ||
import org.eclipse.elk.core.util.ElkUtil; | ||
import org.eclipse.elk.graph.ElkShape; | ||
|
||
/** | ||
* Utility methods for ELK layout-related things. | ||
* | ||
* @author lredor | ||
*/ | ||
public class SiriusElkUtil { | ||
|
||
/** | ||
* Prevents instanciation. | ||
*/ | ||
private SiriusElkUtil() { | ||
} | ||
|
||
/** | ||
* The ELK coordinates use floating point, but GMF uses Integer coordinates. The accumulation of rounding could have | ||
* side effects on absolute location (switch of one pixel for example). To avoid the problem, we try to find the | ||
* more appropriated rounding, above or below, according to parents coordinates. The return value is a | ||
* PrecisionPoint but the coordinates are Integer. PrecisionPoint is used for convenience in the following usages. | ||
* | ||
* @param elkShape | ||
* The shape for which we want to get the rounded coordinates. | ||
* @return The rounded coordinates of <code>elkShape</code> | ||
*/ | ||
public static PrecisionPoint getRoundedCoordinatesAccordingToParents(ElkShape elkShape) { | ||
PrecisionPoint defaultRoundedCoordinates = new PrecisionPoint(Math.toIntExact(Math.round(elkShape.getX())), Math.toIntExact(Math.round(elkShape.getY()))); | ||
if (elkShape.eContainer() instanceof ElkShape parent) { | ||
KVector absoluteELKCoordinates = ElkUtil.absolutePosition(elkShape); | ||
PrecisionPoint parentRoundedAbsoluteCoordinates = getRoundedAbsoluteCoordinates(parent); | ||
PrecisionPoint roundedAbsoluteCoordinates = (PrecisionPoint) defaultRoundedCoordinates.getTranslated(parentRoundedAbsoluteCoordinates); | ||
Dimension delta = new Dimension((int) (absoluteELKCoordinates.x - roundedAbsoluteCoordinates.preciseX()), (int) (absoluteELKCoordinates.y - roundedAbsoluteCoordinates.preciseY())); | ||
defaultRoundedCoordinates.translate(delta); | ||
} | ||
return defaultRoundedCoordinates; | ||
} | ||
|
||
private static PrecisionPoint getRoundedAbsoluteCoordinates(ElkShape elkShape) { | ||
PrecisionPoint roundedCoordinates = getRoundedCoordinatesAccordingToParents(elkShape); | ||
if (elkShape.eContainer() instanceof ElkShape parent) { | ||
roundedCoordinates.translate(getRoundedAbsoluteCoordinates(parent)); | ||
} | ||
return roundedCoordinates; | ||
} | ||
} |
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