Definitions

SquareDanceReasoning.AttendanceType
Attendance(::SDSquare)

Attendance is a fact in the knowledgebase that keeps track of how many DancerStates in a square are present.

This is necessary because tests like encroached_on can only provide a correct result if all of the DanecerStates are available for consideration.

When all of the Dancers of s set have DancerStates, then Attendance emits an AllPresent fact.

Note that Attendance contains mutable data - but once an Attendance is created, only the values in its present field are changed.

source
SquareDanceReasoning.BalanceType
Balance(; role=Everyone(), time=2)

Implements the Balance square dance call, except that dancers just jiggle in place. Maybe it should be renamed _Identify.

source
SquareDanceReasoning.BeforeEightChainType

BeforeEightChain is a formation of eight dancers (four couples) lined up, and is the starting formation for the "eight chain thru" call. It can result from doing "centers pass thru" from a FacingTandemCouples formation.

→←→←
→←→←
source
SquareDanceReasoning.BeforeTradeByType

BeforeTradeBy is a formation of eight dancers (four couples) lined up, and is the starting formation for the call "trade by". It can result from doing a "centers pass thru" from a BeforeEightChain formation.

←→←→
←→←→
source
SquareDanceReasoning.BoundsType
Bounds(dss::Vector{DancerState};
                    margin = COUPLE_DISTANCE / 2)

represents the bounding rectangle surrounding the specified DancerStates. If margin is 0 then Bounds surrounds just the centers of the dancers.

By default, margin is COUPLE_DISTANCE / 2 so that Bounds describes the space actually occupied by the dancers.

source
SquareDanceReasoning.CallScheduleType
CallSchedule(start_time)

CallSchedule maintains the schedule of the ScheduledCalls that are to be performed. The results of expand_parts are added to the schedule while calls are being executed. The call engine (see do_schedule) runs until the schedule is empty.

source
SquareDanceReasoning.CanDoCallType
CanDoCall(preference, call::SquareDanceCall, formation::SquareDanceFormation)

CanDoCall represents that call can be performed from formation, and doing so has the specified preference.

source
SquareDanceReasoning.CompletedDoublePassThruType

CompletedDoublePassThru is a formation of eight dancers (four couples) lined up, and is the ending formation for the call "double pass thru". It can result from doing a "centers pass thru" from a TradeBy formation.

←←→→
←←→→
source
SquareDanceReasoning.DancerStateType
DancerState(dancer, time, direction, down, left)
DancerState(previoous::DancerSTate, time, direction, down, left)

represents the location and facing direction of a single dancer at a moment in time.

time is a number defining a temporal ordering. It could represent a number of beats, for example.

DancerState is also the single dancer SquareDanceFormation.

source
SquareDanceReasoning.DosadoType
Dosado(; role=Everyone(), handedness=RightHanded())

CallerLab Basic1 call.

Timing: Callerlab: 6, unless coming from and returnuing to a squared set, in which case 8.

source
SquareDanceReasoning.FaceLeftType
FaceLeft(; role=Everyone(), time=2)

CallerLab Basic 1 square dance call causing dancers to turn 1/4 to their left. The timing defaults to 2 since, according to Taminations, two beats is the duration for QuarterIn and QuarterOut.

Timing: CallerLab does not soecify timing. Assume 1. Can be specified as a parameter.

source
SquareDanceReasoning.FaceRightType
FaceRight(; role=Everyone(), time=2)

CallerLab Basic 1 square dance call causing dancers to turn 1/4 to their right. The timing defaults to 2 since, according to Taminations, two beats is the duration for QuarterIn and QuarterOut.

Timing: CallerLab does not soecify timing. Assume 1. Can be specified as a parameter.

source
SquareDanceReasoning.FacingTandemCouplesType

FacingTandemCouples is a formation of eight dancers (four couples) lined up, and is the starting formation for the "double pass thru" call. This formation is more commonly known as "Double Pass Thru".

→→←←
→→←←
source
SquareDanceReasoning.GenderType

Gender represents the gender of a dancer, which might be Guy, Gal or Unspecified.

Unspecified exists for when we want to emphasize gender agnosticism in a diagram.

Gender equality: Guy() == Guy(), Gal() == Gal(), otherwise not equal.

Use opposite to get the opposite gender.

source
SquareDanceReasoning.HandednessType
Handedness

square dance formations have a handedness, one of RightHanded(), LeftHanded() or NoHandedness().

opposite of a handedness returns the other handedness. NoHandednessis its own opposite.

source
SquareDanceReasoning.ObverseRoleType
ObverseRole(::role)

For roles like CoupleNumbers or DesignatedDancers we can't determine the obverse until we know all of the dancers involved. This serves as a "place holder" until we can determine which dancers have the role that is obverse to the specified Role.

source
SquareDanceReasoning.PassThruType
PassThru(; role=Everyone())

CallerLab Basic 1 call.

Timing: CallerLab: 2.

PassThru is only proper from FaceToFace or from RHMiniWave (because of the "Ocean Wave Rule"). For LHMiniWave, use StepThru.

source
SquareDanceReasoning.PullByType
PullBy(; role=Everyone(), handedness=RightHanded())

CallerLab Basic 1 call.

Timing: CallerLab doesn't specify timing, but since the timing for PassThru is 2, assume the same for PullBy.

source
SquareDanceReasoning.RespiratorType
Respirator(::Vector{DancerState))

Respirator is a device for assisting breating. It performs the bookkeeping associed with tracking the current location of each dancer as adjusted by the breathing algorithm without creating new DancerStates.

source
SquareDanceReasoning.SDSquareType
SDSquare(dancers)

SDSquare represents the dancers in a square.

make_square(number_of_couples) will return an SDSquare.

SDSquare is a fact that can be asserted to the knowledge base to inform it that the dancers form a square.

other_dancers(::SDSquare, dancers) returns the set of Dancers that are in the SDSquare but are not in dancers.

source
SquareDanceReasoning.SquareDanceCallType
SquareDanceCall

For each call, a struct is defined that is a subtype of SquareDanceCall.

For each call and each formation it can be done from, a can_do_from method should be defined. If the "Ocean Wave Rule" applies, then a can_do_from method should be defined for that case.

For each call and each formation it can be performed from, either a perform or an expand_parts method should be defined.

source
SquareDanceReasoning.StarType

Star represents four dancers holding either right or left hands together in their center. All are facing either clockwise or counterclockwise.

source
SquareDanceReasoning.StepThruType
StepThru(; role=Everyone())

CallerLab Basic 1 square dance call that goes from MiniWave to BackToBack.

Timing: CallerLab doesn't spoecify a timing, but since the specified timing for PassThru is 2 and StepThru must be simpler, assume 1.

source
SquareDanceReasoning.StepToAWaveType
StepToAWave(; role=Everyone(), handedness=RightHanded())

CallerLab Basic 2 square dance call that goes from FaceToFace to a MiniWave of the specified handedness. The first half of PassThru.

Timing: 2.

source
SquareDanceReasoning.TandemType
Tandem(leaderLLDancerState, trailer::DancerState)

Tandem repreents a formation of two dancers where the trailer is facing the back of the leader.

source
SquareDanceReasoning.UnspecifiedType
Unspecified

Unspecified gender is provided just for gender neutral diagraming, where it appears as a square with rounded corners. It is not supported widely through this codebase. For example original partner and original corner are do not support it.

Note that

Unspecified() != Unspecified()

and

opposite(Unspecified())

returns Unspecified().

source
SquareDanceReasoning._BackToAWaveType
_BackToAWave(; role=Everyone(), handedness=RightHanded())

Primitive square dance call that goes from BackToBack to a MiniWave of the specified handedness. The third quarter of Dosado.

Timing: 1.

source
SquareDanceReasoning._EndAtType
_EndAt(f::TwoDancerFormation, time=0, swap=true)

Primitive square dance call that causes the dancer to end at the starting location of the other dancer.

If swap is false then the dancer ends in its own starting location instead of that of the other dancer.

source
SquareDanceReasoning._GenderedRollType
_GenderedRoll(; role=Everyone(), time=2)

The second part of calls like StarThru and SlideThru. Guy turn one quarter to the right, Gal turn one quarter to the left.

Timing: as specified in the parameter. Defaults to 2. CallerLab says the timing for StarThru is 4, so thisseems reasonable.

source
SquareDanceReasoning._MeetType
_Meet(; role=Everyone(), duration=0)

Facing dancers move forward until they are close together.

Consider a call like PassThru where the dancers might be close together or some distance apart (like in a squared set). PassThru uses _EndAt to put the dancers in each others previous locations. What if we want the Heads of a squared set to end up in the middle. We have the dancers _Meet first.

source
SquareDanceReasoning._RestType
_Rest(; role=Everyone(), time)

Primitive square dance call causing dancers to rest in place for the specified time.

Timing: as specified in the parameter.

source
Base.islessMethod
Base.isless(::Dancer, ::Dancer)::Bool

Provides a total ordering for dancers.

source
SquareDanceReasoning.animateMethod
animate(method::AnimationMethod, output_file, dancer_states; bpm=40)

Returns an SVG document fragment that animates the motion of the Dancers in dancer_states.

If output_file ends in ".svg" then the document fragment is written to that file. output_file is still needed so that the relative path to the dancer symbols file canbe determined.

dancer_states should have the most recent DancerState for each Dancer. the previous property of each DancerState is used to determine the Dancer's motion.

bpm or "beats per minute" provides a time scale for the animation. Assuming each unit of time in a DancerState is a single beat, bpm is used to calculate the total duration of one cycle through the animation.

source
SquareDanceReasoning.back_to_a_waveMethod
back_to_a_wave(f::BackToBack, time_delta, h::Union{RightHanded, LeftHanded})::FaceToFace

The back to back dancers back up to firm a miniwave of the specified handedness.

Breating should be done separately.

source
SquareDanceReasoning.backwardMethod
backward(ds::DancerState, distance, time_delta)::DancerState

Move the Dancer identified by ds backward (based on ds.direction) the specified distance by returning a new dancer state.

source
SquareDanceReasoning.breatheMethod
breathe(playmates::Vector{<:TwoDancerFormation}, everyone::Vector{DancerState})::Vector{DancerState}

Moves the dancers apart such that those that have collided no longer overlap.

playmates is used to inform what direction colliders should be moved in such that playmates are not separated.

everyone includes all DancerStates that are to be affected.

source
SquareDanceReasoning.bump_outMethod
bump_out(bounds::Bounds)

Returns a new Bounds object that is expanded by COUPLE_DISTANCE / 2 on each edge so that instead of encompassing the centers of each Dancer it encompasses whole dancers.

source
SquareDanceReasoning.call_schedule_islessMethod
call_schedule_isless(call1::ScqareDanceCall, call2::SquareDanceCall)

We need some way to control the scheduleing order of zero duration calls like _EndAt.

This is kind of a kludge but I've not thought of anything better.

source
SquareDanceReasoning.can_do_fromMethod

candofrom(::SquareDanceCall, ::SquareDanceFormation)::Int

Determins if the specified call can be performed from the specified formation. A return value of 0 means the call is not appropriate (or not currently supported). Otherwise the return value is a preference level with a higher value indicating more preferable. For example UTurnBack from Couple is more preferable to UTurnBack from DancerState, even though both would be applicable.

source
SquareDanceReasoning.can_rollMethod
can_roll(ds::DancerState)

Determine whether the modifier "and roll" can be applied to the DancerState. If the dancer can roll then can_roll returns a signed rotation value.

This is not useful for "and roll as if you could".

source
SquareDanceReasoning.collateral_file_relpathMethod
collateral_file_relpath(resource_name, html_file_destination)

Returns the path to the named resource in the environment of html_file_destination.

resource_name is one of the keys of HTML_COLLATERAL_FILES.

html_file_destination is the absolute path of the XML or HTML file that is referring to the resource.

source
SquareDanceReasoning.containment_graphMethod

containment_graph(kb::SDRKnowledgeBase, title, backend::ContainmentGraphBackend)

Visualizes the containment graph for the formations in kb.

title is a title for the graph. It might be used as the base of a file name.

backend says how to visualize the graph.

source
SquareDanceReasoning.copy_html_collateral_filesMethod
copy_html_collateral_files()

Copies each of the files identified in HTMLCOLLATERALFILES to each of the directories listed in TARGET_LOCATIONS.

SquareDanceReasoning writes XML and HTML files to various locations. Some of those locations are only accessible in certain circumstances. For example, The package source code hierarchy is not available to documentation foles delivered to the gh-pages branch. copy_html_collateral_files copies the files to where they might be needed. collateral_file_relpath is used to file the most appropriate

Use collateral_file_relpath to get the best reference location for a resource file.

source
SquareDanceReasoning.corner_couple_numberMethod
corner_couple_number(::Dancer)

Returns the couple number of the dancer's corner. Since this function has no way of knowing the number of daners in the "square", the value returned nmight require numeric rapping.

source
SquareDanceReasoning.directionFunction
direction(formation)

If all of the dancers of formation are facing in the same direction then return that direction. Otherwise get a no such method error.

source
SquareDanceReasoning.directionMethod
direction(focus, other)

returns the absolute direction that other is from the point of view of focus. Either argument can be a DancerState or a localtion represented as a two element Vector.

source
SquareDanceReasoning.do_callMethod
do_call(kb::SDRKnowledgeBase, call::SquareDanceCall; dbgctx = nothing)::SDRKnowledgeBase

Perform the specified square dance call and return an updated knowledgebase. do_call is the entry point into the call engine.

source
SquareDanceReasoning.eltMethod
elt(f, tagname::AbstractString, things...)
elt(tagname::AbstractString, things...)

Return an XML element. f is called with a single argument: either an XML.AbstractXMLNode or a Pair describing an XML attribute to be added to the resulting element.

source
SquareDanceReasoning.encroached_onMethod
encroached_on(formations, kb)

Returns true if any of the other contemporary DancerStates in the knowledge base are within the Bounds of the specified formations.

source
SquareDanceReasoning.expand_partsMethod
expand_parts(::SquareDanceCall, ::SquareDanceFormation, ::ScheduledCall)

Returns either the ScheduledCall itself, if it has no expansion, or a vector of a ScheduledCall for each part.

The ScheduledCall's when field is the starting time for the call. The pats in the expansion can have their times offset from that.

source
SquareDanceReasoning.formation_svgMethod
formation_svg(f::SquareDanceFormation, symbol_uri_base; id=nothing)

Returns an SVG element that illustrates the formation.

symbol_uri_base is a relative URL to the SVG symbols file. See collateral_file_relpath.

If id is specified, it will be the XML Id of the drawing.

If margin is specified, its the additional space that surrounds the formation.

source
SquareDanceReasoning.forwardMethod
forward(ds::DancerState, distance, time_delta)::DancerState

Move the Dancer identified by ds forward (based on ds.direction) the specified distance by returning a new dancer state.

source
SquareDanceReasoning.fractionMethod
fraction(tb::TimeBounds, t)

return where t falls within tb as a fraction. For t == tb.min the result would be 0. For t == tb.max the result would be 100.

source
SquareDanceReasoning.grid_arrangementMethod
 grid_arrangement(dancers::Vector{Dancer}, dancer_indices::Array{<:Integer, 2}, dancer_directions::Array{Rational, 2})

Returns a two dimensional array of DancerStates such that the dancers are arranged in a rectangular grid of the specified dimensions.

dancers is a vector of Dancers indexed by dancer_indices. A dancer index can be 0 to indicate that there is no dancer in that positriion.

dancer_indices and dancer_directions are Arrays of the same dimensions. This determiines the dimensions of the resulting grid.

Alternatively, dancer_directions can be a Vector of strings of the Unicode arrow characters ←, ↑, →, or ↓, with the space character serving as a placeholder where there is no dancer.

The two indices of each array correspond to the down and left coordinates respectively.

source
SquareDanceReasoning.in_boundsMethod
in_bounds(bounds::Bounds, ds::DancerState)::Bool

Returns true if the specified DancerState it located within bounds.

in_bounds(Bounds([ds]), ds) == true

source
SquareDanceReasoning.jitterMethod
jitter(ds::DancerState, time_delta)::DancerState

Adds noise to the position and facing direction of the DancerState. This allows us to test whether our formation recognition rules are sensitive to such noise.

source
SquareDanceReasoning.leftwardMethod
leftward(ds::DancerState, distance, time_delta)::DancerState

Move the Dancer identified by ds to the left (based on ds.direction) by the specified distance by returning a new dancer state.

source
SquareDanceReasoning.motion_for_collisionMethod
motion_for_collision(rsp::Respirator, collision, movement::Dict{Dancer, Vector})

Compute the motions required to resolve the specified collision and add it to movement. Does not apply those motions yet. movement is a Dict mapping Dancer to motion vector.

source
SquareDanceReasoning.nearMethod
near(::DancerState, ::DancerState)

returns true if the two DancerStates are for different dancers and are close enough together (within DANCERNEARDISTANCE).

source
SquareDanceReasoning.obverseFunction
obverse(::Role)::Role

Each role has an obverse role. (I didn't want to overload opposite). At a given time a dancer either has role or role's obverse.

source
SquareDanceReasoning.percentageMethod
percentage(tb::TimeBounds, t)

return where t falls within tb as a percentage. For t == tb.min the result would be 0. For t == tb.max the result would be 100.

source
SquareDanceReasoning.performFunction
perform(::SquareDanceCall, ::SquareDanceFormation, ::SDRKnowledgeBase)::SquareDanceFormation

Performs the call on the specified formation and returns the new formation.

source
SquareDanceReasoning.playmateFunction
playmate(ds::Dancer, f::TwoDancerFormation)::Union{Nothing, Dancer}

If the Dancer is part of the formation then return the other Dancer in the formation, otherwise return nothing.

source
SquareDanceReasoning.restricted_toMethod
restricted_to(call)::Role

Returns the role that call has been restricted to.

Each subtype of SquareDanceCall must have either a role field or a restricted_to method.

source
SquareDanceReasoning.revolveMethod
revolve(ds::DancerState, center, new_direction, time_delta)::DancerState

Revolves the Dancer identified by ds around center (a two element Vector of down and left coordinates) until the Dancer's new facing direction is new_direction. A new DancerState is returned. time_delta is the duration of the revolution operation.

source
SquareDanceReasoning.rightwardMethod
rightward(ds::DancerState, distance, time_delta)::DancerState

Move the Dancer identified by ds to the right (based on ds.direction) by the specified distance by returning a new dancer state.

source
SquareDanceReasoning.rotateMethod
rotate(ds::DancerState, rotation, time_delta)::DancerState

Rotates the dancer idntified by the DancerState in place by rotation.

source
SquareDanceReasoning.scheduleMethod
schedule(sched::CallSchedule, call::SquareDanceCall, at)

Enters call into sched so that it will be performed at the specified time at.

source
SquareDanceReasoning.showcaseMethod
showcase(filename::String, title::String, initial_kb, choreography::Vector{SquareDanceCall}; inhibit_call_engine_logging = true; dbgctx = nothing)

Writes a markdown file named filename in the choreography Showcase documentation directory.

title is the title string for the document.

initial_kb is the knowledgebase containing the formations that choreography starts from.

choreography is a vector of the calls to be performed.

If inhibit_call_engine_logging is true then teh usual call engine logging will be suppressed.

If provided, dbgctx should be a CallEngineDebugContext.

source
SquareDanceReasoning.step_to_a_waveMethod
step_to_a_wave(f::FaceToFace, time_delta, h::Handedness)::MiniWave

The face to face dancers move up to make a right or left handed miniwave.

Breating should be done separately.

source
SquareDanceReasoning.timeofMethod
timeof(::SquareDanceFormation)

Returns the valuie of the time field, which should be the same for all DancerSTate in the formation.

source
SquareDanceReasoning.update_fromFunction

update_from(formation::SquareDanceFormation, newest::Vector{DancerState})

Return a new formation of the same type as formation but with its component DancerStates taken from newest, matching by Dancer.

source