The final restructured version for automatic build using maven tycho
[Mograsim.git] / plugins / net.mograsim.logic.model / src / net / mograsim / logic / model / model / components / Orientation.java
1 package net.mograsim.logic.model.model.components;
2
3 /**
4  * For components that can have different orientations. The meaning is not clearly defined, however it is common that the orientation
5  * denotes the direction the output is facing or the general flow of signals. <code>_ALT</code> represents an alternative, which is normally
6  * a mirrored version. A component can choose to not support some variants.
7  * <p>
8  * In terms of calculation, {@link #RIGHT} is considered the default.
9  * <p>
10  * Note that this needs to be interpreted using the GUI coordinate system, meaning that UP and DOWN are swapped.
11  * 
12  * @author Christian Femers
13  */
14 public enum Orientation
15 {
16         /**
17          * The orientation <code>RIGHT</code> is the default orientation, all others are defined relative to it.
18          */
19         RIGHT(1, 0, 0, 1), LEFT(-1, 0, 0, -1), UP(0, 1, -1, 0), DOWN(0, -1, 1, 0), RIGHT_ALT(1, 0, 0, -1), LEFT_ALT(-1, 0, 0, 1),
20         UP_ALT(0, -1, -1, 0), DOWN_ALT(0, 1, 1, 0);
21
22         // simple 2D transformation matrix
23         final double trans11;
24         final double trans12;
25         final double trans21;
26         final double trans22;
27
28         private Orientation(double trans11, double trans12, double trans21, double trans22)
29         {
30                 this.trans11 = trans11;
31                 this.trans12 = trans12;
32                 this.trans21 = trans21;
33                 this.trans22 = trans22;
34         }
35
36         /**
37          * Performs a simple rotation around the origin. This does not work for the display coordinate system.
38          * 
39          * @return the point's new X coordinate
40          */
41         public double getNewX(double rightX, double rightY)
42         {
43                 return rightX * trans11 + rightY * trans12;
44         }
45
46         /**
47          * Performs a simple rotation around the origin. This does not work for the display coordinate system.
48          * 
49          * @return the point's new Y coordinate
50          */
51         public double getNewY(double rightX, double rightY)
52         {
53                 return rightX * trans21 + rightY * trans22;
54         }
55
56         public boolean doesMirror()
57         {
58                 return ordinal() > 3;
59         }
60
61         public boolean swapsWidthAndHeight()
62         {
63                 return trans11 == 0;
64         }
65 }