|
sdr 0.3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.cscott.sdr.calls.Position
public class Position
Position objects represent the position and orientation of a dancer.
The (0,0) coordinate represents the center of the square (or formation),
and dancers
are nominally at least two units away from each other (although breathing
may change this). A zero rotation for 'facing direction' means
"facing away from the caller". Positive y is "away from the caller". Positive
x is "toward the caller's right". The boy in couple number one
starts out at (-1, -3)
facing 0
.
The facing
field may not be null
;
to indicate "rotation unspecified" (for example, for phantoms
or when specifying "general lines") use a Rotation
with a
modulus of 0.
Field Summary | |
---|---|
Rotation |
facing
Facing direction. |
Fraction |
x
Location. |
Fraction |
y
Location. |
Constructor Summary | |
---|---|
Position(Fraction x,
Fraction y,
Rotation facing)
Create a Position object from the given x and y coordinates and Rotation . |
|
Position(int x,
int y,
Rotation facing)
Create a Position object with integer-valued x and y coordinates. |
Method Summary | |
---|---|
int |
compareTo(Position p)
Compare two Position s. |
boolean |
equals(Object o)
|
Position |
forwardStep(Fraction distance)
Move the given distance in the facing direction. |
static Position |
getGrid(int x,
int y,
ExactRotation r)
Returns a position corresponding to the standard square dance grid. 0,0 is the center of the set, and odd coordinates between -3 and 3 correspond to the standard 4x4 grid. |
static Position |
getGrid(int x,
int y,
String direction)
Returns a position corresponding to the standard square dance grid. 0,0 is the center of the set, and odd coordinates between -3 and 3 correspond to the standard 4x4 grid. |
int |
hashCode()
|
Position |
normalize()
Normalize (restrict to 0-modulus) the rotation of the given position. |
Position |
rotateAroundOrigin(ExactRotation rot)
Rotate this position around the origin by the given amount. |
Position |
sideStep(Fraction distance)
Move the given distance perpendicular to the facing direction. |
String |
toString()
|
Position |
turn(Fraction amount)
Turn in place the given amount. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public final Fraction x
public final Fraction y
public final Rotation facing
facing
should always be an
ExactRotation
for real (non-phantom) dancers.
Constructor Detail |
---|
public Position(Fraction x, Fraction y, Rotation facing)
Rotation
.
public Position(int x, int y, Rotation facing)
Method Detail |
---|
public Position forwardStep(Fraction distance)
facing
direction be an
ExactRotation
.
js> importPackage(net.cscott.sdr.util) js> Position.getGrid(-1,-3,"n").forwardStep(Fraction.TWO) -1,-1,0
public Position sideStep(Fraction distance)
facing
direction be an
ExactRotation
.
js> importPackage(net.cscott.sdr.util) js> Position.getGrid(-1,-3,"n").sideStep(Fraction.mONE) -2,-3,0
js> importPackage(net.cscott.sdr.util) js> Position.getGrid(3,1,"w").sideStep(Fraction.ONE) 3,2,3/4
public Position turn(Fraction amount)
js> ONE_HALF = net.cscott.sdr.util.Fraction.ONE_HALF 1/2 js> p = Position.getGrid(0,0,"n").turn(ONE_HALF) 0,0,1/2 js> p = p.turn(ONE_HALF) 0,0,1
public Position rotateAroundOrigin(ExactRotation rot)
js> p = Position.getGrid(-1,-3,0) -1,-3,0 js> p.rotateAroundOrigin(ExactRotation.ONE_QUARTER) -3,1,1/4
public Position normalize()
js> importPackage(net.cscott.sdr.util) js> p = Position.getGrid(0,0,"e").turn(Fraction.ONE_HALF) 0,0,3/4 js> p = p.turn(Fraction.ONE_HALF) 0,0,1 1/4 js> p.normalize() 0,0,1/4
public static Position getGrid(int x, int y, ExactRotation r)
js> Position.getGrid(0,0,ExactRotation.ZERO) 0,0,0 js> Position.getGrid(-3,3,ExactRotation.WEST) -3,3,3/4
public static Position getGrid(int x, int y, String direction)
ExactRotation.valueOf(String)
.
js> Position.getGrid(0,0,"n") 0,0,0 js> Position.getGrid(1,2,"e") 1,2,1/4
public boolean equals(Object o)
equals
in class Object
public int hashCode()
hashCode
in class Object
public String toString()
toString
in class Object
public int compareTo(Position p)
Position
s. We use reading order: top to bottom,
then left to right. Ties are broken by facing direction: first
the most specific rotation modulus, then by normalized direction.
compareTo
in interface Comparable<Position>
js> Position.getGrid(0,0,"n").compareTo(Position.getGrid(1,1,"n")) > 0 true
js> Position.getGrid(1,0,"n").compareTo(Position.getGrid(0,0,"n")) > 0 true
js> new Position["(int,int,net.cscott.sdr.calls.Rotation)"]( > 0,0,Rotation.fromAbsoluteString("|") > ).compareTo(Position.getGrid(0,0,"n")) > 0 true
js> Position.getGrid(0,0,"e").compareTo(Position.getGrid(0,0,"n")) > 0 true
js> Position.getGrid(1,2,"w").compareTo(Position.getGrid(1,2,"w")) == 0 true
|
sdr 0.3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |