<commit_before>// FIXME factor out key precondition (shift et. al)

goog.provide('ol.Control');

goog.require('ol.MapBrowserEvent');
goog.require('ol.control.Constraints');



/**
 * @constructor
 * @param {ol.control.Constraints} constraints Constraints.
 */
ol.Control = function(constraints) {

  /**
   * @protected
   * @type {ol.control.Constraints}
   */
  this.constraints = constraints;

};


/**
 * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
 */
ol.Control.prototype.handleMapBrowserEvent = goog.abstractMethod;


/**
 * @param {ol.Map} map Map.
 * @param {ol.Extent} extent Extent.
 */
ol.Control.prototype.fitExtent = function(map, extent) {
  var resolution = map.getResolutionForExtent(extent);
  resolution = this.constraints.resolution(resolution, 0);
  var center = extent.getCenter();
  center = this.constraints.center(center, resolution, ol.Coordinate.ZERO);
  map.withFrozenRendering(function() {
    map.setCenter(center);
    map.setResolution(resolution);
  });
};


/**
 * @param {ol.Map} map Map.
 * @param {ol.Coordinate} delta Delta.
 * @param {ol.Coordinate=} opt_anchor Anchor.
 */
ol.Control.prototype.pan = function(map, delta, opt_anchor) {
  var center = opt_anchor ? opt_anchor : map.getCenter();
  var resolution = map.getResolution();
  center = this.constraints.center(center, resolution, delta);
  map.setCenter(center);
};


/**
 * @param {ol.Map} map Map.
 * @param {number|undefined} rotation Rotation.
 * @param {number} delta Delta.
 * @param {ol.Coordinate=} opt_anchor Anchor.
 */
ol.Control.prototype.rotate = function(map, rotation, delta, opt_anchor) {
  // FIXME handle rotation about anchor
  rotation = this.constraints.rotation(rotation, delta);
  map.setRotation(rotation);
};


/**
 * @param {ol.Map} map Map.
 * @param {number|undefined} resolution Resolution.
 */
ol.Control.prototype.setResolution = function(map, resolution) {
  resolution = this.constraints.resolution(resolution, 0);
  map.setResolution(resolution);
};


/**
 * @param {ol.Map} map Map.
 * @param {number|undefined} resolution Resolution.
 * @param {number} delta Delta.
 * @param {ol.Coordinate=} opt_anchor Anchor.
 */
ol.Control.prototype.zoom = function(map, resolution, delta, opt_anchor) {
  if (goog.isDefAndNotNull(opt_anchor)) {
    var anchor = opt_anchor;
    var mapCenter = /** @type {!ol.Coordinate} */ map.getCenter();
    var mapResolution = map.getResolution();
    resolution = this.constraints.resolution(resolution, delta);
    var x = anchor.x - resolution *  (anchor.x - mapCenter.x) / mapResolution;
    var y = anchor.y - resolution *  (anchor.y - mapCenter.y) / mapResolution;
    var center = new ol.Coordinate(x, y);
    center = this.constraints.center(center, resolution, ol.Coordinate.ZERO);
    map.withFrozenRendering(function() {
      map.setCenter(center);
      map.setResolution(resolution);
    });
  } else {<commit_msg>Clean up whitespace<commit_after>// FIXME factor out key precondition (shift et. al)

goog.provide('ol.Control');

goog.require('ol.MapBrowserEvent');
goog.require('ol.control.Constraints');



/**
 * @constructor
 * @param {ol.control.Constraints} constraints Constraints.
 */
ol.Control = function(constraints) {

  /**
   * @protected
   * @type {ol.control.Constraints}
   */
  this.constraints = constraints;

};


/**
 * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
 */
ol.Control.prototype.handleMapBrowserEvent = goog.abstractMethod;


/**
 * @param {ol.Map} map Map.
 * @param {ol.Extent} extent Extent.
 */
ol.Control.prototype.fitExtent = function(map, extent) {
  var resolution = map.getResolutionForExtent(extent);
  resolution = this.constraints.resolution(resolution, 0);
  var center = extent.getCenter();
  center = this.constraints.center(center, resolution, ol.Coordinate.ZERO);
  map.withFrozenRendering(function() {
    map.setCenter(center);
    map.setResolution(resolution);
  });
};


/**
 * @param {ol.Map} map Map.
 * @param {ol.Coordinate} delta Delta.
 * @param {ol.Coordinate=} opt_anchor Anchor.
 */
ol.Control.prototype.pan = function(map, delta, opt_anchor) {
  var center = opt_anchor ? opt_anchor : map.getCenter();
  var resolution = map.getResolution();
  center = this.constraints.center(center, resolution, delta);
  map.setCenter(center);
};


/**
 * @param {ol.Map} map Map.
 * @param {number|undefined} rotation Rotation.
 * @param {number} delta Delta.
 * @param {ol.Coordinate=} opt_anchor Anchor.
 */
ol.Control.prototype.rotate = function(map, rotation, delta, opt_anchor) {
  // FIXME handle rotation about anchor
  rotation = this.constraints.rotation(rotation, delta);
  map.setRotation(rotation);
};


/**
 * @param {ol.Map} map Map.
 * @param {number|undefined} resolution Resolution.
 */
ol.Control.prototype.setResolution = function(map, resolution) {
  resolution = this.constraints.resolution(resolution, 0);
  map.setResolution(resolution);
};


/**
 * @param {ol.Map} map Map.
 * @param {number|undefined} resolution Resolution.
 * @param {number} delta Delta.
 * @param {ol.Coordinate=} opt_anchor Anchor.
 */
ol.Control.prototype.zoom = function(map, resolution, delta, opt_anchor) {
  if (goog.isDefAndNotNull(opt_anchor)) {
    var anchor = opt_anchor;
    var mapCenter = /** @type {!ol.Coordinate} */ map.getCenter();
    var mapResolution = map.getResolution();
    resolution = this.constraints.resolution(resolution, delta);
    var x = anchor.x - resolution * (anchor.x - mapCenter.x) / mapResolution;
    var y = anchor.y - resolution * (anchor.y - mapCenter.y) / mapResolution;
    var center = new ol.Coordinate(x, y);
    center = this.constraints.center(center, resolution, ol.Coordinate.ZERO);
    map.withFrozenRendering(function() {
      map.setCenter(center);
      map.setResolution(resolution);
    });
  } else {
{'fraction_non_alphanumeric': 0.14953592299759366, 'fraction_numerical': 0.0006875214850464077, 'mean_word_length': 4.082096069868996, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1749215', 'n_tokens_mistral': 1874, 'n_tokens_neox': 1831, 'n_words': 396}