Dear users, Please note that, from Monday, August 16, 2019, RSA keys shorter than 2048bit will no longer be accepted for security reasons. Please update your keys as needed before this date. If you need assistance with regard to this process, please contact sia@list.lu

Thank you for your understanding.

Commit d670fb8a authored by Nico Mack's avatar Nico Mack

Added withinBounds method to Point class

Added static ZERO_BOUNDS to Bounds2D class
parent 39e79fcb
......@@ -12,6 +12,8 @@ public class Bounds2D {
public static DecimalFormat format = new DecimalFormat();
public static final Bounds2D ZERO_BOUNDS = new Bounds2D(0, 0, 0, 0);
static {
format.setDecimalSeparatorAlwaysShown(false);
format.setMaximumFractionDigits(2);
......
......@@ -31,6 +31,9 @@ import lu.list.itis.dkd.dbc.annotation.NonNull;
* @version 2.3.0
*/
public class CameraCoordinates extends CoordinateState {
private static final Bounds2D BOUNDS = new Bounds2D(Calibration.getCameraLeft(), Calibration.getCameraTop(), Calibration.getTableWidth(), Calibration.getTableHeight());
/**
* Constructing an instance with the provided points.
*
......@@ -70,11 +73,15 @@ public class CameraCoordinates extends CoordinateState {
@Deprecated
public void toCamera(@NonNull Point context) {
/**
* The conversion is naught as the point's coordinates are already given in this reference
* scheme!
* The conversion is naught as the point's coordinates are already given in this reference scheme!
*/
}
@Override
public boolean withinBounds(Point context) {
return BOUNDS.includes(context);
}
/** {@inheritDoc} */
@Override
public Point normalize(Point context) {
......
......@@ -32,8 +32,7 @@ import lu.list.itis.dkd.dbc.annotation.NonNull;
public abstract class CoordinateState {
/**
* normalizes the coordinates of a given point with the respect to its current coordinate
* system.
* normalizes the coordinates of a given point with the respect to its current coordinate system.
*
* @param context
* point to convert in given coordinate state
......@@ -70,9 +69,9 @@ public abstract class CoordinateState {
}
/**
* Method used to transition coordinates from the current system to table coordinates. By
* default, unless overridden, the method does nothing. This method is deprecated. Use
* toCoordinates method instead.
* Method used to transition coordinates from the current system to table coordinates. By default,
* unless overridden, the method does nothing. This method is deprecated. Use toCoordinates method
* instead.
*
* @param context
* The context of the state; the feature the state gives meaning.
......@@ -82,9 +81,9 @@ public abstract class CoordinateState {
public abstract void toTable(@NonNull Point context);
/**
* Method used to transition coordinates from the current system to screen coordinates. By
* default, unless overridden, the method does nothing. This method is deprecated. Use
* toCoordinates method instead.
* Method used to transition coordinates from the current system to screen coordinates. By default,
* unless overridden, the method does nothing. This method is deprecated. Use toCoordinates method
* instead.
*
* @param context
* The context of the state; the feature the state gives meaning.
......@@ -94,9 +93,9 @@ public abstract class CoordinateState {
public abstract void toScreen(@NonNull Point context);
/**
* Method used to transition coordinates from the current system to camera coordinates. By
* default, unless overridden, the method does nothing. This method is deprecated. Use
* toCoordinates method instead.
* Method used to transition coordinates from the current system to camera coordinates. By default,
* unless overridden, the method does nothing. This method is deprecated. Use toCoordinates method
* instead.
*
* @param context
* The context of the state; the feature the state gives meaning.
......@@ -105,6 +104,16 @@ public abstract class CoordinateState {
@Deprecated
public abstract void toCamera(@NonNull Point context);
/**
* Checks whether the specified point is withing acceptable bounds.
*
* @param context
* @return <code>true</code> if specified point can be represented by this coordinate state,
* <code>false</code> otherwise
*/
public abstract boolean withinBounds(Point context);
/**
* Method testing for equality.
*
......
......@@ -33,6 +33,9 @@ import com.google.common.base.Preconditions;
* @version 2.3.0
*/
public class NormalizedCoordinates extends CoordinateState {
private static final Bounds2D BOUNDS = new Bounds2D(0, 0, 1, 1);
/**
* Constructing an instance with the provided points.
*
......@@ -76,6 +79,11 @@ public class NormalizedCoordinates extends CoordinateState {
toCoordinates(context, CameraCoordinates.class);
}
@Override
public boolean withinBounds(Point context) {
return BOUNDS.includes(context);
}
/** {@inheritDoc} */
@Override
public Point normalize(Point context) {
......
......@@ -571,6 +571,17 @@ public class Point extends Float implements Comparable<Point>, KdComparator<Poin
return comparison;
}
/**
* Checks whether the specified point is within the acceptable bounds of its coordinate state.
*
* @return <code>true</code> if specified point can be represented by this coordinate state,
* <code>false</code> otherwise
*/
public boolean withinBounds() {
return state.withinBounds(this);
}
}
......
......@@ -86,6 +86,12 @@ public class ScreenCoordinates extends CoordinateState {
context.setState(new CameraCoordinates(context, Calibration.screenToCameraX(context.x), Calibration.screenToCameraY(context.y)));
}
@Override
public boolean withinBounds(Point context) {
Bounds2D currentBounds = (bounds == null) ? FULL_SCREEN : bounds;
return currentBounds.includes(context);
}
/** {@inheritDoc} */
@Override
public Point normalize(Point context) {
......
......@@ -31,6 +31,9 @@ import lu.list.itis.dkd.dbc.annotation.NonNull;
* @version 2.3.0
*/
public class TableCoordinates extends CoordinateState {
private static final Bounds2D BOUNDS = new Bounds2D(0, 0, Calibration.getTableWidth(), Calibration.getTableHeight());
/**
* Constructing an instance with the provided points.
*
......@@ -52,8 +55,7 @@ public class TableCoordinates extends CoordinateState {
@Deprecated
public void toTable(@NonNull Point context) {
/**
* The conversion is naught as the point's coordinates are already given in this reference
* scheme!
* The conversion is naught as the point's coordinates are already given in this reference scheme!
*/
}
......@@ -75,11 +77,16 @@ public class TableCoordinates extends CoordinateState {
context.setState(new CameraCoordinates(context, Calibration.tableToCameraX(context.x), Calibration.tableToCameraY(context.y)));
}
@Override
public boolean withinBounds(Point context) {
return BOUNDS.includes(context);
}
/** {@inheritDoc} */
@Override
public Point normalize(Point context) {
double normx = context.x / Calibration.getTableWidth();
double normy = context.y / Calibration.getTableHeight();
double normx = context.x / BOUNDS.getWidth();
double normy = context.y / BOUNDS.getHeight();
return new Point((float) normx, (float) normy, context.getAngle(), NormalizedCoordinates.class);
}
......@@ -90,8 +97,8 @@ public class TableCoordinates extends CoordinateState {
// Preconditions.checkArgument((normalized.x >= 0) && (normalized.x <= 1));
// Preconditions.checkArgument((normalized.y >= 0) && (normalized.y <= 1));
double tblx = (normalized.x * Calibration.getTableWidth());
double tbly = (normalized.y * Calibration.getTableHeight());
double tblx = (normalized.x * BOUNDS.getWidth());
double tbly = (normalized.y * BOUNDS.getHeight());
return new Point((float) tblx, (float) tbly, normalized.getAngle(), this.getClass());
}
......
......@@ -91,6 +91,11 @@ public class GraphCoordinates extends CoordinateState {
toCoordinates(context, CameraCoordinates.class);
}
@Override
public boolean withinBounds(Point context) {
return bounds.includes(context);
}
@Override
public Point normalize(Point context) {
double normx = ((context.x - bounds.x1) / bounds.getWidth());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment