View Javadoc

1   package net.sf.josceleton.core.api.entity;
2   
3   import java.util.Collections;
4   import java.util.HashMap;
5   import java.util.Map;
6   
7   
8   /**
9    * @since 0.4
10   */
11  public final class CoordinateUtil {
12  
13  	private static final float LOWER_LIMIT_XYZ = 0.0F;
14  	
15  	private static final Map<XyzDirection, Float> UPPER_LIMITS;
16  	static {
17  		final Map<XyzDirection, Float> tmp = new HashMap<XyzDirection, Float>();
18  		final Float upperLimitXy = Float.valueOf(1.0F);
19  		final Float upperLimitZ = Float.valueOf(7.0F);
20  		tmp.put(XyzDirection.X, upperLimitXy);
21  		tmp.put(XyzDirection.Y, upperLimitXy);
22  		tmp.put(XyzDirection.Z, upperLimitZ);
23  		UPPER_LIMITS = Collections.unmodifiableMap(tmp);
24  	}
25  	
26  	private CoordinateUtil() {
27  		// utility class is not instantiable
28  	}
29  	
30  	/**
31  	 * @since 0.4
32  	 */
33  	public static int prettyPrint(final Coordinate coordinate, final XyzDirection direction) {
34  		final float rawValue;
35  		
36  		if(direction == XyzDirection.X) {
37  			rawValue = coordinate.x();
38  		} else if(direction == XyzDirection.Y) {
39  			rawValue = coordinate.y();
40  		} else { // there should be no 4th dimension in the near future ;)
41  			rawValue = coordinate.z();
42  		}
43  		
44  		return Math.round(rawValue * 100);
45  	}
46  	
47  	public static boolean isCorrectValue(final float value, final XyzDirection direction) {
48  		return value >= LOWER_LIMIT_XYZ && value <= UPPER_LIMITS.get(direction).floatValue();
49  	}
50  	
51  	public static String getCorrectValueLabel(final XyzDirection direction) {
52  		return "[" + LOWER_LIMIT_XYZ + "-" + UPPER_LIMITS.get(direction) + "]";
53  	}
54  	
55  }