|
sdr 0.7 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.cscott.sdr.calls.Rotation net.cscott.sdr.calls.ExactRotation
public class ExactRotation
Rotations are represented as fractions, where '0' is facing north (away from the caller), and '1/4' is facing east. Positive denotes clockwise rotation.
Field Summary | |
---|---|
static ExactRotation |
EAST
Common absolute rotations. |
static ExactRotation |
FIVE_EIGHTHS
Common rotations. |
static ExactRotation |
mONE_QUARTER
Common rotations. |
static ExactRotation |
NORTH
Common absolute rotations. |
static ExactRotation |
ONE
Common rotations. |
static ExactRotation |
ONE_EIGHTH
Common rotations. |
static ExactRotation |
ONE_HALF
Common rotations. |
static ExactRotation |
ONE_QUARTER
Common rotations. |
static ExactRotation |
SEVEN_EIGHTHS
Common rotations. |
static ExactRotation |
SOUTH
Common absolute rotations. |
static ExactRotation |
THREE_EIGHTHS
Common rotations. |
static ExactRotation |
THREE_QUARTERS
Common rotations. |
static ExactRotation |
WEST
Common absolute rotations. |
static ExactRotation |
ZERO
Common rotations. |
Fields inherited from class net.cscott.sdr.calls.Rotation |
---|
amount, modulus |
Constructor Summary | |
---|---|
ExactRotation(Fraction amount)
Constructor from a Fraction object. |
Method Summary | |
---|---|
ExactRotation |
add(Fraction f)
Add the given amount to this rotation direction. |
int |
compareTo(ExactRotation r)
Compare unnormalized rotation amounts. |
static ExactRotation |
fromAbsoluteString(String s)
Converts a string (one of n/s/e/w, ne/nw/se/sw) to the appropriate rotation object. |
static ExactRotation |
fromRelativeString(String s)
Returns a ExactRotation corresponding to one of the strings "right", "left", or "none". |
static ExactRotation |
fromXY(Fraction x,
Fraction y)
Convert an x/y displacement to a rotation, using our 'squared off' circle. |
boolean |
isExact()
Return true iff this rotation is exact (that is, if the modulus is one). |
Fraction |
minSweep(ExactRotation er)
Compute the minimum angle (in absolute value) between this
heading and the given heading er . |
ExactRotation |
negate()
Negate this rotation (mirror image). |
ExactRotation |
normalize()
Normalize rotation to the range [0, 1). |
String |
repr()
Return an executable representation of this Rotation . |
ExactRotation |
subtract(Fraction f)
Subtract the given amount from this rotation direction. |
String |
toAbsoluteString()
Returns a human-readable description of the rotation. |
char |
toDiagramChar()
Convert rotation to an appropriate ascii-art representation. |
String |
toRelativeString()
Returns a human-readable description of the rotation. |
String |
toString()
Returns a human-readable description of the rotation. |
Fraction |
toX()
Return the X offset of a one-unit step in the rotation direction. |
Fraction |
toY()
Return the Y offset of a one-unit step in the rotation direction. |
Methods inherited from class net.cscott.sdr.calls.Rotation |
---|
create, equals, hashCode, included, includes, union, union |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final ExactRotation mONE_QUARTER
public static final ExactRotation ZERO
public static final ExactRotation ONE_EIGHTH
public static final ExactRotation ONE_QUARTER
public static final ExactRotation THREE_EIGHTHS
public static final ExactRotation ONE_HALF
public static final ExactRotation FIVE_EIGHTHS
public static final ExactRotation THREE_QUARTERS
public static final ExactRotation SEVEN_EIGHTHS
public static final ExactRotation ONE
public static final ExactRotation NORTH
public static final ExactRotation EAST
public static final ExactRotation SOUTH
public static final ExactRotation WEST
Constructor Detail |
---|
public ExactRotation(Fraction amount)
Fraction
object.
Method Detail |
---|
public boolean isExact()
Rotation
isExact
in class Rotation
public ExactRotation add(Fraction f)
add
in class Rotation
public ExactRotation subtract(Fraction f)
subtract
in class Rotation
public ExactRotation negate()
negate
in class Rotation
public ExactRotation normalize()
normalize
in class Rotation
public int compareTo(ExactRotation r)
compareTo
in interface Comparable<ExactRotation>
public Fraction minSweep(ExactRotation er)
this
heading and the given heading er
. The result is positive or
negative, and can be added to this heading to yield a rotation
equivalent to the given heading er
.
js> ExactRotation.ONE_EIGHTH.minSweep(ExactRotation.SEVEN_EIGHTHS); -1/4 js> ExactRotation.SEVEN_EIGHTHS.minSweep(ExactRotation.ONE_EIGHTH); 1/4
public String toAbsoluteString()
ExactRotation.fromAbsoluteString(String)
.
toAbsoluteString
in class Rotation
public String toRelativeString()
ExactRotation.fromAbsoluteString(String)
.
public static ExactRotation fromAbsoluteString(String s)
public String repr()
Rotation
Rotation
.
repr
in class Rotation
public static ExactRotation fromRelativeString(String s)
s
-
IllegalArgumentException
- if s is not one of "right", "left",
"none", or a number.public Fraction toX()
toY()
js> importPackage(net.cscott.sdr.util); js> for (n=-8; n<20; n++) { > er = new ExactRotation(Fraction.valueOf(n, 16)); > print("toX("+er+")="+er.toX().toProperString()); > }; undefined toX(-1/2)=0 toX(-7/16)=-1/2 toX(-3/8)=-1 toX(-5/16)=-1 toX(-1/4)=-1 toX(-3/16)=-1 toX(-1/8)=-1 toX(-1/16)=-1/2 toX(0)=0 toX(1/16)=1/2 toX(1/8)=1 toX(3/16)=1 toX(1/4)=1 toX(5/16)=1 toX(3/8)=1 toX(7/16)=1/2 toX(1/2)=0 toX(9/16)=-1/2 toX(5/8)=-1 toX(11/16)=-1 toX(3/4)=-1 toX(13/16)=-1 toX(7/8)=-1 toX(15/16)=-1/2 toX(1)=0 toX(1 1/16)=1/2 toX(1 1/8)=1 toX(1 3/16)=1
public Fraction toY()
toX()
js> importPackage(net.cscott.sdr.util); js> for (n=-8; n<20; n++) { > er = new ExactRotation(Fraction.valueOf(n, 16)); > print("toY("+er+")="+er.toY().toProperString()); > }; undefined toY(-1/2)=-1 toY(-7/16)=-1 toY(-3/8)=-1 toY(-5/16)=-1/2 toY(-1/4)=0 toY(-3/16)=1/2 toY(-1/8)=1 toY(-1/16)=1 toY(0)=1 toY(1/16)=1 toY(1/8)=1 toY(3/16)=1/2 toY(1/4)=0 toY(5/16)=-1/2 toY(3/8)=-1 toY(7/16)=-1 toY(1/2)=-1 toY(9/16)=-1 toY(5/8)=-1 toY(11/16)=-1/2 toY(3/4)=0 toY(13/16)=1/2 toY(7/8)=1 toY(15/16)=1 toY(1)=1 toY(1 1/16)=1 toY(1 1/8)=1 toY(1 3/16)=1/2
public static ExactRotation fromXY(Fraction x, Fraction y)
public String toString()
Rotation
ExactRotation.valueOf(String)
.
toString
in class Rotation
public char toDiagramChar()
toDiagramChar
in class Rotation
js> function c2s(c) { return String.fromCharCode(c) } js> [c2s(r.toDiagramChar()) for each (r in > [ExactRotation.NORTH, ExactRotation.EAST, > ExactRotation.SOUTH, ExactRotation.WEST])] ^,>,v,< js> [c2s(r.toDiagramChar()) for each (r in > [ExactRotation.ONE_EIGHTH, ExactRotation.THREE_EIGHTHS, > ExactRotation.FIVE_EIGHTHS, ExactRotation.SEVEN_EIGHTHS])] 7,Q,L,` js> c2s(new ExactRotation(net.cscott.sdr.util.Fraction.valueOf(1,3)) > .toDiagramChar()) .
|
sdr 0.7 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |