<commit_before>var minHeap = require("./min-heap");

module.exports = function(topology, minArea) {
  var heap = minHeap(),
      maxArea = 0,
      triangle;

  topology.arcs.forEach(function(arc) {
    var points = arc, // TODO projection
        triangles = [];

    for (var i = 1, n = arc.length - 1; i < n; ++i) {
      triangle = points.slice(i - 1, i + 2);
      if (triangle[1].area = area(triangle)) {
        triangles.push(triangle);
        heap.push(triangle);
      }
    }

    for (var i = 0, n = triangles.length; i < n; ++i) {
      triangle = triangles[i];
      triangle.previous = triangles[i - 1];
      triangle.next = triangles[i + 1];
    }

    return points;
  });

  while (triangle = heap.pop()) {

    // If the area of the current point is less than that of the previous point
    // to be eliminated, use the latter's area instead. This ensures that the
    // current point cannot be eliminated without eliminating previously-
    // eliminated points.
    if (triangle[1].area < maxArea) triangle[1].area = maxArea;
    else maxArea = triangle[1].area;

    if (triangle.previous) {
      triangle.previous.next = triangle.next;
      triangle.previous.area = triangle.area;
      update(triangle.previous);
    } else {
      triangle[0].area = triangle[1].area;
    }

    if (triangle.next) {
      triangle.next.previous = triangle.previous;
      triangle.next[0] = triangle[0];
      update(triangle.next);
    } else {
      triangle[2].area = triangle[1].area;
    }
  }

  topology.arcs = topology.arcs.map(function(arc) {
    var j = arc.length - 1;
    return arc.filter(function(point, i) {<commit_msg>Fix borked simplification.<commit_after>var minHeap = require("./min-heap");

module.exports = function(topology, minArea) {
  var heap = minHeap(),
      maxArea = 0,
      triangle;

  topology.arcs.forEach(function(arc) {
    var points = arc, // TODO projection
        triangles = [];

    for (var i = 1, n = arc.length - 1; i < n; ++i) {
      triangle = points.slice(i - 1, i + 2);
      if (triangle[1].area = area(triangle)) {
        triangles.push(triangle);
        heap.push(triangle);
      }
    }

    for (var i = 0, n = triangles.length; i < n; ++i) {
      triangle = triangles[i];
      triangle.previous = triangles[i - 1];
      triangle.next = triangles[i + 1];
    }

    return points;
  });

  while (triangle = heap.pop()) {

    // If the area of the current point is less than that of the previous point
    // to be eliminated, use the latter's area instead. This ensures that the
    // current point cannot be eliminated without eliminating previously-
    // eliminated points.
    if (triangle[1].area < maxArea) triangle[1].area = maxArea;
    else maxArea = triangle[1].area;

    if (triangle.previous) {
      triangle.previous.next = triangle.next;
      triangle.previous[2] = triangle[2];
      update(triangle.previous);
    } else {
      triangle[0].area = triangle[1].area;
    }

    if (triangle.next) {
      triangle.next.previous = triangle.previous;
      triangle.next[0] = triangle[0];
      update(triangle.next);
    } else {
      triangle[2].area = triangle[1].area;
    }
  }

  topology.arcs = topology.arcs.map(function(arc) {
    var j = arc.length - 1;
    return arc.filter(function(point, i) {
{'fraction_non_alphanumeric': 0.13819171454490475, 'fraction_numerical': 0.012095554883580285, 'mean_word_length': 2.4675052410901466, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '1844585', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1016, 'n_words': 274}