Browse Source

fix(Skyline): replace undefined values with neighboring values. Fix some tab scores (#911)

fix by @momolarson, reviewed by @sschmidTU
visual regression tests pass. (with merging develop into the PR branch)
Gregg Larson 4 years ago
parent
commit
e824928983
1 changed files with 47 additions and 0 deletions
  1. 47 0
      src/MusicalScore/Graphical/SkyBottomLineCalculator.ts

+ 47 - 0
src/MusicalScore/Graphical/SkyBottomLineCalculator.ts

@@ -101,7 +101,19 @@ export class SkyBottomLineCalculator {
                         break;
                     }
                 }
+
+               // if (tmpSkyLine[x] === undefined) {
+                 //   tmpSkyLine[x] = tmpSkyLine[x-1];
+               // }
+
+            }
+
+            for (let idx: number = 0; idx < tmpSkyLine.length; idx++) {
+                if (tmpSkyLine[idx] === undefined) {
+                    tmpSkyLine[idx] = Math.max(this.findPreviousValidNumber(idx, tmpSkyLine), this.findNextValidNumber(idx, tmpSkyLine));
+                }
             }
+
             this.mSkyLine.push(...tmpSkyLine);
             this.mBottomLine.push(...tmpBottomLine);
 
@@ -153,6 +165,41 @@ export class SkyBottomLineCalculator {
     }
 
     /**
+     * go backwards through the skyline array and find a number so that
+     * we can properly calculate the average
+     * @param start
+     * @param backend
+     * @param color
+     */
+    private findPreviousValidNumber(start: number, tSkyLine: number[]): number {
+        for (let idx: number = start; idx >= 0; idx--) {
+            if (!isNaN(tSkyLine[idx])) {
+                return tSkyLine[idx];
+            }
+        }
+        return 0;
+    }
+
+    /**
+     * go forward through the skyline array and find a number so that
+     * we can properly calculate the average
+     * @param start
+     * @param backend
+     * @param color
+     */
+    private findNextValidNumber(start: number, tSkyLine: Array<number>): number {
+        if (start >= tSkyLine.length) {
+            return tSkyLine[start - 1];
+        }
+        for (let idx: number = start; idx < tSkyLine.length; idx++) {
+            if (!isNaN(tSkyLine[idx])) {
+                return tSkyLine[idx];
+            }
+        }
+        return 0;
+    }
+
+    /**
      * Debugging drawing function that can draw single pixels
      * @param coord Point to draw to
      * @param backend the backend to be used