<commit_before>// Copyright 2009 - <NAME> (Geodan)
// 
// This file is part of Mapsui.
// Mapsui is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// Mapsui is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.

// You should have received a copy of the GNU Lesser General Public License
// along with Mapsui; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 

using System;
using System.Collections.Generic;
using Mapsui.Styles;

namespace Mapsui.Utilities
{
    public static class ZoomHelper
    {
        public static double ZoomIn(IList<double> resolutions, double resolution)
        {
            if (resolutions.Count == 0) return resolution / 2.0;
            
            //smaller than smallest
            if (resolutions[resolutions.Count - 1] > resolution) return resolutions[resolutions.Count - 1];

            foreach (double resolutionOfLevel in resolutions)
            {
                if (resolutionOfLevel < resolution)
                    return resolutionOfLevel;
            }
            return resolutions[resolutions.Count - 1];
        }

        public static double ClipToExtremes(IList<double> resolutions, double resolution)
        {
            if (resolutions.Count == 0) return resolution;

            //smaller than smallest
            if (resolutions[resolutions.Count - 1] > (resolution + 0.2 * resolution)) return resolutions[resolutions.Count - 1];

            //bigger than biggest
            if (resolutions[0] < resolution) return resolutions[0];

            return resolution;
        }

        public static double ZoomOut(IList<double> resolutions, double resolution)
        {
            if (resolutions.Count == 0) return resolution * 2.0;

            //bigger than biggest
            if (resolutions[0] < resolution) return resolutions[0];

            for (int i = resolutions.Count - 1; i >= 0; i--)
            {
                if (resolutions[i] > (resolution + 0.2 * resolution))
                    return resolutions[i];
            }
            return resolutions[0];
        }

        public static double DetermineResolution(double worldWidth, double worldHeight, double screenWidth, double screenHeight, ScaleMethod scaleMethod = ScaleMethod.Fit)
        {
            double widthResolution = worldWidth / screenWidth;
            double heightResolution = worldHeight/screenHeight;

            switch (scaleMethod)
            {
                case ScaleMethod.FitHeight:
                    return heightResolution;
                case ScaleMethod.FitWidth:
                    return widthResolution;
                case ScaleMethod.Fill:
                    return Math.Min(widthResolution, heightResolution);
                case ScaleMethod.Fit:<commit_msg>Removing old 0.2 correction on ZoomHelper<commit_after>// Copyright 2009 - <NAME> (Geodan)
// 
// This file is part of Mapsui.
// Mapsui is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// Mapsui is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.

// You should have received a copy of the GNU Lesser General Public License
// along with Mapsui; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 

using System;
using System.Collections.Generic;

namespace Mapsui.Utilities
{
    public static class ZoomHelper
    {
        public static double ZoomIn(IList<double> resolutions, double resolution)
        {
            if (resolutions.Count == 0) return resolution / 2.0;
            
            //smaller than smallest
            if (resolutions[resolutions.Count - 1] > resolution) return resolutions[resolutions.Count - 1];

            foreach (double resolutionOfLevel in resolutions)
            {
                if (resolutionOfLevel < resolution) return resolutionOfLevel;
            }
            return resolutions[resolutions.Count - 1];
        }

        public static double ClipToExtremes(IList<double> resolutions, double resolution)
        {
            if (resolutions.Count == 0) return resolution;

            //smaller than smallest
            if (resolutions[resolutions.Count - 1] > resolution) return resolutions[resolutions.Count - 1];

            //bigger than biggest
            if (resolutions[0] < resolution) return resolutions[0];

            return resolution;
        }

        public static double ZoomOut(IList<double> resolutions, double resolution)
        {
            if (resolutions.Count == 0) return resolution * 2.0;

            //bigger than biggest
            if (resolutions[0] < resolution) return resolutions[0];

            for (int i = resolutions.Count - 1; i >= 0; i--)
            {
                if (resolutions[i] > resolution) return resolutions[i];
            }
            return resolutions[0];
        }

        public static double DetermineResolution(double worldWidth, double worldHeight, double screenWidth, double screenHeight, ScaleMethod scaleMethod = ScaleMethod.Fit)
        {
            double widthResolution = worldWidth / screenWidth;
            double heightResolution = worldHeight/screenHeight;

            switch (scaleMethod)
            {
                case ScaleMethod.FitHeight:
                    return heightResolution;
                case ScaleMethod.FitWidth:
                    return widthResolution;
                case ScaleMethod.Fill:
                    return Math.Min(widthResolution, heightResolution);
                case ScaleMethod.Fit:
{'fraction_non_alphanumeric': 0.07445626289887283, 'fraction_numerical': 0.013017939355453246, 'mean_word_length': 2.131212723658052, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, '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': '3284497', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1470, 'n_words': 562}