sdr 0.21

net.cscott.sdr.calls
Class Rotation

java.lang.Object
  extended by net.cscott.sdr.calls.Rotation
Direct Known Subclasses:
ExactRotation

public class Rotation
extends Object

Rotations are represented as fractions, where '0' is facing north, 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.
 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.
 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).
 String toString()
          Returns a human-readable description of the rotation.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

amount

public final Fraction amount
The amount of the rotation.


modulus

public final Fraction modulus
The 'modulus' of the rotation: indicates the amount of uncertainty in the direction. The modulus cannot exceed 1.

Constructor Detail

Rotation

protected Rotation(Fraction amount,
                   Fraction modulo)
Private constructor from a Fraction object.

Method Detail

create

public static final Rotation create(Fraction amount,
                                    Fraction modulo)

isExact

public boolean isExact()
Return true iff this rotation is exact (that is, if the modulus is one).


add

public Rotation add(Fraction f)
Add the given amount to this rotation direction.


subtract

public Rotation subtract(Fraction f)
Subtract the given amount from this rotation direction.


negate

public Rotation negate()
Negate this rotation (mirror image).


normalize

public Rotation normalize()
Normalize rotation to the range 0-modulus.


equals

public boolean equals(Object o)
Rotations are equal iff their normalized rotation amount and modulus are exactly equal.

Overrides:
equals in class Object

hashCode

public int hashCode()
Hashcode of the normalized amount & modulus.

Overrides:
hashCode in class Object

includes

public 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. 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.


toString

public String toString()
Returns a human-readable description of the rotation. The output is a valid input to ExactRotation.valueOf(String).

Overrides:
toString in class Object

toAbsoluteString

public String toAbsoluteString()
Returns a human-readable description of the rotation, similar to the input to ExactRotation.fromAbsoluteString(String).


fromAbsoluteString

public static Rotation fromAbsoluteString(String s)
Converts a string (one of n/s/e/w, ne/nw/se/sw) to the appropriate rotation object. 'n' is facing the caller. The string '-' means "east or west", and the string '|' means "north or south". The string "+" means "north, south, east, or west". The string 'o' means "any rotation".


sdr 0.21

Copyright (c) 2006 C. Scott Ananian