Clean up unused code

This commit is contained in:
Arne Keller 2020-03-05 21:15:07 +01:00
parent 672be521d7
commit 4dd3d872a2
4 changed files with 26 additions and 65 deletions

View File

@ -82,17 +82,22 @@ public abstract class Rail {
public abstract Vector2D getDirectionFrom(Vector2D position);
/**
* Check whether a train can be placed on this rail in the specified direction.
* Check whether a train can be placed on this rail facing the specified direction.
*
* @param position train front position
* @param direction the normalized direction vector to check
* @return whether a train can be placed on this rail facing that direction
*/
public abstract boolean allowsPlacement(Vector2D position, Vector2D direction);
/**
* Check whether a train can be move on this rail in the specified direction.
*
* @param position start position
* @param direction the normalized direction vector to check
* @return whether a train can be placed on this rail in that direction
* @return whether a train can move on this rail in the direction
*/
public abstract boolean allowsDirectionFrom(Vector2D position, Vector2D direction);
public abstract boolean allowsPlacementInDirection(Vector2D position, Vector2D direction);
public abstract boolean allowsMovementInDirection(Vector2D position, Vector2D direction);
public abstract boolean allowsMovement(Vector2D position, Vector2D direction);
/**
* Move a position along this rail in the specified direction for the specified amount of steps. This method will

View File

@ -100,47 +100,14 @@ public final class Switch extends Rail {
}
@Override
public boolean allowsDirectionFrom(Vector2D position, Vector2D direction) {
/*
if (positionOne.connectsTo(position) && positionTwo.connectsTo(position)) {
// trying to connect to start position
final boolean a = selection.allowsDirectionFrom(position, direction);
final boolean b = (selection == positionOne && positionTwo.allowsDirectionFrom(position, direction.negated()));
final boolean c = (selection == positionTwo && positionOne.allowsDirectionFrom(position, direction.negated()));
return a || b || c;
} else {
return selection.allowsDirectionFrom(position, direction);
}
*/
/*
if (selection != null) {
if (positionOne.connectsTo(position) && positionTwo.connectsTo(position)) {
return positionOne.allowsDirectionFrom(position, direction)
|| positionTwo.allowsDirectionFrom(position, direction)
|| selection.allowsDirectionFrom(position, direction.negated());
}
return selection.allowsDirectionFrom(position, direction)
|| selection.allowsDirectionFrom(position, direction.negated());
} else {
return (positionOne.connectsTo(position) && positionOne.allowsDirectionFrom(position, direction))
|| (positionTwo.connectsTo(position) && positionTwo.allowsDirectionFrom(position, direction));
}
*/
return (selection != null && selection.contains(position))
|| (positionOne.connectsTo(position) && positionOne.allowsDirectionFrom(position, direction))
|| (positionTwo.connectsTo(position) && positionTwo.allowsDirectionFrom(position, direction));
public boolean allowsPlacement(Vector2D position, Vector2D direction) {
return selection.allowsPlacement(position, direction);
}
@Override
public boolean allowsPlacementInDirection(Vector2D position, Vector2D direction) {
return selection.allowsPlacementInDirection(position, direction);
}
@Override
public boolean allowsMovementInDirection(Vector2D position, Vector2D direction) {
return positionOne.allowsMovementInDirection(position, direction)
|| positionTwo.allowsMovementInDirection(position, direction);
public boolean allowsMovement(Vector2D position, Vector2D direction) {
return positionOne.allowsMovement(position, direction)
|| positionTwo.allowsMovement(position, direction);
}
@Override

View File

@ -109,23 +109,13 @@ public final class Track extends Rail {
}
@Override
public boolean allowsDirectionFrom(Vector2D position, Vector2D direction) {
if (connectsTo(position)) {
return getDirectionFrom(position).negated().equals(direction);
} else if (contains(position)) {
return getDirectionFrom(position).isParallelTo(direction);
}
return false;
}
@Override
public boolean allowsPlacementInDirection(Vector2D position, Vector2D direction) {
public boolean allowsPlacement(Vector2D position, Vector2D direction) {
return contains(position) && getDirectionFrom(position).isParallelTo(direction)
|| connectsTo(position) && getDirectionFrom(position).negated().equals(direction);
}
@Override
public boolean allowsMovementInDirection(Vector2D position, Vector2D direction) {
public boolean allowsMovement(Vector2D position, Vector2D direction) {
return contains(position) && getDirectionFrom(position).isParallelTo(direction)
|| connectsTo(position) && getDirectionFrom(position).equals(direction);
}

View File

@ -3,7 +3,6 @@ package edu.kit.informatik.model;
import edu.kit.informatik.ui.InvalidInputException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
@ -158,20 +157,20 @@ public final class Train {
final Rail[] touchingRails = railNetwork.findTouchingRails(position);
if (touchingRails.length == 0) {
if (!railNetwork.findContainingRail(position)
.map(rail -> rail.allowsPlacementInDirection(position, direction))
.map(rail -> rail.allowsPlacement(position, direction))
.orElse(false)) {
return false;
}
} else if (touchingRails.length == 1) {
if (!(touchingRails[0].allowsPlacementInDirection(position, direction)
|| touchingRails[0].allowsMovementInDirection(position, direction))) {
if (!(touchingRails[0].allowsPlacement(position, direction)
|| touchingRails[0].allowsMovement(position, direction))) {
return false;
}
} else if (touchingRails.length == 2
&& !touchingRails[0].allowsPlacementInDirection(position, direction)
&& !touchingRails[1].allowsPlacementInDirection(position, direction)
&& !(touchingRails[0].allowsMovementInDirection(position, direction)
|| touchingRails[1].allowsMovementInDirection(position, direction))) {
&& !touchingRails[0].allowsPlacement(position, direction)
&& !touchingRails[1].allowsPlacement(position, direction)
&& !(touchingRails[0].allowsMovement(position, direction)
|| touchingRails[1].allowsMovement(position, direction))) {
return false;
}
final Set<Rail> occupiedRailsSet = new HashSet<>();