From e2dbc00c3de1e9e5e100944f69e4bdfe32afaad8 Mon Sep 17 00:00:00 2001 From: David Bauer Date: Mon, 23 Dec 2024 13:02:05 +0100 Subject: [PATCH] Add ordering on alignments --- include/vrv/horizontalaligner.h | 8 ++++++++ src/horizontalaligner.cpp | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/vrv/horizontalaligner.h b/include/vrv/horizontalaligner.h index 48fbb88e613..afb8aab6e28 100644 --- a/include/vrv/horizontalaligner.h +++ b/include/vrv/horizontalaligner.h @@ -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). diff --git a/src/horizontalaligner.cpp b/src/horizontalaligner.cpp index eae12142b76..c232a3eb3eb 100644 --- a/src/horizontalaligner.cpp +++ b/src/horizontalaligner.cpp @@ -542,6 +542,29 @@ bool Alignment::IsSupportedChild(Object *child) return true; } +bool Alignment::operator==(const Alignment &other) const +{ + const Measure *measure = vrv_cast(this->GetFirstAncestor(MEASURE)); + const Measure *otherMeasure = vrv_cast(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(this->GetFirstAncestor(MEASURE)); + const Measure *otherMeasure = vrv_cast(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;