Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhendriks committed Oct 16, 2016
1 parent 46d26f4 commit 3d18f6c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import com.fundynamic.d2tm.game.entities.Entity;
import com.fundynamic.d2tm.game.entities.Predicate;
import com.fundynamic.d2tm.math.Coordinate;
import com.fundynamic.d2tm.math.Rectangle;

/**
Expand All @@ -20,7 +21,10 @@ public EntityIsWithinAreaOfAbsoluteCoordinates(Rectangle rectangle) {

@Override
public boolean test(Entity entity) {
return rectangle.isVectorWithin(entity.getCenteredCoordinate());
Coordinate centered = entity.getCenteredCoordinate();
boolean result = rectangle.isVectorWithin(centered);
// System.out.println("Checking if entity @ [" + centered.getXAsInt() + "," + centered.getYAsInt() + "] is within " + rectangle + " -> " + result);
return result;
}

@Override
Expand Down
9 changes: 2 additions & 7 deletions src/main/java/com/fundynamic/d2tm/math/Rectangle.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public int getHeightAsInt() {

public boolean isVectorWithin(Vector2D vec) {
boolean result = vec.getX() >= topLeft.getX() && vec.getX() < bottomRight.getX() && vec.getY() >= topLeft.getY() && vec.getY() < bottomRight.getY();
// System.out.println("Testing if " + vec + " is within " + this + " --> " + result);
// System.out.println("Testing if " + vec.getXAsInt() + "," + vec.getYAsInt() + " is within " + this + " --> " + result);
return result;
}

Expand All @@ -61,11 +61,6 @@ public Vector2D getSize() {

@Override
public String toString() {
return "Rectangle{" +
"width=" + width +
", height=" + height +
", topLeft=" + topLeft +
", bottomRight=" + bottomRight +
'}';
return "Rectangle [@ " + topLeft.getXAsInt() + ", " + topLeft.getYAsInt() + " -> WXH " + (topLeft.getXAsInt() + width) + " X " + (topLeft.getYAsInt() + height) + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class EntitiesSetTest extends AbstractD2TMTest {
private int playerOneBareEntitiesCount;
private int destroyers;
private int moveableUnitsOfPlayerOne;
private Coordinate topLeftFirstQuad;

@Before
public void setUp() throws SlickException {
Expand All @@ -37,13 +38,14 @@ public void setUp() throws SlickException {
entitiesSet = new EntitiesSet();

player = new Player("Player one", Recolorer.FactionColor.GREEN);
Player playerTwo = new Player("Player two", Recolorer.FactionColor.RED);

// player one has 4 units and 2 structures
entitiesSet.add(makeUnit(player, Coordinate.create(320, 320), "QUAD"));
entitiesSet.add(makeUnit(player, Coordinate.create(384, 320), "QUAD"));
entitiesSet.add(makeUnit(player, Coordinate.create(320, 384), "QUAD"));
entitiesSet.add(makeUnit(player, Coordinate.create(960, 960), "QUAD"));
topLeftFirstQuad = Coordinate.create(320, 320);
entitiesSet.add(makeUnit(player, topLeftFirstQuad, "QUAD"));
entitiesSet.add(makeUnit(player, topLeftFirstQuad.add(Coordinate.create(64, 0)), "QUAD"));
entitiesSet.add(makeUnit(player, topLeftFirstQuad.add(Coordinate.create(0, 64)), "QUAD"));
entitiesSet.add(makeUnit(player, topLeftFirstQuad.add(Coordinate.create(640, 640)), "QUAD"));

playerOneUnitCount = 4;
moveableUnitsOfPlayerOne = 4;
destroyers = 4;
Expand All @@ -52,6 +54,8 @@ public void setUp() throws SlickException {
entitiesSet.add(makeStructure(player, 200));
playerOneStructureCount = 2;

Player playerTwo = new Player("Player two", Recolorer.FactionColor.RED);

// player two has 3 units and 3 structures
entitiesSet.add(makeUnit(playerTwo));
entitiesSet.add(makeUnit(playerTwo));
Expand Down Expand Up @@ -117,11 +121,13 @@ public void returnsThreeUnitsOfPlayerOneWithinRectangle() {
Set<Entity> result = entitiesSet.filter(
Predicate.builder().withinArea(
Rectangle.create(
Vector2D.create(319, 319),
Vector2D.create(385, 385)
topLeftFirstQuad.min(Coordinate.create(1,1)),
topLeftFirstQuad
.add(Coordinate.create(64, 64)) // topleft of quads area
.addHalfTile() // make sure we are at least over the center of the unit
.add(Coordinate.create(1,1))) // and over it
)
)
);
);
assertEquals(3, result.size());
}

Expand Down

0 comments on commit 3d18f6c

Please sign in to comment.