<commit_before>"use strict";

var ViewPortCreator = Class.extend({
  init: function() {
    this.trajectoryCalculator = new TrajectoryCalculator();
  },

  findPillarsInViewPort: function(scrollLocation, pillar) {
    return _.map(pillar.findAllNearby(scrollLocation), function(col) { 
      return col - scrollLocation;
    });
  },

  shiftTrajectoriesForViewPort: function(scrollLocation, trajectories) {
    //refactor out these awful temp arrays when I switch out from underscore to lo-dash
    var newTrajectories = [];
    for (var i=0; i<trajectories.length; i++) {
      var newTrajectory = [];
      var legalPoints = _.filter(trajectories[i], function(point) {
        return point.isLegal();
      });

      for (var j=0; j<legalPoints.length; j++) {
        newTrajectory.push(this.shiftLocationForViewPort(scrollLocation, legalPoints[j]));
      }

      newTrajectories.push(newTrajectory);
    }

    return newTrajectories;
  },

  shiftLocationForViewPort: function(scrollLocation, point) {
    if (point === undefined) {
      return undefined;
    }
    return pointRowCol(point.row, point.col - scrollLocation);
  },

  create: function(scrollLocation, playerLocation, topPillar, bottomPillar, collided, outOfBounds, gameOver, score) {
    var topPillars = this.findPillarsInViewPort(scrollLocation, topPillar);
    var bottomPillars = this.findPillarsInViewPort(scrollLocation, bottomPillar);

    if (playerLocation === undefined) {
      return {
        topPillars: topPillars,
        bottomPillars: bottomPillars,
        collided: collided,
        outOfBounds: outOfBounds,
        gameOver: gameOver,
        score: score,
      };
    };

    return {
      playerLocation: this.shiftLocationForViewPort(scrollLocation, playerLocation),
      trajectory: this.shiftTrajectoriesForViewPort(
        scrollLocation, 
        this.trajectoryCalculator.getTrajectories(playerLocation)),
      topPillars: topPillars,
      bottomPillars: bottomPillars,
      collided: collided,
      outOfBounds: outOfBounds,
      gameOver: gameOver,
      score: score,
    };
  },
});<commit_msg>refactor: remove duplication<commit_after>"use strict";

var ViewPortCreator = Class.extend({
  init: function() {
    this.trajectoryCalculator = new TrajectoryCalculator();
  },

  findPillarsInViewPort: function(scrollLocation, pillar) {
    return _.map(pillar.findAllNearby(scrollLocation), function(col) { 
      return col - scrollLocation;
    });
  },

  shiftTrajectoriesForViewPort: function(scrollLocation, trajectories) {
    //refactor out these awful temp arrays when I switch out from underscore to lo-dash
    var newTrajectories = [];
    for (var i=0; i<trajectories.length; i++) {
      var newTrajectory = [];
      var legalPoints = _.filter(trajectories[i], function(point) {
        return point.isLegal();
      });

      for (var j=0; j<legalPoints.length; j++) {
        newTrajectory.push(this.shiftLocationForViewPort(scrollLocation, legalPoints[j]));
      }

      newTrajectories.push(newTrajectory);
    }

    return newTrajectories;
  },

  shiftLocationForViewPort: function(scrollLocation, point) {
    if (point === undefined) {
      return undefined;
    }
    return pointRowCol(point.row, point.col - scrollLocation);
  },

  create: function(scrollLocation, playerLocation, topPillar, bottomPillar, collided, outOfBounds, gameOver, score) {
    var result = {
      topPillars: this.findPillarsInViewPort(scrollLocation, topPillar),
      bottomPillars: this.findPillarsInViewPort(scrollLocation, bottomPillar),
      collided: collided,
      outOfBounds: outOfBounds,
      gameOver: gameOver,
      score: score,
    };

    if (playerLocation === undefined) {
      return result;
    };

    return _.extend(result, {
      playerLocation: this.shiftLocationForViewPort(scrollLocation, playerLocation),
      trajectory: this.shiftTrajectoriesForViewPort(
        scrollLocation, 
        this.trajectoryCalculator.getTrajectories(playerLocation)),
    });
  },
});
{'fraction_non_alphanumeric': 0.10556383507203179, 'fraction_numerical': 0.0009935419771485345, 'mean_word_length': 3.529808773903262, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1775078', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1186, 'n_words': 240}