<commit_before>/*
 * Copyright 2014 WebFilings, LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

define(function() {
    'use strict';

    /**
     * Utility to offset a scale to accommodate content margins.
     *
     * @param {number} dimension - The value of the dimension to offset.
     * @param {number} marginA - The margin on one side of the item.
     * @param {number} marginB - The margin on the opposite side of the item.
     * @return {number}
     */
    function marginScaleOffset(dimension, marginA, marginB) {
        return (dimension - (marginA + marginB)) / dimension;
    }

    /**
     * @classdesc
     *
     * ScaleStrategies calculate the scale required to fit items within a viewport.
     *
     * @exports ScaleStrategies
     */
    var ScaleStrategies = {

        /**
         * Calculates the scale required to fit items inside the viewport.
         *
         * @method
         * @param {{width: number, height: number}} viewportSize
         *        The size of the viewport.
         * @param {Array.<{width: number, height: number}>|{width: number, height: number}} itemSizeOrSizes
         *        The size of the item or items to fit.
         * @param {number|{left: number, right: number, top: number, bottom: number}} margin
         *        The margin around the item.
         * @returns {number}
         */
        auto: function(viewportSize, itemSizeOrSizes, margin) {
            var widthScale = ScaleStrategies.width(viewportSize, itemSizeOrSizes, margin);
            var heightScale = ScaleStrategies.height(viewportSize, itemSizeOrSizes, margin);

            return Math.min(widthScale, heightScale);
        },

        /**
         * Gets the scale required to fit the height of the viewport.
         *
         * @method
         * @param {{height: number}} viewportSize
         *        The size of the viewport.
         * @param {Array.<{height: number}>|{height: number}} itemSizeOrSizes
         *        The size of the item or items to fit.
         * @param {number|{left: number, right: number, top: number, bottom: number}} margin
         *        The margin around the item.
         * @returns {number}
         */
        height: function(viewportSize, itemSizeOrSizes, margin) {
            var viewportHeight = viewportSize.height;
            var maxPageHeight = 0;
            var sizes = Array.isArray(itemSizeOrSizes) ? itemSizeOrSizes : [itemSizeOrSizes];

            // Get the maximum page height.
            for (var i = 0, n = sizes.length; i < n; i++) {
                var size = sizes[i];
                if (size.height > maxPageHeight) {
                    maxPageHeight = size.height;
                }
            }<commit_msg>HV-193 Add guards for potential division by zero<commit_after>/*
 * Copyright 2014 WebFilings, LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

define(function() {
    'use strict';

    /**
     * Utility to offset a scale to accommodate content margins.
     *
     * @param {number} dimension - The value of the dimension to offset.
     * @param {number} marginA - The margin on one side of the item.
     * @param {number} marginB - The margin on the opposite side of the item.
     * @return {number}
     */
    function marginScaleOffset(dimension, marginA, marginB) {
        if (dimension === 0) {
            return 0;
        } else {
            return (dimension - (marginA + marginB)) / dimension;
        }
    }

    /**
     * @classdesc
     *
     * ScaleStrategies calculate the scale required to fit items within a viewport.
     *
     * @exports ScaleStrategies
     */
    var ScaleStrategies = {

        /**
         * Calculates the scale required to fit items inside the viewport.
         *
         * @method
         * @param {{width: number, height: number}} viewportSize
         *        The size of the viewport.
         * @param {Array.<{width: number, height: number}>|{width: number, height: number}} itemSizeOrSizes
         *        The size of the item or items to fit.
         * @param {number|{left: number, right: number, top: number, bottom: number}} margin
         *        The margin around the item.
         * @returns {number}
         */
        auto: function(viewportSize, itemSizeOrSizes, margin) {
            var widthScale = ScaleStrategies.width(viewportSize, itemSizeOrSizes, margin);
            var heightScale = ScaleStrategies.height(viewportSize, itemSizeOrSizes, margin);

            return Math.min(widthScale, heightScale);
        },

        /**
         * Gets the scale required to fit the height of the viewport.
         *
         * @method
         * @param {{height: number}} viewportSize
         *        The size of the viewport.
         * @param {Array.<{height: number}>|{height: number}} itemSizeOrSizes
         *        The size of the item or items to fit.
         * @param {number|{left: number, right: number, top: number, bottom: number}} margin
         *        The margin around the item.
         * @returns {number}
         */
        height: function(viewportSize, itemSizeOrSizes, margin) {
            var viewportHeight = viewportSize.height;
            var maxPageHeight = 0;
            var sizes = Array.isArray(itemSizeOrSizes) ? itemSizeOrSizes : [itemSizeOrSizes];

            // Get the maximum page height.
            for (var i = 0, n = sizes.length; i < n; i++) {
                var size = sizes[i];
                if (size.height > maxPageHeight) {
                    maxPageHeight = size.height;
                }
            }

            // Avoid division by zero below
            if (maxPageHeight === 0) {
                return 0;
            }
{'fraction_non_alphanumeric': 0.09301290609701825, 'fraction_numerical': 0.004005340453938585, 'mean_word_length': 2.0715261958997724, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3843153', 'n_tokens_mistral': 1807, 'n_tokens_neox': 1763, 'n_words': 659}