From edd4e1301a0c6eb97167e03da1f6ae3aa104affd Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Thu, 5 Mar 2015 12:37:00 +0100 Subject: Updated final version according to feedback --- Week4/src/oo15loipe/Loipe.java | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'Week4/src/oo15loipe') diff --git a/Week4/src/oo15loipe/Loipe.java b/Week4/src/oo15loipe/Loipe.java index 3ac4fd9..9155988 100644 --- a/Week4/src/oo15loipe/Loipe.java +++ b/Week4/src/oo15loipe/Loipe.java @@ -38,8 +38,27 @@ public class Loipe implements InfoLoipe { * @param pad */ public Loipe (String pad) { + setLoipe(pad); + } + + /** + * Refresh everything based on a new path + * + * @param pad + */ + public final void setLoipe(String pad) { + setWidthAndHeight(pad); + fillLoipe(pad); - // First calculate width and height + path_pointer = 0; + } + + /** + * Set the width and height of the loipe based on a path + * + * @param pad + */ + private void setWidthAndHeight(String pad) { int direction = DIRECTION_NORTH; int maxX = 0, maxY = 0, minX = 0, minY = 0; @@ -83,13 +102,21 @@ public class Loipe implements InfoLoipe { height = maxY - minY + 1; width = maxX - minX + 1; - start = new Punt(-minX, -minY); - // Now fill the Loipe + start = new Punt(-minX, -minY); + } + + /** + * Fill the loipe with fragments based on a path. + * Assumes the width, height and start attributes to be correct. + * + * @param pad + */ + private void fillLoipe(String pad) { loipe = new Fragment[width + 1][height + 1]; path = new Punt[pad.length()]; - current_point = start; - direction = DIRECTION_NORTH; + Punt current_point = start; + int direction = DIRECTION_NORTH; for (int i = 0; i < pad.length(); i++) { path[i] = current_point; -- cgit v1.2.3