Skip to content

Commit

Permalink
F Transform any Position onto the Path of a Shape. #1 remove old method
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominic authored and Dominic committed Apr 25, 2020
1 parent 680a7b8 commit 22b0d48
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 18 deletions.
21 changes: 14 additions & 7 deletions Moveable/src/com/myownb3/piranha/grid/gridelement/shape/Shape.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,22 @@ public interface Shape {
boolean detectObject(Position detectorPosition, Detector detector);

/**
* Returns the {@link Position} placed on the path which is equivalent to the
* given Position. That means the position to return faces the same direction.
* Returns the {@link Position} of this {@link GridElement} which faces the same
* direction than it's center {@link Position} but is placed on it's
* {@link Shape}
*
* @param position
* the given {@link Position}
* @return the {@link Position} placed on the path which is equivalent to the
* given Position
* @return the {@link Position} of this {@link GridElement}
*/
Position getFurthermostFrontPosition();

/**
* Returns the {@link Position} of this {@link GridElement} which faces the oposit
* direction than it's center {@link Position} but is placed on it's
* {@link Shape}
*
* @return the {@link Position} of this {@link GridElement}
*/
Position getPositionOnPathFor(Position position);
Position getFurthermostBackPosition();

/**
* Transform this shape according the new {@link Position}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.myownb3.piranha.detector.collision.CollisionDetectionHandler;
import com.myownb3.piranha.grid.Grid;
import com.myownb3.piranha.grid.gridelement.position.Position;
import com.myownb3.piranha.grid.gridelement.position.Positions;
import com.myownb3.piranha.grid.gridelement.shape.AbstractShape;
import com.myownb3.piranha.grid.gridelement.shape.Shape;
import com.myownb3.piranha.grid.gridelement.shape.position.PositionShape;
Expand Down Expand Up @@ -81,14 +80,12 @@ public Position getPosition() {

@Override
public Position getFurthermostFrontPosition() {
return shape.getPositionOnPathFor(position);
return shape.getFurthermostFrontPosition();
}

@Override
public Position getFurthermostBackPosition() {
Position posInverted = Positions.of(position);
posInverted.rotate(180);
return shape.getPositionOnPathFor(posInverted);
return shape.getFurthermostBackPosition();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,15 @@ public void transform(Position position) {
}

@Override
public Position getPositionOnPathFor(Position position) {
return getNextCirclePos(position, radius, 0);
public Position getFurthermostFrontPosition() {
return getNextCirclePos(center, radius, 0);
}

@Override
public Position getFurthermostBackPosition() {
Position posInverted = Positions.of(center);
posInverted.rotate(180);
return getNextCirclePos(posInverted, radius, 0);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ public void transform(Position position) {
}

@Override
public Position getPositionOnPathFor(Position position) {
public Position getFurthermostBackPosition() {
return getPosition();
}

@Override
public Position getFurthermostFrontPosition() {
return getPosition();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void testCheck4Collision_CheckRadius() {
}

@Test
void testGetPositionOnPathFor() {
void testGetFurthermostFrontPosition() {
// Given
int amountOfPoints = 4;
int radius = 5;
Expand All @@ -142,12 +142,33 @@ void testGetPositionOnPathFor() {
.build();

// When
Position positionOnPathFor = circle.getPositionOnPathFor(center);
Position positionOnPathFor = circle.getFurthermostFrontPosition();

// Then
assertThat(positionOnPathFor.getDirection(), is(center.getDirection()));
}

@Test
void testGetFurthermostBackPosition() {
// Given
int amountOfPoints = 4;
int radius = 5;
Position center = Positions.of(0, 0);
center.rotate(45);
Circle circle = new CircleBuilder(radius)
.withAmountOfPoints(amountOfPoints)
.withCenter(center)
.build();

// When
Position positionOnPathFor = circle.getFurthermostBackPosition();

// Then
Position centerInverted = Positions.of(center);
centerInverted.rotate(180);
assertThat(positionOnPathFor.getDirection(), is(centerInverted.getDirection()));
}

@Test
void testGetPositionOnPathForReverted() {
// Given
Expand All @@ -161,7 +182,7 @@ void testGetPositionOnPathForReverted() {

// When
center.rotate(167);
Position positionOnPathFor = circle.getPositionOnPathFor(center);
Position positionOnPathFor = circle.getFurthermostFrontPosition();

// Then
assertThat(positionOnPathFor.getDirection(), is(center.getDirection()));
Expand Down

0 comments on commit 22b0d48

Please sign in to comment.