ソースを参照

add comments for array.slice occurences

Simon Schmid 5 年 前
コミット
2cdb1a4261

+ 9 - 3
src/MusicalScore/Graphical/SkyBottomLineCalculator.ts

@@ -114,7 +114,7 @@ export class SkyBottomLineCalculator {
             tmpCanvas.clear();
         }
         // Subsampling:
-        // The pixel width is bigger then the measure size in units. So we split the array into
+        // The pixel width is bigger than the measure size in units. So we split the array into
         // chunks with the size of MeasurePixelWidth/measureUnitWidth and reduce the value to its
         // average
         const arrayChunkSize: number = this.mSkyLine.length / arrayLength;
@@ -122,9 +122,15 @@ export class SkyBottomLineCalculator {
         const subSampledSkyLine: number[] = [];
         const subSampledBottomLine: number[] = [];
         for (let chunkIndex: number = 0; chunkIndex < this.mSkyLine.length; chunkIndex += arrayChunkSize) {
-            let chunk: number[] = this.mSkyLine.slice(chunkIndex, chunkIndex + arrayChunkSize);
+            let chunk: number[] = this.mSkyLine.slice(chunkIndex, chunkIndex + arrayChunkSize); // slice does not include end index
+            // TODO chunkIndex + arrayChunkSize is sometimes bigger than this.mSkyLine.length -> out of bounds
+            // TODO chunkIndex + arrayChunkSize is often a non-rounded float as well. is that ok to use with slice?
+            /*const diff: number = this.mSkyLine.length - (chunkIndex + arrayChunkSize);
+            if (diff < 0) { // out of bounds
+                console.log("length - slice end index: " + diff);
+            }*/
             subSampledSkyLine.push(Math.min(...chunk));
-            chunk = this.mBottomLine.slice(chunkIndex, chunkIndex + arrayChunkSize);
+            chunk = this.mBottomLine.slice(chunkIndex, chunkIndex + arrayChunkSize); // slice does not include end index
             subSampledBottomLine.push(Math.max(...chunk));
         }
 

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

@@ -25,7 +25,7 @@ export class MusicPartManager /*implements ISelectionListener*/ {
      * Main initialize method for MusicPartManager.
      */
     public init(): void {
-        this.parts = this.musicSheet.Repetitions.slice();
+        this.parts = this.musicSheet.Repetitions.slice(); // slice=arrayCopy
         this.sheetStart = this.musicSheet.SelectionStart = new Fraction(0, 1);
         this.sheetEnd = this.musicSheet.SelectionEnd = this.musicSheet.SheetEndTimestamp;
         this.calcMapping();

+ 1 - 1
src/MusicalScore/ScoreIO/InstrumentReader.ts

@@ -675,7 +675,7 @@ export class InstrumentReader {
    * @returns {boolean}
    */
   private isAttributesNodeAtEndOfMeasure(parentNode: IXmlElement, attributesNode: IXmlElement): boolean {
-    const childs: IXmlElement[] = parentNode.elements().slice();
+    const childs: IXmlElement[] = parentNode.elements().slice(); // slice=arrayCopy
     let attributesNodeIndex: number = 0;
     for (let i: number = 0; i < childs.length; i++) {
       if (childs[i] === attributesNode) {

+ 1 - 1
src/MusicalScore/VoiceData/Instructions/RepetitionInstruction.ts

@@ -45,7 +45,7 @@ export class RepetitionInstruction /*implements IComparable*/ {
                 parentRepetition: Repetition = undefined, endingIndices: number[] = undefined) {
         this.measureIndex = measureIndex;
         if (endingIndices !== undefined) {
-            this.endingIndices = endingIndices.slice();
+            this.endingIndices = endingIndices.slice(); // slice=arrayCopy
         }
         this.type = type;
         this.alignment = alignment;