From b89d29aac2eed38a0696eb2d81876e5c817f9327 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Mon, 2 May 2011 02:00:50 +0200 Subject: Refactored model to conform to the requested metrics git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@59 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/model/StoneTray.java | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'src/jrummikub/model/StoneTray.java') diff --git a/src/jrummikub/model/StoneTray.java b/src/jrummikub/model/StoneTray.java index ff32153..0d48bf5 100644 --- a/src/jrummikub/model/StoneTray.java +++ b/src/jrummikub/model/StoneTray.java @@ -69,19 +69,8 @@ public class StoneTray implements for (Pair i : objects) { Position currentPosition = i.getSecond(); E currentObject = i.getFirst(); - // Tests if position is left of, above ... the current object - if (position.getX() + object.getWidth() <= currentPosition.getX()) { - continue; - } - if (position.getY() + object.getHeight() <= currentPosition.getY()) { - continue; - } - if (position.getX() >= currentPosition.getX() - + currentObject.getWidth()) { - continue; - } - if (position.getY() >= currentPosition.getY() - + currentObject.getHeight()) { + if (!objectsOverlap(object, position, + currentObject, currentPosition)) { continue; } // Object would be placed inside the current object @@ -114,6 +103,27 @@ public class StoneTray implements objects.add(new Pair(object, position)); } + /** Tests whether two objects overlap **/ + private boolean objectsOverlap(E object1, Position position1, E object2, + Position position2) { + // Tests if position is left of, above ... the current object + if (position1.getX() + object1.getWidth() <= position2.getX()) { + return false; + } + if (position1.getY() + object1.getHeight() <= position2.getY()) { + return false; + } + if (position1.getX() >= position2.getX() + + object2.getWidth()) { + return false; + } + if (position1.getY() >= position2.getY() + + object2.getHeight()) { + return false; + } + return true; + } + private Direction getMoveDirection(E object, Position position, Pair blocking) { boolean isVertical = getMoveOrientationn(object, position, blocking); -- cgit v1.2.3