Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Redor2014-10-14 13:34:30 +0000
committerLaurent Redor2014-10-14 15:12:37 +0000
commit7d47eb8d8f5e581297910a075b7d3ee7ead61723 (patch)
tree2a06be9871083b5d79e2a258c46fdcc515f77cf0
parent245ac7452adf98d1b0a8cd2718b81faaabfa30e1 (diff)
downloadorg.eclipse.sirius-7d47eb8d8f5e581297910a075b7d3ee7ead61723.tar.gz
org.eclipse.sirius-7d47eb8d8f5e581297910a075b7d3ee7ead61723.tar.xz
org.eclipse.sirius-7d47eb8d8f5e581297910a075b7d3ee7ead61723.zip
[442289] Improve gap computation
Currently, the gap is rounded to the lower Integer. So the last gap can be different. To minimize the delta between the last gap and the others, the gap is now rounded up to the lower Integer if the remainder is less than or equal to 0.5 and higher integer if the remainder is greater than 0.5. Bug: 442289 Change-Id: Ia1c234af77157abc6f61bf4aa28498ddb721f494 Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/commands/DistributeCommand.java10
1 files changed, 8 insertions, 2 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/commands/DistributeCommand.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/commands/DistributeCommand.java
index f86ab89539..8b970dd664 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/commands/DistributeCommand.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/commands/DistributeCommand.java
@@ -422,7 +422,10 @@ public class DistributeCommand extends AbstractTransactionalCommand {
availableSpace -= getSizeFunction.apply(part);
}
}
- return availableSpace / (partsToDistribute.size() - 1);
+ // Gap is rounded up to the lower Integer if the
+ // remainder is less than or equal to 0.5 and higher
+ // integer if the remainder is greater than 0.5.
+ return Math.round(((float) availableSpace) / (partsToDistribute.size() - 1));
}
});
}
@@ -470,7 +473,10 @@ public class DistributeCommand extends AbstractTransactionalCommand {
new GetGapFunction(partsToDistribute, getMainAxisFunction, getMainAxisFunction, getSizeFunction) {
@Override
public int apply(IGraphicalEditPart firstPart, IGraphicalEditPart lastPart) {
- return (getFirstPartMainAxisFunction.apply(lastPart) - getLastPartMainAxisFunction.apply(firstPart)) / (partsToDistribute.size() - 1);
+ // Gap is rounded up to the lower Integer if the
+ // remainder is less than or equal to 0.5 and higher
+ // integer if the remainder is greater than 0.5.
+ return Math.round(((float) (getFirstPartMainAxisFunction.apply(lastPart) - getLastPartMainAxisFunction.apply(firstPart))) / (partsToDistribute.size() - 1));
}
});
}

Back to the top