1 package net.mograsim.logic.model.model.components;
4 * This class simplifies the calculation of coordinates, especially for GUI components.
6 * Supply it with the original width and height and an orientation, and use the methods {@link #newX(double, double)} and
7 * {@link #newY(double, double)} to retrieve the new coordinates, relative to the upper left corner of {@link Orientation#RIGHT}. The
8 * {@link #height()} and {@link #width()} methods return the width and height in the new orientation.
10 * This is meant to be used in the context of a a classic display coordinate system, as done in the {@link GUIComponent}s.
13 * @author Christian Femers
15 public class OrientationCalculator
18 final double oldWHalf;
19 final double oldHHalf;
25 public OrientationCalculator(Orientation o, double width, double height)
28 this.oldWHalf = width / 2;
29 this.oldHHalf = height / 2;
31 if (o.swapsWidthAndHeight())
47 * Returns the new height (that equals the old width if {@link Orientation#swapsWidthAndHeight()} is true)
49 public double height()
55 * Returns the new width (that equals the old height if {@link Orientation#swapsWidthAndHeight()} is true)
62 public double newX(double x, double y)
64 return (x - oldWHalf) * o.trans11 + (y - oldHHalf) * o.trans12 + wHalf;
67 public double newY(double x, double y)
69 return (x - oldWHalf) * o.trans21 + (y - oldHHalf) * o.trans22 + hHalf;
72 public final Orientation getOrientation()