From: SourceForge.net <no...@so...> - 2007-11-18 21:17:41
|
Bugs item #1834145, was opened at 2007-11-18 19:23 Message generated for change (Comment added) made by martinfuchs You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=101111&aid=1834145&group_id=1111 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None >Status: Closed >Resolution: Fixed Priority: 5 Private: No Submitted By: Hendrik (nhnb) Assigned to: Martin Fuchs (martinfuchs) Summary: Entity.nextTo changed in version 1.95 seem strange Initial Comment: Old Code: public boolean nextTo(Entity entity, double step) { Rectangle2D thisArea = getArea(); Rectangle2D otherArea = entity.getArea(); thisArea.setRect(thisArea.getX() - step, thisArea.getY() - step, thisArea.getWidth() + step, thisArea.getHeight() + step); otherArea.setRect(otherArea.getX() - step, otherArea.getY() - step, otherArea.getWidth() + step, otherArea.getHeight() + step); return thisArea.intersects(otherArea); } New Code: public boolean nextTo(Entity entity, double step) { Rectangle2D thisArea = getArea(); Rectangle2D otherArea = entity.getArea(); thisArea.setRect(thisArea.getX(), thisArea.getY(), thisArea.getWidth() + step, thisArea.getHeight() + step); otherArea.setRect(otherArea.getX(), otherArea.getY(), otherArea.getWidth() + step, otherArea.getHeight() + step); return thisArea.intersects(otherArea); } The new code seems to ignore the upper left area. ---------------------------------------------------------------------- >Comment By: Martin Fuchs (martinfuchs) Date: 2007-11-18 22:17 Message: Logged In: YES user_id=1534223 Originator: NO I added an explanatory comment to the nextTo() function to make clear how the algorithm works. ---------------------------------------------------------------------- Comment By: Martin Fuchs (martinfuchs) Date: 2007-11-18 22:17 Message: Logged In: YES user_id=1534223 Originator: NO Thanks you for your time on submitting this bug! Please checkout the new CVS, this bug has been fixed. If you are not satisfied with the solution, please reopen the bug. ---------------------------------------------------------------------- Comment By: Hendrik (nhnb) Date: 2007-11-18 21:47 Message: Logged In: YES user_id=990499 Originator: YES File Added: diagram.pdf ---------------------------------------------------------------------- Comment By: Hendrik (nhnb) Date: 2007-11-18 21:39 Message: Logged In: YES user_id=990499 Originator: YES What are those four coordinates x1, y1, x2 and y2 based on? We compare the distance here of two objects which consists of two points each. So we have 4 points total. ---------------------------------------------------------------------- Comment By: Martin Fuchs (martinfuchs) Date: 2007-11-18 19:41 Message: Logged In: YES user_id=1534223 Originator: NO Hendrik, if you look at the mathematical formuala you will see the subtraction of "step" on all four coordinates x1, y1, x2 and y2 is redundant: The distance is calcualted by looking at abs(x1-x2) and abs(y1-y2), so you get exactly the same result as for abs((x1-step)-(x2-step)) and abs((y1-step)-(y2-step)) ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=101111&aid=1834145&group_id=1111 |