|
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
public class Rotation
Rotations are represented as fractions, where '0' is facing north (that is, away from the caller), and '1/4' is facing east. The also have a 'modulus', since they can represent "general" directions. For example, "1/4 modulo 1/2" means facing east or west (but not north, south, or any other direction). A rotation modulo 0 matches any direction. A rotation modulo 1 indicates an 'exact' rotation; the modulus can not exceed 1.
Field Summary | |
---|---|
Fraction |
amount
The amount of the rotation. |
Fraction |
modulus
The 'modulus' of the rotation: indicates the amount of uncertainty in the direction. |
Constructor Summary | |
---|---|
protected |
Rotation(Fraction amount,
Fraction modulo)
Private constructor from a Fraction object. |
Method Summary | |
---|---|
Rotation |
add(Fraction f)
Add the given amount to this rotation direction. |
static Rotation |
create(Fraction amount,
Fraction modulo)
|
boolean |
equals(Object o)
Rotations are equal iff their normalized rotation amount and modulus are exactly equal. |
static Rotation |
fromAbsoluteString(String s)
Converts a string (one of n/s/e/w, ne/nw/se/sw) to the appropriate rotation object. |
int |
hashCode()
Hashcode of the normalized amount & modulus. |
Collection<ExactRotation> |
included()
Returns an Iterator over the ExactRotation s included
in this Rotation . |
boolean |
includes(Rotation r)
Returns true iff all the rotations possible with the given r
are included within the set of rotations possible with this . |
boolean |
isExact()
Return true iff this rotation is exact (that is, if the modulus is one). |
Rotation |
negate()
Negate this rotation (mirror image). |
Rotation |
normalize()
Normalize rotation to the range [0, modulus). |
String |
repr()
Return an executable representation of this Rotation . |
Rotation |
subtract(Fraction f)
Subtract the given amount from this rotation direction. |
String |
toAbsoluteString()
Returns a human-readable description of the rotation, similar to the input to ExactRotation.fromAbsoluteString(String) . |
char |
toDiagramChar()
Convert rotation to an appropriate ascii-art representation. |
String |
toString()
Returns a human-readable description of the rotation. |
static Rotation |
union(List<Rotation> rots)
|
Rotation |
union(Rotation r)
Return a Rotation which includes all the directions represented
by this and the specified Rotation . |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public final Fraction amount
public final Fraction modulus
Constructor Detail |
---|
protected Rotation(Fraction amount, Fraction modulo)
Fraction
object.
Method Detail |
---|
public static final Rotation create(Fraction amount, Fraction modulo)
public boolean isExact()
public Rotation add(Fraction f)
public Rotation subtract(Fraction f)
public Rotation negate()
public Rotation normalize()
public boolean equals(Object o)
equals
in class Object
public int hashCode()
hashCode
in class Object
public boolean includes(Rotation r)
r
are included within the set of rotations possible with this
.
For example, the Rotation 0 mod 1/4
(ie, north, east, south, or
west, but no intermediate directions) includes 3/4 mod 1
(ie, exactly west), but the reverse is not true: 3/4 mod 1
includes 7/4 mod 1
, but does not include 0 mod 1/4
.
Formally, returns true iff the congruence class of this
is
a superset of the congruence class of r
.
js> importPackage(net.cscott.sdr.util) js> r1 = Rotation.create(Fraction.ZERO, Fraction.ONE_QUARTER) 0 mod 1/4 js> r2 = Rotation.create(Fraction.THREE_QUARTERS, Fraction.ONE) 3/4 js> r3 = Rotation.create(Fraction.valueOf(7, 4), Fraction.ONE) 1 3/4 js> r1.includes(r2) true js> r2.includes(r1) false js> r2.includes(r3) true
public Collection<ExactRotation> included()
Iterator
over the ExactRotation
s included
in this Rotation
.
js> r = Rotation.fromAbsoluteString('+') 0 mod 1/4 js> [x for (x in Iterator(r.included()))] 0,1/4,1/2,3/4 js> r = Rotation.fromAbsoluteString('x') 1/8 mod 1/4 js> [x for (x in Iterator(r.included()))] 1/8,3/8,5/8,7/8
public Rotation union(Rotation r)
Rotation
which includes all the directions represented
by this
and the specified Rotation
. The operation may
be inexact; that is, the result may include directions which are
not included in either of the arguments.
js> ExactRotation.EAST.union(ExactRotation.WEST) 1/4 mod 1/2 js> ExactRotation.NORTH.union(ExactRotation.SOUTH) 0 mod 1/2 js> Rotation.fromAbsoluteString('|').union( > Rotation.fromAbsoluteString('-')) 0 mod 1/4
js> importPackage(net.cscott.sdr.util) // for Fraction js> ExactRotation.NORTH.union(ExactRotation.EAST) 0 mod 1/4 js> Rotation.fromAbsoluteString('|').union(ExactRotation.EAST) 0 mod 1/4 js> Rotation.create(Fraction.ONE_QUARTER, Fraction.ONE_HALF).union( > ExactRotation.SOUTH) 0 mod 1/4 js> Rotation.create(Fraction.ZERO, Fraction.ONE_HALF).union( > Rotation.create(Fraction.ZERO, Fraction.ONE_THIRD)) 0 mod 1/6 js> Rotation.create(Fraction.ZERO, Fraction.ONE_THIRD).union( > ExactRotation.SOUTH) 0 mod 1/6 js> Rotation.create(Fraction.ZERO, Fraction.ONE_THIRD).union( > Rotation.create(Fraction.ZERO, Fraction.ONE_QUARTER)) 0 mod 1/12 js> Rotation.create(Fraction.ONE_EIGHTH, Fraction.ONE_QUARTER).union( > ExactRotation.SOUTH) 0 mod 1/8
public static Rotation union(List<Rotation> rots)
public String toString()
ExactRotation.valueOf(String)
.
toString
in class Object
public String toAbsoluteString()
ExactRotation.fromAbsoluteString(String)
.
public static Rotation fromAbsoluteString(String s)
public char toDiagramChar()
js> function m(s) { > return String.fromCharCode(Rotation.fromAbsoluteString(s).toDiagramChar()) > } js> Array.map("|-+xo", m) |,-,+,x,o
js> importPackage(net.cscott.sdr.util) js> r = Rotation.create(Fraction.ZERO, Fraction.ONE_THIRD) 0 mod 1/3 js> String.fromCharCode(r.toDiagramChar()) .
public String repr()
Rotation
.
|
sdr 0.7 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |