|
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.Formation
public class Formation
A Formation is a set of dancers and positions for them. Certain dancers in the formation can be selected. In addition, all dancers can be tagged with modifiers such as 'BEAU', 'BELLE', 'LEADER', 'TRAILER', etc.
Field Summary | |
---|---|
static Map<Dancer,String> |
dancerNames
Map from StandardDancer s to 2-character dancer representations. |
static Formation |
FOUR_SQUARE
Starting formation for 2-couple dancing. |
protected Map<Dancer,Position> |
location
|
protected Set<Dancer> |
selected
|
static Formation |
SQUARED_SET
Starting formation for 8-couple dancing. |
Constructor Summary | |
---|---|
|
Formation(Formation f,
Map<Dancer,Dancer> map)
|
|
Formation(Map<Dancer,Position> location)
|
protected |
Formation(Map<Dancer,Position> location,
Set<Dancer> selected)
|
Method Summary | |
---|---|
Box |
bounds()
Return the bounds of this formation, which is the bounding box around all the dancers' bounding boxes. |
Box |
bounds(Dancer d)
Return the bounds of the given dancer -- always its position plus or minus 1 unit on the x and y axes. |
Comparator<Dancer> |
dancerComparator()
Return a Dancer Comparator that compares dancers
based on their positions within this Formation . |
Set<Dancer> |
dancers()
|
boolean |
equals(Object o)
|
int |
hashCode()
|
boolean |
isCentered()
Return true if the given formation is centered at the origin. |
boolean |
isSelected(Dancer d)
Return true iff the given dancer is selected. |
Position |
location(Dancer d)
|
Formation |
onlySelected()
Create a new formation containing only the selected dancers from this formation. |
Formation |
recenter()
Build a new formation, centered on 0,0. |
Formation |
rotate(ExactRotation rotation)
Build a new formation, like this one except rotated around 0,0. |
Formation |
select(Set<Dancer> s)
Build a new formation with only the given dancers selected. |
Set<Dancer> |
selectedDancers()
|
String |
toString()
|
String |
toStringDiagram()
Return an ascii-art diagram of this formation. |
String |
toStringDiagram(String prefix,
Map<Dancer,String> dancerNames)
Return an ascii-art diagram of this formation, using a custom mapping from Dancer s to 2-character strings. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected final Map<Dancer,Position> location
protected final Set<Dancer> selected
public static final Map<Dancer,String> dancerNames
StandardDancer
s to 2-character dancer representations.
js> Formation.dancerNames.get(StandardDancer.COUPLE_1_BOY) 1B js> Formation.dancerNames.get(StandardDancer.COUPLE_4_GIRL) 4G
public static final Formation SQUARED_SET
js> Formation.SQUARED_SET.toStringDiagram() 3Gv 3Bv 4B> 2G< 4G> 2B< 1B^ 1G^
public static final Formation FOUR_SQUARE
js> Formation.FOUR_SQUARE.toStringDiagram() 3Gv 3Bv 1B^ 1G^
Constructor Detail |
---|
protected Formation(Map<Dancer,Position> location, Set<Dancer> selected)
public Formation(Map<Dancer,Position> location)
public Formation(Formation f, Map<Dancer,Dancer> map)
Method Detail |
---|
public Formation onlySelected()
js> importPackage(java.util) js> f = Formation.SQUARED_SET ; undefined js> sides = [d for each (d in Iterator(f.dancers())) if (d.isSide())] COUPLE 2 BOY,COUPLE 2 GIRL,COUPLE 4 BOY,COUPLE 4 GIRL js> f2 = f.select(new LinkedHashSet(Arrays.asList(sides))).onlySelected() net.cscott.sdr.calls.Formation@4fce71[ location={COUPLE 2 BOY=3,-1,3/4, COUPLE 2 GIRL=3,1,3/4, COUPLE 4 BOY=-3,1,1/4, COUPLE 4 GIRL=-3,-1,1/4} selected=[COUPLE 2 BOY, COUPLE 2 GIRL, COUPLE 4 BOY, COUPLE 4 GIRL] ] js> f2.toStringDiagram() 4B> 2G< 4G> 2B<
public boolean isSelected(Dancer d)
js> importPackage(java.util) js> f = Formation.SQUARED_SET ; undefined js> heads = [d for each (d in Iterator(f.dancers())) if (d.isHead())] COUPLE 1 BOY,COUPLE 1 GIRL,COUPLE 3 BOY,COUPLE 3 GIRL js> sides = [d for each (d in Iterator(f.dancers())) if (d.isSide())] COUPLE 2 BOY,COUPLE 2 GIRL,COUPLE 4 BOY,COUPLE 4 GIRL js> f2 = f.select(new LinkedHashSet(Arrays.asList(sides))); undefined js> [f2.isSelected(d) for each (d in sides)] true,true,true,true js> [f2.isSelected(d) for each (d in heads)] false,false,false,false
public Set<Dancer> selectedDancers()
public Set<Dancer> dancers()
public Position location(Dancer d)
public Box bounds()
bounds(Dancer)
applies here
as well. If there are no dancers, returns a zero-width,
zero-height box centered at the origin.
js> Formation.SQUARED_SET.bounds() -4,-4,4,4 js> Formation.SQUARED_SET.select(java.util.Collections.EMPTY_SET).onlySelected().bounds() 0,0,0,0
public Box bounds(Dancer d)
public Formation select(Set<Dancer> s)
js> importPackage(java.util) js> f = Formation.SQUARED_SET ; undefined js> heads = [d for each (d in Iterator(f.dancers())) if (d.isHead())] COUPLE 1 BOY,COUPLE 1 GIRL,COUPLE 3 BOY,COUPLE 3 GIRL js> f2 = f.select(new LinkedHashSet(Arrays.asList(heads))) net.cscott.sdr.calls.Formation@12a0f6c[ location={COUPLE 1 BOY=-1,-3,0, COUPLE 1 GIRL=1,-3,0, COUPLE 2 BOY=3,-1,3/4, COUPLE 2 GIRL=3,1,3/4, COUPLE 3 BOY=1,3,1/2, COUPLE 3 GIRL=-1,3,1/2, COUPLE 4 BOY=-3,1,1/4, COUPLE 4 GIRL=-3,-1,1/4} selected=[COUPLE 1 BOY, COUPLE 1 GIRL, COUPLE 3 BOY, COUPLE 3 GIRL] ]
public Formation recenter()
js> importPackage(java.util) js> couple1 = [StandardDancer.COUPLE_1_BOY, StandardDancer.COUPLE_1_GIRL] COUPLE 1 BOY,COUPLE 1 GIRL js> f = Formation.SQUARED_SET.select(new LinkedHashSet(Arrays.asList(couple1))).onlySelected() net.cscott.sdr.calls.Formation@a31e1b[ location={COUPLE 1 BOY=-1,-3,0, COUPLE 1 GIRL=1,-3,0} selected=[COUPLE 1 BOY, COUPLE 1 GIRL] ] js> f.isCentered() false js> f = f.recenter() net.cscott.sdr.calls.Formation@1b3f829[ location={COUPLE 1 BOY=-1,0,0, COUPLE 1 GIRL=1,0,0} selected=[COUPLE 1 BOY, COUPLE 1 GIRL] ] js> f.isCentered() true
public Formation rotate(ExactRotation rotation)
rotation
parameter;
"north" corresponds to no rotation.
js> Formation.SQUARED_SET.rotate(ExactRotation.ONE_QUARTER).toStringDiagram() 4Gv 4Bv 1B> 3G< 1G> 3B< 2B^ 2G^
js> Formation.SQUARED_SET.rotate(ExactRotation.ONE_EIGHTH).toStringDiagram() 4BQ 3GL 4GQ 3BL 1B7 2G` 1G7 2B`
public boolean isCentered()
js> Formation.SQUARED_SET.isCentered() true
public Comparator<Dancer> dancerComparator()
Dancer
Comparator
that compares dancers
based on their positions within this Formation
.
public boolean equals(Object o)
equals
in class Object
public int hashCode()
hashCode
in class Object
public String toString()
toString
in class Object
public String toStringDiagram()
"1B^ 1Gv \n" " \n" "3B^ 3Gv "Note that the return value has no trailing \n.
public String toStringDiagram(String prefix, Map<Dancer,String> dancerNames)
Dancer
s to 2-character strings. Each line
of the diagram is preceded with the specified prefix.
Note that the return value has no trailing \n.
toStringDiagram()
js> m = java.util.LinkedHashMap() {} js> for (i in Iterator(StandardDancer.values())) { > m.put(i[1], String.fromCharCode(65+i[0],65+i[0])) > } null js> Formation.SQUARED_SET.toStringDiagram("|", m) | FFv EEv | |GG> DD< | |HH> CC< | | AA^ BB^
|
sdr 0.3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |