瀏覽代碼

fix(Fractions): add gt and gte methods, replace some > and < occurences (#518)

fix #518
sschmid 5 年之前
父節點
當前提交
c80fea64ae

+ 8 - 0
src/Common/DataObjects/Fraction.ts

@@ -256,6 +256,14 @@ export class Fraction {
     return this.realValue <= frac.realValue;
   }
 
+  public gt(frac: Fraction): boolean {
+    return !this.lte(frac);
+  }
+
+  public gte(frac: Fraction): boolean {
+    return !this.lt(frac);
+  }
+
   //public Equals(f: Fraction): boolean {
   //    if (ReferenceEquals(this, f))
   //        return true;

+ 1 - 1
src/MusicalScore/Graphical/VexFlow/VexFlowMeasure.ts

@@ -461,7 +461,7 @@ export class VexFlowMeasure extends GraphicalMeasure {
             let gNotesEndTimestamp: Fraction = new Fraction();
             for (const graphicalNote of gve.notes) {
                 const noteEnd: Fraction  = Fraction.plus(graphicalNote.sourceNote.getAbsoluteTimestamp(), graphicalNote.sourceNote.Length);
-                if (gNotesEndTimestamp < noteEnd) {
+                if (gNotesEndTimestamp.lt(noteEnd)) {
                     gNotesEndTimestamp = noteEnd;
                 }
             }

+ 1 - 1
src/MusicalScore/MusicParts/MusicPartManager.ts

@@ -34,7 +34,7 @@ export class MusicPartManager /*implements ISelectionListener*/ {
         let curTransform: TimestampTransform = undefined;
         for (let i: number = this.timestamps.length - 1; i >= 0; i--) {
             curTransform = this.timestamps[i];
-            if (curEnrolledTimestamp >= curTransform.$from) {
+            if (curEnrolledTimestamp.gte(curTransform.$from)) {
                 return curTransform;
             }
         }

+ 4 - 2
src/MusicalScore/MusicParts/MusicPartManagerIterator.ts

@@ -305,7 +305,7 @@ export class MusicPartManagerIterator {
     private moveDynamicIndexToTimestamp(absoluteTimestamp: Fraction): void {
         let dynamics: DynamicsContainer[] = this.manager.MusicSheet.TimestampSortedDynamicExpressionsList;
         for (let index: number = 0; index < dynamics.length; index++) {
-            if (dynamics[index].parMultiExpression().AbsoluteTimestamp >= absoluteTimestamp) {
+            if (dynamics[index].parMultiExpression().AbsoluteTimestamp.gte(absoluteTimestamp)) {
                 this.currentDynamicEntryIndex = Math.Max(0, index - 1);
                 return
             }
@@ -501,7 +501,9 @@ export class MusicPartManagerIterator {
             this.currentVoiceEntries = this.getVoiceEntries(currentContainer);
             this.currentVerticalContainerInMeasureTimestamp = currentContainer.Timestamp;
             this.currentTimeStamp = Fraction.plus(this.currentMeasure.AbsoluteTimestamp, this.currentVerticalContainerInMeasureTimestamp);
-            if (this.currentTimeStamp >= this.manager.MusicSheet.SelectionEnd) {
+            const selectionEnd: Fraction = this.manager.MusicSheet.SelectionEnd;
+            // TODO handle selectionEnd undefined, can happen in Beethoven Ferne Geliebte
+            if (selectionEnd && this.currentTimeStamp.gte(selectionEnd)) {
                 this.endReached = true;
             }
             this.activateCurrentDynamicOrTempoInstructions();