Skip to content

Commit

Permalink
Add javadoc comments for OsuPixels.java and UnitTesting.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Althoumb committed Apr 4, 2018
1 parent cce2968 commit 90d5eba
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 15 deletions.
39 changes: 35 additions & 4 deletions src/game/OsuPixels.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand All @@ -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();
Expand Down
31 changes: 20 additions & 11 deletions src/utils/UnitTesting.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>
* 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;
Expand Down

0 comments on commit 90d5eba

Please sign in to comment.