diff --git a/TULIP/src/lu/list/itis/dkd/tui/space/SpatialMatrix.java b/TULIP/src/lu/list/itis/dkd/tui/space/SpatialMatrix.java index bc4104645586c590f7915a29d6d4184a1030e798..e84a9624ae6ba48dd0c5c51317af30b88f2abb7b 100644 --- a/TULIP/src/lu/list/itis/dkd/tui/space/SpatialMatrix.java +++ b/TULIP/src/lu/list/itis/dkd/tui/space/SpatialMatrix.java @@ -59,8 +59,8 @@ public class SpatialMatrix { * The object to add. */ public synchronized void add(TangibleObject object) { - horizontal.add(findHorizontalIndexFor(object), object); - vertical.add(findVerticalIndexFor(object), object); + horizontal.add(findHorizontalIndexFor(object, false), object); + vertical.add(findVerticalIndexFor(object, false), object); } /** @@ -113,10 +113,18 @@ public class SpatialMatrix { * @return The index to add the element or the size of the list if the element should be added * at the end. */ - private synchronized int findHorizontalIndexFor(TangibleObject object) { + private synchronized int findHorizontalIndexFor(TangibleObject object, boolean strict) { for (int index = 0; index < horizontal.size(); index++) { - if (Double.compare(object.getPosition().toScreenCoordinates().getX(), horizontal.get(index).getPosition().toScreenCoordinates().getX()) <= 0) { - return index; + int comparisonResult = Double.compare(object.getPosition().toScreenCoordinates().getX(), horizontal.get(index).getPosition().toScreenCoordinates().getX()); + + if (strict) { + if (comparisonResult < 0) { + return index; + } + } else { + if (comparisonResult <= 0) { + return index; + } } } return horizontal.size(); @@ -132,12 +140,20 @@ public class SpatialMatrix { * @return The index to add the element or the size of the list if the element should be added * at the end. */ - private synchronized int findHorizontalIndexFor(int objectId) { + private synchronized int findHorizontalIndexFor(int objectId, boolean strict) { BaseWidget widget = TangibleObjectManager.getWidget(objectId); for (int index = 0; index < horizontal.size(); index++) { - if (Double.compare(widget.getPosition(objectId).toScreenCoordinates().getX(), horizontal.get(index).getPosition().toScreenCoordinates().getX()) <= 0) { - return index; + int comparisonResult = Double.compare(widget.getPosition(objectId).toScreenCoordinates().getX(), horizontal.get(index).getPosition().toScreenCoordinates().getX()); + + if (strict) { + if (comparisonResult < 0) { + return index; + } + } else { + if (comparisonResult <= 0) { + return index; + } } } return horizontal.size(); @@ -154,10 +170,17 @@ public class SpatialMatrix { * @return The index to add the element or the size of the list if the element should be added * at the end. */ - private synchronized int findVerticalIndexFor(TangibleObject object) { + private synchronized int findVerticalIndexFor(TangibleObject object, boolean strict) { for (int index = 0; index < vertical.size(); index++) { - if (Double.compare(object.getPosition().toScreenCoordinates().getY(), vertical.get(index).getPosition().toScreenCoordinates().getY()) <= 0) { - return index; + int comparisonResult = Double.compare(object.getPosition().toScreenCoordinates().getY(), vertical.get(index).getPosition().toScreenCoordinates().getY()); + if (strict) { + if (comparisonResult < 0) { + return index; + } + } else { + if (comparisonResult <= 0) { + return index; + } } } return vertical.size(); @@ -173,12 +196,20 @@ public class SpatialMatrix { * @return The index to add the element or the size of the list if the element should be added * at the end. */ - private synchronized int findVerticalIndexFor(int objectId) { + private synchronized int findVerticalIndexFor(int objectId, boolean strict) { BaseWidget widget = TangibleObjectManager.getWidget(objectId); for (int index = 0; index < vertical.size(); index++) { - if (Double.compare(widget.getPosition(objectId).toScreenCoordinates().getY(), vertical.get(index).getPosition().toScreenCoordinates().getY()) <= 0) { - return index; + int comparisonResult = Double.compare(widget.getPosition(objectId).toScreenCoordinates().getY(), vertical.get(index).getPosition().toScreenCoordinates().getY()); + + if (strict) { + if (comparisonResult < 0) { + return index; + } + } else { + if (comparisonResult <= 0) { + return index; + } } } return vertical.size(); @@ -200,7 +231,7 @@ public class SpatialMatrix { * left of the given object. */ public synchronized List leftOf(int objectId) { - int index = findHorizontalIndexFor(objectId); + int index = findHorizontalIndexFor(objectId, false); return new ArrayList<>(horizontal.subList(0, index)); } @@ -220,7 +251,7 @@ public class SpatialMatrix { * right of the given object. */ public synchronized List rightOf(int objectId) { - int index = findHorizontalIndexFor(objectId) + 1; + int index = findHorizontalIndexFor(objectId, true); return new ArrayList<>(horizontal.subList(index, horizontal.size())); } @@ -240,7 +271,7 @@ public class SpatialMatrix { * above the given object. */ public synchronized List above(int objectId) { - int index = findVerticalIndexFor(objectId); + int index = findVerticalIndexFor(objectId, false); return new ArrayList<>(vertical.subList(0, index)); } @@ -260,7 +291,7 @@ public class SpatialMatrix { * the given object. */ public synchronized List below(int objectId) { - int index = findVerticalIndexFor(objectId) + 1; + int index = findVerticalIndexFor(objectId, true); return new ArrayList<>(vertical.subList(index, vertical.size())); }