function sortNodes(nodes) {
  const q1 = [];
  const q2 = [];
  const q3 = [];
  const q4 = [];
  for (let i = 0; i < nodes.length; ++i) {
    const { start, end } = nodes[i].desc.slice;
    const middle = normalize((start + end) / 2);
    let section = Math.floor(middle / (Math.PI / 2));
    switch (section) {
      case 0:
        q1.push(nodes[i]);
        break;
      case 1:
        q2.push(nodes[i]);
        break;
      case 2:
        q3.push(nodes[i]);
        break;
      case 3:
        q4.push(nodes[i]);
        break;
      default:
        break;
    }
  }

  const sortFn = (a, b) => {
    const middleA = normalize((a.desc.slice.start + a.desc.slice.end) / 2);
    const middleB = normalize((b.desc.slice.start + b.desc.slice.end) / 2);
    return middleA - middleB;
  };
  const reverseSortFn = (a, b) => sortFn(b, a);

  q1.sort(reverseSortFn);
  q2.sort(sortFn);
  q3.sort(reverseSortFn);
  q4.sort(sortFn);
  return q1.concat(q2, q4, q3);
}
/*
 * Sorts the nodes so that
 *   in each quarter sort nodes from the center (in y) outwards
 *   first quarter before the second
 *   forth quarter before the third
 */
Sorts the nodes so that
in each quarter sort nodes from the center (in y) outwards
first quarter before the second
forth quarter before the third
Sorts the nodes so that in each quarter sort nodes from the center ( in y ) outwards first quarter before the second forth quarter before the third
function sortNodes(nodes) {
  const q1 = [];
  const q2 = [];
  const q3 = [];
  const q4 = [];
  for (let i = 0; i < nodes.length; ++i) {
    const { start, end } = nodes[i].desc.slice;
    const middle = normalize((start + end) / 2);
    let section = Math.floor(middle / (Math.PI / 2));
    switch (section) {
      case 0:
        q1.push(nodes[i]);
        break;
      case 1:
        q2.push(nodes[i]);
        break;
      case 2:
        q3.push(nodes[i]);
        break;
      case 3:
        q4.push(nodes[i]);
        break;
      default:
        break;
    }
  }
  const sortFn = (a, b) => {
    const middleA = normalize((a.desc.slice.start + a.desc.slice.end) / 2);
    const middleB = normalize((b.desc.slice.start + b.desc.slice.end) / 2);
    return middleA - middleB;
  };
  const reverseSortFn = (a, b) => sortFn(b, a);
  q1.sort(reverseSortFn);
  q2.sort(sortFn);
  q3.sort(reverseSortFn);
  q4.sort(sortFn);
  return q1.concat(q2, q4, q3);
}
function sortNodes ( nodes ) { const q1 = [ ] ; const q2 = [ ] ; const q3 = [ ] ; const q4 = [ ] ; for ( let i = 0 ; i < nodes . length ; ++ i ) { const { start , end } = nodes [ i ] . desc . slice ; const middle = normalize ( ( start + end ) / 2 ) ; let section = Math . floor ( middle / ( Math . PI / 2 ) ) ; switch ( section ) { case 0 : q1 . push ( nodes [ i ] ) ; break ; case 1 : q2 . push ( nodes [ i ] ) ; break ; case 2 : q3 . push ( nodes [ i ] ) ; break ; case 3 : q4 . push ( nodes [ i ] ) ; break ; default : break ; } } const sortFn = ( a , b ) => { const middleA = normalize ( ( a . desc . slice . start + a . desc . slice . end ) / 2 ) ; const middleB = normalize ( ( b . desc . slice . start + b . desc . slice . end ) / 2 ) ; return middleA - middleB ; } ; const reverseSortFn = ( a , b ) => sortFn ( b , a ) ; q1 . sort ( reverseSortFn ) ; q2 . sort ( sortFn ) ; q3 . sort ( reverseSortFn ) ; q4 . sort ( sortFn ) ; return q1 . concat ( q2 , q4 , q3 ) ; }
Sorts the nodes so that
   in each quarter sort nodes from the center (in y) outwards
   first quarter before the second
   forth quarter before the third
Sorts the nodes so that in each quarter sort nodes from the center ( in y ) outwards first quarter before the second forth quarter before the third