tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

utils.js (1859B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 /**
      8 * Compares 2 sets of grid fragments to each other and checks if they have the same
      9 * general geometry.
     10 * This means that things like areas, area names or line names are ignored.
     11 * This only checks if the 2 sets of fragments have as many fragments, as many lines, and
     12 * that those lines are at the same distance.
     13 *
     14 * @param  {Array} fragments1
     15 *         A list of gridFragment objects.
     16 * @param  {Array} fragments2
     17 *         Another list of gridFragment objects to compare to the first list.
     18 * @return {boolean}
     19 *         True if the fragments are the same, false otherwise.
     20 */
     21 function compareFragmentsGeometry(fragments1, fragments2) {
     22  // Compare the number of fragments.
     23  if (fragments1.length !== fragments2.length) {
     24    return false;
     25  }
     26 
     27  // Compare the number of areas, rows and columns.
     28  for (let i = 0; i < fragments1.length; i++) {
     29    if (
     30      fragments1[i].cols.lines.length !== fragments2[i].cols.lines.length ||
     31      fragments1[i].rows.lines.length !== fragments2[i].rows.lines.length
     32    ) {
     33      return false;
     34    }
     35  }
     36 
     37  // Compare the offset of lines.
     38  for (let i = 0; i < fragments1.length; i++) {
     39    for (let j = 0; j < fragments1[i].cols.lines.length; j++) {
     40      if (
     41        fragments1[i].cols.lines[j].start !== fragments2[i].cols.lines[j].start
     42      ) {
     43        return false;
     44      }
     45    }
     46    for (let j = 0; j < fragments1[i].rows.lines.length; j++) {
     47      if (
     48        fragments1[i].rows.lines[j].start !== fragments2[i].rows.lines[j].start
     49      ) {
     50        return false;
     51      }
     52    }
     53  }
     54 
     55  return true;
     56 }
     57 
     58 module.exports.compareFragmentsGeometry = compareFragmentsGeometry;