Commit f1f1e80c authored by Eric Tobias's avatar Eric Tobias

Fixed issue with left and right space getters being out of range

parent b2d45017
......@@ -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<TangibleObject> 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<TangibleObject> 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<TangibleObject> 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<TangibleObject> below(int objectId) {
int index = findVerticalIndexFor(objectId) + 1;
int index = findVerticalIndexFor(objectId, true);
return new ArrayList<>(vertical.subList(index, vertical.size()));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment