<commit_before>// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

cr.define('print_preview', function() {
  'use strict';

  /**
   * Creates a Margins object that holds four margin values. The units in which
   * the values are expressed can be any numeric value.
   * @constructor
   * @param {number} left The left margin.
   * @param {number} top The top margin.
   * @param {number} right The right margin.
   * @param {number} bottom The bottom margin.
   */
  function Margins(left, top, right, bottom) {
    this[MarginSettings.LEFT_GROUP] = left;
    this[MarginSettings.TOP_GROUP] = top;
    this[MarginSettings.RIGHT_GROUP] = right;
    this[MarginSettings.BOTTOM_GROUP] = bottom;
  }

  /**
   * Rounds |value| keeping |precision| decimal numbers. Example: 32.76643
   * becomes 32.77.
   * @param {number} value The number to round.
   * @param {number} precision The desired precision.
   * @return {number} The rounded number.
   */
  Margins.roundToPrecision = function(value, precision) {
    return Math.round(value * Math.pow(10, precision)) /
        Math.pow(10, precision);
  }

  Margins.prototype = {
    /**
     * Checks if |rhs| is equal to |this|.
     * @param {Margins} rhs The Margins object to compare against.
     * @return {boolean} true if they are equal.
     */
    isEqual: function(rhs) {
      if (!rhs)
        return false;
      return this[MarginSettings.TOP_GROUP] === rhs[MarginSettings.TOP_GROUP] &&
          this[MarginSettings.LEFT_GROUP] === rhs[MarginSettings.LEFT_GROUP] &&
          this[MarginSettings.RIGHT_GROUP] ===
              rhs[MarginSettings.RIGHT_GROUP] &&
          this[MarginSettings.BOTTOM_GROUP] ===
              rhs[MarginSettings.BOTTOM_GROUP];
    },

    clone: function() {
      return new Margins(this[MarginSettings.TOP_GROUP],
                         this[MarginSettings.LEFT_GROUP],
                         this[MarginSettings.RIGHT_GROUP],
                         this[MarginSettings.BOTTOM_GROUP]);
    },

    /**
     * Helper method returning an array of the string indices used for accessing
     * all margins.
     * @return {array} An array of string indices.
     * @private
     */
    indicesAsArray_: function() {
      return [MarginSettings.LEFT_GROUP, MarginSettings.TOP_GROUP,
          MarginSettings.RIGHT_GROUP, MarginSettings.BOTTOM_GROUP];
    },

    /**
     * Rounds |this| based on the precision used when displaying the margins in
     * the user's prefered units. This is done by converting from points to
     * those units (mm/inches) and back to points.
     */
    roundToLocaleUnits: function() {
      var indicesAsArray = this.indicesAsArray_();
      for (var i = 0; i < indicesAsArray.length; i++) {
        this[indicesAsArray[i]] =
            print_preview.convertPointsToLocaleUnitsAndBack(
                this[indicesAsArray[i]]);
      }<commit_msg>PrintPreview: Fix a regression caused by r110055.<commit_after>// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

cr.define('print_preview', function() {
  'use strict';

  /**
   * Creates a Margins object that holds four margin values. The units in which
   * the values are expressed can be any numeric value.
   * @constructor
   * @param {number} left The left margin.
   * @param {number} top The top margin.
   * @param {number} right The right margin.
   * @param {number} bottom The bottom margin.
   */
  function Margins(left, top, right, bottom) {
    this[MarginSettings.LEFT_GROUP] = left;
    this[MarginSettings.TOP_GROUP] = top;
    this[MarginSettings.RIGHT_GROUP] = right;
    this[MarginSettings.BOTTOM_GROUP] = bottom;
  }

  /**
   * Rounds |value| keeping |precision| decimal numbers. Example: 32.76643
   * becomes 32.77.
   * @param {number} value The number to round.
   * @param {number} precision The desired precision.
   * @return {number} The rounded number.
   */
  Margins.roundToPrecision = function(value, precision) {
    return Math.round(value * Math.pow(10, precision)) /
        Math.pow(10, precision);
  }

  Margins.prototype = {
    /**
     * Checks if |rhs| is equal to |this|.
     * @param {Margins} rhs The Margins object to compare against.
     * @return {boolean} true if they are equal.
     */
    isEqual: function(rhs) {
      if (!rhs)
        return false;
      return this[MarginSettings.TOP_GROUP] === rhs[MarginSettings.TOP_GROUP] &&
          this[MarginSettings.LEFT_GROUP] === rhs[MarginSettings.LEFT_GROUP] &&
          this[MarginSettings.RIGHT_GROUP] ===
              rhs[MarginSettings.RIGHT_GROUP] &&
          this[MarginSettings.BOTTOM_GROUP] ===
              rhs[MarginSettings.BOTTOM_GROUP];
    },

    clone: function() {
      return new Margins(this[MarginSettings.LEFT_GROUP],
                         this[MarginSettings.TOP_GROUP],
                         this[MarginSettings.RIGHT_GROUP],
                         this[MarginSettings.BOTTOM_GROUP]);
    },

    /**
     * Helper method returning an array of the string indices used for accessing
     * all margins.
     * @return {array} An array of string indices.
     * @private
     */
    indicesAsArray_: function() {
      return [MarginSettings.LEFT_GROUP, MarginSettings.TOP_GROUP,
          MarginSettings.RIGHT_GROUP, MarginSettings.BOTTOM_GROUP];
    },

    /**
     * Rounds |this| based on the precision used when displaying the margins in
     * the user's prefered units. This is done by converting from points to
     * those units (mm/inches) and back to points.
     */
    roundToLocaleUnits: function() {
      var indicesAsArray = this.indicesAsArray_();
      for (var i = 0; i < indicesAsArray.length; i++) {
        this[indicesAsArray[i]] =
            print_preview.convertPointsToLocaleUnitsAndBack(
                this[indicesAsArray[i]]);
      }
{'fraction_non_alphanumeric': 0.10543766578249338, 'fraction_numerical': 0.007625994694960212, 'mean_word_length': 2.674177831912302, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5448443', 'n_tokens_mistral': 1774, 'n_tokens_neox': 1741, 'n_words': 510}