From 860d31d8fb5735da9ed347733ac017b81d4b8272 Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Wed, 4 Mar 2020 20:17:03 +0100 Subject: [PATCH] Recompute train direction when needed --- src/edu/kit/informatik/model/Train.java | 20 ++----------------- .../kit/informatik/model/TrainManager.java | 2 -- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/src/edu/kit/informatik/model/Train.java b/src/edu/kit/informatik/model/Train.java index 86631c6..2b9f573 100644 --- a/src/edu/kit/informatik/model/Train.java +++ b/src/edu/kit/informatik/model/Train.java @@ -31,10 +31,6 @@ public final class Train { * positions when moving the train. */ private LinkedList position; - /** - * Direction of the train head. - */ - private Vector2D direction; /** * Set of rails this train occupies. */ @@ -197,7 +193,6 @@ public final class Train { }).collect(Collectors.toSet()); this.position = positions; - this.direction = rawDirection.normalized(); this.occupiedRails = occupiedRailsSet; return true; @@ -207,7 +202,7 @@ public final class Train { * @return whether this train is placed on a rail network */ public boolean isPlaced() { - return position != null && direction != null && occupiedRails != null; + return position != null && occupiedRails != null; } /** @@ -250,7 +245,7 @@ public final class Train { */ public Vector2D getDirection() { // make sure caller can not modify internal state - return new Vector2D(direction); + return position.get(0).subtract(position.get(1)); } /** @@ -341,22 +336,11 @@ public final class Train { } // else: only touching new rail } - /** - * Update the direction of this train. - * - * @param newDirection new direction of the train - */ - public void setDirection(final Vector2D newDirection) { - // make sure the caller can not modify internal data afterwards - direction = new Vector2D(newDirection); - } - /** * Remove this train from the rail network. */ public void removeFromRails() { position = null; - direction = null; occupiedRails = null; } diff --git a/src/edu/kit/informatik/model/TrainManager.java b/src/edu/kit/informatik/model/TrainManager.java index 9ec9326..bb3cb9f 100644 --- a/src/edu/kit/informatik/model/TrainManager.java +++ b/src/edu/kit/informatik/model/TrainManager.java @@ -280,7 +280,6 @@ public final class TrainManager { collisions.add(new HashSet<>(Arrays.asList(train))); } else { train.moveTo(railNetwork, nextPosition); - train.setDirection(direction); } }); getStaticCollisions(collisions); @@ -306,7 +305,6 @@ public final class TrainManager { collisions.add(new HashSet<>(Arrays.asList(train))); } else { train.moveBackTo(railNetwork, nextPosition); - train.setDirection(front.subtract(train.getFrontPosition())); } }); getStaticCollisions(collisions);