neoscore.core.spanner

class neoscore.core.spanner.Spanner[source]

Bases: object

Mixin for a PositionedObject with starting and ending anchors.

If the spanner is in a Flowable, the endpoint must be in the same one. Likewise, if the spanner is not in one, the endpoint must not be in one either.

This mixin only provides a common interface for ending anchors. The starting position of this spanner should be the main object’s PositionedObject.pos, and the starting anchor should be its PositionedObject.parent. It is up to the implementing class to decide how to use this information.

Simple Spanners are horizontal relative to their starting anchor. Arbitrary end-y positions can be set with Spanner2D.

Implementations should be careful to declare Spanner as a superclass before PositionedObject or any inheritors of it. This is necessary in order to get the correct method resolution order for custom PositionedObject behavior provided by this class - namely Spanner.breakable_length.

__init__(end_x: Unit, end_parent: PositionedObject)[source]
Parameters
  • end_x – The X position of the endpoint.

  • end_parent – The parent of the endpoint. end_x will be relative to this object. This can be the spanner itself to make it relative to the starting point.

property end_x: Unit

The x position of the endpoint

end_y

The y position of the endpoint.

This value is automatically computed such that the spanner is horizontal.

property end_pos: Point

The position of the endpoint

property end_parent: PositionedObject

The parent of the endpoint. This may be self.

spanner_x_length

The x-axis length of the spanner.

property breakable_length: Unit

Spanners are breakable over their spanner_x_length.

Note that in order for this implementation to take effect on concrete spanners, Spanner must be declared as a superclass before PositionedObject or any other class that implements breakable_length!

point_along_spanner(ratio: float) Point[source]

Find the point on the spanner at a given 0-1 ratio along it.

For example, a ratio of 0.5 will give the point half-way along the spanner.

The returned point will be relative to the starting point.

Parameters

ratio – A value representing progress along the spanner, where 0 is at the start and 1 is at the end. Values outside these bounds will give a point as if the spanner extended to infinity.