From 90d5eba1cfdc43411988a52ed55f541a2d2122ac Mon Sep 17 00:00:00 2001 From: s-ballw Date: Wed, 4 Apr 2018 13:17:24 -0700 Subject: [PATCH] Add javadoc comments for OsuPixels.java and UnitTesting.java --- src/game/OsuPixels.java | 39 ++++++++++++++++++++++++++++++++++---- src/utils/UnitTesting.java | 31 +++++++++++++++++++----------- 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/src/game/OsuPixels.java b/src/game/OsuPixels.java index 819a00a..70c6066 100644 --- a/src/game/OsuPixels.java +++ b/src/game/OsuPixels.java @@ -3,13 +3,24 @@ import org.newdawn.slick.GameContainer; import org.newdawn.slick.geom.Vector2f; +/** + * + * @author William Ball + * + */ public class OsuPixels { /** - * Converts osupixels to display coordinates + * Converts a vector containing osupixel coordinates to a vector containing + * display coordinates. * * @param gc + * The game container, used to find the dimensions of the game + * window. * @param osupixels - * @return + * The vector, in osupixel coordinates, to be converted to display + * coordinates. + * @return Returns a vector containing the converted display coordinates of the + * osupixel coordinate vector. */ public Vector2f osuPixeltoXY(GameContainer gc, Vector2f osupixels) { float newx = osupixels.x; @@ -32,11 +43,17 @@ public Vector2f osuPixeltoXY(GameContainer gc, Vector2f osupixels) { } /** - * Converts display coordinates to osupixels + * Converts a vector containing display coordinates to a vector containing + * osupixel coordinates. * * @param gc + * The game container, used to find the dimensions of the game + * window. * @param XYpixels - * @return + * The vector, in display coordinates, to be converted to osupixel + * coordinates. + * @return Returns a vector containing the converted osupixel coordinates of the + * display coordinate vector. */ public Vector2f XYtoOsuPixel(GameContainer gc, Vector2f convertedvector) { float scalefactor = (float) (1.0 / getScaleFactor(gc)); @@ -59,6 +76,20 @@ public Vector2f XYtoOsuPixel(GameContainer gc, Vector2f convertedvector) { return vector; } + /** + * Determines the scale factor to use when converting osupixel coordinates to + * display coordinates. + * + * @param gc + * The game container, used to find the dimensions of the game + * window. + * @return If the screen width to screen height ratio is greater than that of a + * 640x480px display, returns the float ratio between the screen height + * and the height of a 640x480px display. If the screen width to screen + * height ratio is less than that of a 640x480px display, returns the + * float ratio between the screen width and that of a 640x480px display. + * + */ protected float getScaleFactor(GameContainer gc) { int screenheight = gc.getHeight(); int screenwidth = gc.getWidth(); diff --git a/src/utils/UnitTesting.java b/src/utils/UnitTesting.java index 0f38ef6..8befca7 100644 --- a/src/utils/UnitTesting.java +++ b/src/utils/UnitTesting.java @@ -5,23 +5,32 @@ import game.OsuPixels; +/** + * + * @author William Ball + * + */ public class UnitTesting { /** - * Using the GameContainer, tests if OsuPixels returns the right vectors. - * + * Tests if OsuPixels returns the right vectors. + *

+ * Goes through all possible osupixel coordinate values, and converts them to + * display coordinates and back. + * * @param gc - * @return + * The game container, used for osupixel conversion. + * @return Returns whether or not the test was successful. */ public boolean testOsuPixels(GameContainer gc) { OsuPixels osupixelconverter = new OsuPixels(); - for (int i = 0; i < 100; i++) { - int x = (int) (Math.random() * 512); - int y = (int) (Math.random() * 384); - Vector2f test = new Vector2f(x, y); - test = osupixelconverter.osuPixeltoXY(gc, test); - test = osupixelconverter.XYtoOsuPixel(gc, test); - if ((int) test.x != x || (int) test.y != y) { - return false; + for (int x = 0; x <= 512; x++) { + for (int y = 0; y <= 384; y++) { + Vector2f test = new Vector2f(x, y); + test = osupixelconverter.osuPixeltoXY(gc, test); + test = osupixelconverter.XYtoOsuPixel(gc, test); + if ((int) test.x != x || (int) test.y != y) { + return false; + } } } return true;