<commit_before>module.exports = toHeightmap;

function toHeightmap(graph, getNodePosition) {
  var maxHeight = 1024;
  var aboveWater = 3;
  var minHeight = 1;

  var bounds = getBounds();

  var offsetX = bounds.x - bounds.half;
  var offsetY = bounds.y - bounds.half;

  var squareSize = upperPowerOfTwo((bounds.half + 1) * 2);
  console.log('heightmap side length: ' + squareSize);

  var maxHillRadius = squareSize * 0.01; /// graph.getNodesCount();
  var maxHillRadiusSquared = maxHillRadius * maxHillRadius;

  var size = squareSize * squareSize;
  var heightMap = new Uint16Array(size);
  fillInMap();

  return {
    size: squareSize,
    map: heightMap,
    maxHeight: maxHeight,
    waterLevel: aboveWater
  };

  function getBounds() {
    var minX = 0;
    var maxX = 0;
    var minY = 0;
    var maxY = 0;
    var maxDegree = 0;

    graph.forEachNode(computeMetadata);

    var half = (Math.max((maxX - minX), (maxY - minY)))/2;

    return {
      maxDegree: maxDegree,
      x: (minX + maxX)/2,
      y: (minY + maxY)/2,
      half: half
    };

    function computeMetadata(node) {
      var pos = getNodePosition(node);
      var degree = getDegree(node.id);

      if (pos.x < minX) minX = pos.x;
      if (pos.y < minY) minY = pos.y;
      if (pos.x > minX) maxX = pos.x;<commit_msg>Should be using correct half<commit_after>module.exports = toHeightmap;

function toHeightmap(graph, getNodePosition) {
  var maxHeight = 1024;
  var aboveWater = 3;
  var minHeight = 1;

  var bounds = getBounds();

  var offsetX = bounds.x - bounds.half;
  var offsetY = bounds.y - bounds.half;

  var squareSize = upperPowerOfTwo((bounds.half + 1) * 2);
  console.log('heightmap side length: ' + squareSize);

  var maxHillRadius = squareSize * 0.01; /// graph.getNodesCount();
  var maxHillRadiusSquared = maxHillRadius * maxHillRadius;

  var size = squareSize * squareSize;
  var heightMap = new Uint16Array(size);
  fillInMap();

  return {
    size: squareSize,
    map: heightMap,
    maxHeight: maxHeight,
    waterLevel: aboveWater
  };

  function getBounds() {
    var minX = 0;
    var maxX = 0;
    var minY = 0;
    var maxY = 0;
    var maxDegree = 0;

    graph.forEachNode(computeMetadata);

    var half = (Math.max((maxX - minX), (maxY - minY)))/2;

    return {
      maxDegree: maxDegree,
      x: (minX + half),
      y: (minY + half),
      half: half
    };

    function computeMetadata(node) {
      var pos = getNodePosition(node);
      var degree = getDegree(node.id);

      if (pos.x < minX) minX = pos.x;
      if (pos.y < minY) minY = pos.y;
      if (pos.x > minX) maxX = pos.x;
{'fraction_non_alphanumeric': 0.12457011845624762, 'fraction_numerical': 0.015284677111196026, 'mean_word_length': 2.7453505007153076, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '5114239', 'n_tokens_mistral': 973, 'n_tokens_neox': 897, 'n_words': 241}