Skip to content

Commit

Permalink
Add ordering on alignments
Browse files Browse the repository at this point in the history
  • Loading branch information
brdvd committed Dec 27, 2024
1 parent 666c6e1 commit e2dbc00
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/vrv/horizontalaligner.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ class Alignment : public Object {
Fraction GetTime() const { return m_time; }
///@}

/**
* @name Weak ordering: for alignments in the same measure it is based on time, otherwise on the measure order
*/
///@{
bool operator==(const Alignment &other) const;
std::weak_ordering operator<=>(const Alignment &other) const;
///@}

/**
* Add the LayerElement to the appropriate AlignmentReference child.
* Looks at the cross-staff situation (@staff or parent @staff).
Expand Down
23 changes: 23 additions & 0 deletions src/horizontalaligner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,29 @@ bool Alignment::IsSupportedChild(Object *child)
return true;
}

bool Alignment::operator==(const Alignment &other) const
{
const Measure *measure = vrv_cast<const Measure *>(this->GetFirstAncestor(MEASURE));
const Measure *otherMeasure = vrv_cast<const Measure *>(other.GetFirstAncestor(MEASURE));
assert(measure && otherMeasure);

return (measure == otherMeasure) && (this->GetTime() == other.GetTime());
}

std::weak_ordering Alignment::operator<=>(const Alignment &other) const
{
const Measure *measure = vrv_cast<const Measure *>(this->GetFirstAncestor(MEASURE));
const Measure *otherMeasure = vrv_cast<const Measure *>(other.GetFirstAncestor(MEASURE));
assert(measure && otherMeasure);

if (measure == otherMeasure) {
return this->GetTime() <=> other.GetTime();
}
else {
return Object::IsPreOrdered(measure, otherMeasure) ? std::weak_ordering::less : std::weak_ordering::greater;
}
}

bool Alignment::HasAccidVerticalOverlap(const Alignment *otherAlignment, int staffN) const
{
if (!otherAlignment) return false;
Expand Down

0 comments on commit e2dbc00

Please sign in to comment.