<commit_before>part of couclient;

WorldMap worldMap;

class WorldMap
{
  Map<String,String> hubInfo;
  Map<String,Map> hubMaps;
  Map<String,String> moteInfo;

  DataMaps map = new DataMaps();

  bool worldMapVisible = false;
  Element WorldMapDiv = querySelector("#WorldMapLayer");
  Element HubMabDiv = querySelector("#HubMapLayer");

  WorldMap(String hub_id) {
    loadhubdiv(hub_id);

    // toggle main and hub maps
    Element toggleMapView = querySelector("#map-window-world");
    toggleMapView.onClick.listen((_) {
      if (worldMapVisible) {
        // go to current hub
        hubMap();
        toggleMapView.setInnerHtml('<i class="fa fa-fw fa-globe"></i>');
      } else if (!worldMapVisible) {
        // go to world map
        mainMap();
        toggleMapView.setInnerHtml('<i class="fa fa-fw fa-map-marker"></i>');
      }
    });
  }

  loadhubdiv (String hub_id) {
    // read in street data
    hubInfo = map.data_maps_hubs[hub_id]();
    hubMaps = map.data_maps_maps[hub_id]();
    moteInfo = map.data_maps_streets['9']();

    // prepare ui elements
    view.mapTitle.text = hubInfo['name'];
    view.mapImg.style.backgroundImage = 'url(' +hubInfo['bg']+ ')';
    HubMabDiv.children.clear();

    // render
    for (Map object in hubMaps['objs'].values) {
      // streets
      if (object['type'] == 'S') {
        String streetName = moteInfo[hub_id][object['tsid']];

        Map streetPlacement = {
          "x1": object["x1"],
          "x2": object["x2"],
          "y1": object["y1"],
          "y2": object["y2"],
          "deg": 0,
          "length": 0,
        };
        streetPlacement['deg'] = getStreetAngle(streetPlacement);
        streetPlacement['length'] = getStreetLength(streetPlacement);
        Map customAttributes = {
          "tsid": object['tsid']
        };

        DivElement street = new DivElement()
          ..classes.add('hm-street')
          ..text = streetName
          ..title = "Teleport to " + streetName
          ..attributes.addAll(customAttributes)
          ..style.left = streetPlacement['x1'].toString() + 'px'
          ..style.top = streetPlacement['y1'].toString() + 'px'
          ..style.width = streetPlacement['length'].toString() + 'px'
          ..style.transform = 'rotate(' + streetPlacement['deg'].toString() + 'rad)';

        if (object['tsid'].substring(1) == currentStreet.streetData['tsid'].substring(1)) {
          // current street
          street.classes.add('hm-street-current');
        }

        if (street.text.contains('Machine Room') == false) {
          HubMabDiv.append(street);
        }
      }
    }

    HubMabDiv.onClick.listen((e) {
      String tsid = e.target.attributes['tsid'];
      view.mapLoadingScreen.className = "MapLoadingScreenIn";
      view.mapLoadingScreen.style.opacity = "1.0";
      minimap.containerE.hidden = true;
      //changes first letter to match revdancatt's code - only if it starts with an L
      if (tsid.startsWith("L")) tsid = tsid.replaceFirst("L", "G");
      streetService.requestStreet(tsid);
      querySelector('.hm-street.hm-street-current').classes.remove('hm-street-current');
      new Service([#streetLoaded], (_) {
        loadhubdiv(currentStreet.hub_id);
      });
    });

    HubMabDiv.classes.add('scaled');

    worldMapVisible = false;
    HubMabDiv.hidden = false;
    WorldMapDiv.hidden = true;
  }

  getStreetAngle (Map street) {
    Rectangle streetBox = new Rectangle(street['x1'], street['y1'], street['x2'] - street['x1'], street['y2'] - street['y1']);
    DivElement box = new DivElement()
      ..style.height = streetBox.height.toString() + 'px'
      ..style.width = streetBox.width.toString() + 'px'
      ..style.border = '1px solid black'
      ..style.position = 'absolute'
      ..style.top = streetBox.top.toString() + 'px'
      ..style.left = streetBox.left.toString() + 'px';
    HubMabDiv.append(box);
    //
    num angle;
    if (street['y1'] >= street['y2']) {
      // problem
      angle = atan2 (streetBox.height, streetBox.width) + 90;
    } else {
      angle = atan2 (streetBox.height, streetBox.width);
    }
    return angle;
  }

  getStreetLength (Map street) {
    num base = street['x2'] - street['x1'];
    num height = street['y2'] - street['y1'];
    num hyp = (base * base) + (height * height);<commit_msg>angles<commit_after>part of couclient;

WorldMap worldMap;

class WorldMap
{
  Map<String,String> hubInfo;
  Map<String,Map> hubMaps;
  Map<String,String> moteInfo;

  DataMaps map = new DataMaps();

  bool worldMapVisible = false;
  Element WorldMapDiv = querySelector("#WorldMapLayer");
  Element HubMabDiv = querySelector("#HubMapLayer");

  WorldMap(String hub_id) {
    loadhubdiv(hub_id);

    // toggle main and hub maps
    Element toggleMapView = querySelector("#map-window-world");
    toggleMapView.onClick.listen((_) {
      if (worldMapVisible) {
        // go to current hub
        hubMap();
        toggleMapView.setInnerHtml('<i class="fa fa-fw fa-globe"></i>');
      } else if (!worldMapVisible) {
        // go to world map
        mainMap();
        toggleMapView.setInnerHtml('<i class="fa fa-fw fa-map-marker"></i>');
      }
    });
  }

  loadhubdiv (String hub_id) {
    // read in street data
    hubInfo = map.data_maps_hubs[hub_id]();
    hubMaps = map.data_maps_maps[hub_id]();
    moteInfo = map.data_maps_streets['9']();

    // prepare ui elements
    view.mapTitle.text = hubInfo['name'];
    view.mapImg.style.backgroundImage = 'url(' +hubInfo['bg']+ ')';
    HubMabDiv.children.clear();

    // render
    for (Map object in hubMaps['objs'].values) {
      // streets
      if (object['type'] == 'S') {
        String streetName = moteInfo[hub_id][object['tsid']];

        Map streetPlacement = {
          "x1": object["x1"],
          "x2": object["x2"],
          "y1": object["y1"],
          "y2": object["y2"],
          "deg": 0,
          "length": 0,
        };
        streetPlacement['deg'] = getStreetAngle(streetPlacement);
        streetPlacement['length'] = getStreetLength(streetPlacement);
        Map customAttributes = {
          "tsid": object['tsid']
        };

        DivElement street = new DivElement()
          ..classes.add('hm-street')
          ..text = streetName
          ..title = "Teleport to " + streetName
          ..attributes.addAll(customAttributes)
          ..style.left = streetPlacement['x1'].toString() + 'px'
          ..style.top = streetPlacement['y1'].toString() + 'px'
          ..style.width = streetPlacement['length'].toString() + 'px'
          ..style.transform = 'rotate(' + streetPlacement['deg'].toString() + 'rad)';

        if (object['tsid'].substring(1) == currentStreet.streetData['tsid'].substring(1)) {
          // current street
          street.classes.add('hm-street-current');
        }

        if (street.text.contains('Machine Room') == false) {
          HubMabDiv.append(street);
        }
      }
    }

    HubMabDiv.onClick.listen((e) {
      String tsid = e.target.attributes['tsid'];
      view.mapLoadingScreen.className = "MapLoadingScreenIn";
      view.mapLoadingScreen.style.opacity = "1.0";
      minimap.containerE.hidden = true;
      //changes first letter to match revdancatt's code - only if it starts with an L
      if (tsid.startsWith("L")) tsid = tsid.replaceFirst("L", "G");
      streetService.requestStreet(tsid);
      querySelector('.hm-street.hm-street-current').classes.remove('hm-street-current');
      new Service([#streetLoaded], (_) {
        loadhubdiv(currentStreet.hub_id);
      });
    });

    HubMabDiv.classes.add('scaled');

    worldMapVisible = false;
    HubMabDiv.hidden = false;
    WorldMapDiv.hidden = true;
  }

  getStreetAngle (Map street) {
    Rectangle streetBox = new Rectangle(street['x1'], street['y1'], street['x2'] - street['x1'], street['y2'] - street['y1']);
    DivElement box = new DivElement()
      ..style.height = streetBox.height.toString() + 'px'
      ..style.width = streetBox.width.toString() + 'px'
      ..style.border = '1px solid black'
      ..style.position = 'absolute'
      ..style.top = streetBox.top.toString() + 'px'
      ..style.left = streetBox.left.toString() + 'px';
    HubMabDiv.append(box);
    //
    num angle;
    if (street['y1'] >= street['y2']) {
      // problem
      angle = atan2 (streetBox.width, streetBox.height);
    } else {
      angle = atan2 (streetBox.height, streetBox.width);
    }
    return angle;
  }

  getStreetLength (Map street) {
    num base = street['x2'] - street['x1'];
    num height = street['y2'] - street['y1'];
    num hyp = (base * base) + (height * height);
{'fraction_non_alphanumeric': 0.16206496519721578, 'fraction_numerical': 0.00765661252900232, 'mean_word_length': 2.6268405553218344, 'pattern_counts': {'":': 14, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5307861', 'n_tokens_mistral': 2804, 'n_tokens_neox': 2711, 'n_words': 528}