mirror of
https://gitlab.com/arnekeller/kit-programmieren-ws1920-final1.git
synced 2024-11-24 01:15:05 +00:00
Checkstyle
This commit is contained in:
parent
4dd3d872a2
commit
ea15f218cb
@ -28,8 +28,8 @@ public final class Switch extends Rail {
|
|||||||
* Construct a new switch.
|
* Construct a new switch.
|
||||||
*
|
*
|
||||||
* @param start start position
|
* @param start start position
|
||||||
* @param end1 end position 1
|
* @param end1 first end position
|
||||||
* @param end2 end position 2
|
* @param end2 second end position
|
||||||
* @param id identifier of this switch
|
* @param id identifier of this switch
|
||||||
* @throws InvalidInputException if the switch is not composed of straight lines
|
* @throws InvalidInputException if the switch is not composed of straight lines
|
||||||
*/
|
*/
|
||||||
@ -46,8 +46,7 @@ public final class Switch extends Rail {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean connectsTo(Vector2D point) {
|
public boolean connectsTo(Vector2D point) {
|
||||||
return (positionOne.canConnectTo(point) && positionTwo.canConnectTo(point))
|
return selection != null && selection.canConnectTo(point);
|
||||||
|| (selection != null && selection.canConnectTo(point));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -74,10 +73,7 @@ public final class Switch extends Rail {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(Vector2D position) {
|
public boolean contains(Vector2D position) {
|
||||||
if (selection == null) {
|
return selection != null && selection.contains(position);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return selection.contains(position);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -143,7 +143,7 @@ public final class Train {
|
|||||||
*/
|
*/
|
||||||
public boolean placeOn(RailwayNetwork railNetwork, Vector2D position, Vector2D rawDirection) {
|
public boolean placeOn(RailwayNetwork railNetwork, Vector2D position, Vector2D rawDirection) {
|
||||||
if (isPlaced()) {
|
if (isPlaced()) {
|
||||||
return false;
|
return false; // do not place a train that is already placed
|
||||||
}
|
}
|
||||||
final Vector2D direction = rawDirection.normalized();
|
final Vector2D direction = rawDirection.normalized();
|
||||||
final Vector2D positioningDirection = direction.negated();
|
final Vector2D positioningDirection = direction.negated();
|
||||||
@ -159,22 +159,23 @@ public final class Train {
|
|||||||
if (!railNetwork.findContainingRail(position)
|
if (!railNetwork.findContainingRail(position)
|
||||||
.map(rail -> rail.allowsPlacement(position, direction))
|
.map(rail -> rail.allowsPlacement(position, direction))
|
||||||
.orElse(false)) {
|
.orElse(false)) {
|
||||||
return false;
|
return false; // containing rail is orthogonal to the requested direction
|
||||||
}
|
}
|
||||||
} else if (touchingRails.length == 1) {
|
} else if (touchingRails.length == 1) {
|
||||||
if (!(touchingRails[0].allowsPlacement(position, direction)
|
if (!(touchingRails[0].allowsPlacement(position, direction)
|
||||||
|| touchingRails[0].allowsMovement(position, direction))) {
|
|| touchingRails[0].allowsMovement(position, direction))) {
|
||||||
return false;
|
return false; // rail is orthogonal to the requested direction
|
||||||
}
|
}
|
||||||
} else if (touchingRails.length == 2
|
} else if (!touchingRails[0].allowsPlacement(position, direction)
|
||||||
&& !touchingRails[0].allowsPlacement(position, direction)
|
|
||||||
&& !touchingRails[1].allowsPlacement(position, direction)
|
&& !touchingRails[1].allowsPlacement(position, direction)
|
||||||
&& !(touchingRails[0].allowsMovement(position, direction)
|
&& !(touchingRails[0].allowsMovement(position, direction)
|
||||||
|| touchingRails[1].allowsMovement(position, direction))) {
|
|| touchingRails[1].allowsMovement(position, direction))) {
|
||||||
|
// rail network does not allow this direction according to
|
||||||
|
// https://ilias.studium.kit.edu/goto.php?client_id=produktiv&target=frm_996924_139143_534378
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Set<Rail> occupiedRailsSet = new HashSet<>();
|
final Set<Rail> occupiedRailsSet = new HashSet<>();
|
||||||
while (length > 0) {
|
while (length > 0) { // while part of the train still needs to be placed
|
||||||
rollingStockPosition = railNetwork.move(rollingStockPosition, positioningDirection, length);
|
rollingStockPosition = railNetwork.move(rollingStockPosition, positioningDirection, length);
|
||||||
if (rollingStockPosition == null) {
|
if (rollingStockPosition == null) {
|
||||||
// derailed
|
// derailed
|
||||||
@ -182,7 +183,7 @@ public final class Train {
|
|||||||
}
|
}
|
||||||
final long distanceToLastPosition = positionList.getLast().distanceTo(rollingStockPosition);
|
final long distanceToLastPosition = positionList.getLast().distanceTo(rollingStockPosition);
|
||||||
if (distanceToLastPosition == 0) {
|
if (distanceToLastPosition == 0) {
|
||||||
// stuck
|
// stuck at end of rail
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user