Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
4971 lines (4380 sloc) 188 KB
// Accord Math Library
// The Accord.NET Framework
// http://accord-framework.net
//
// Copyright © César Souza, 2009-2017
// cesarsouza at gmail.com
//
// This library 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.1 of the License, or (at your option) any later version.
//
// This library 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 this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
// ======================================================================
// This code has been generated by a tool; do not edit manually. Instead,
// edit the T4 template Vector.Scale.tt so this file can be regenerated.
// ======================================================================
namespace Accord.Math
{
using System;
using Accord.Math;
public static partial class Vector
{
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static int Scale(this int value, int fromMin, int fromMax, int toMin, int toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (int)value;
return (int)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this int[] values, int fromMin, int fromMax, int toMin, int toMax, int[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
return values;
}
for (int i = 0; i < values.Length; i++)
result[i] = (int)((toMax - toMin) * (values[i] - fromMin) / (int)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int Scale(this int value, IRange<int> fromRange, IRange<int> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this int[] values, int fromMin, int fromMax, int toMin, int toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new int[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this int[] values, int toMin, int toMax)
{
int[] result = new int[values.Length];
int fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this int[] values, int toMin, int toMax, int[] result)
{
int fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this int[] values, IRange<int> fromRange, IRange<int> toRange, int[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this int[] values, IRange<int> fromRange, IRange<int> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new int[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this int[] values, IRange<int> toRange, int[] result)
{
int fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static float Scale(this int value, int fromMin, int fromMax, float toMin, float toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (float)value;
return (float)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this int[] values, int fromMin, int fromMax, float toMin, float toMax, float[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (float)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (float)((toMax - toMin) * (values[i] - fromMin) / (float)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float Scale(this int value, IRange<int> fromRange, IRange<float> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this int[] values, int fromMin, int fromMax, float toMin, float toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new float[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this int[] values, float toMin, float toMax)
{
float[] result = new float[values.Length];
int fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this int[] values, float toMin, float toMax, float[] result)
{
int fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this int[] values, IRange<int> fromRange, IRange<float> toRange, float[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this int[] values, IRange<int> fromRange, IRange<float> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new float[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this int[] values, IRange<float> toRange, float[] result)
{
int fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static double Scale(this int value, int fromMin, int fromMax, double toMin, double toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (double)value;
return (double)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this int[] values, int fromMin, int fromMax, double toMin, double toMax, double[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (double)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (double)((toMax - toMin) * (values[i] - fromMin) / (double)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double Scale(this int value, IRange<int> fromRange, IRange<double> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this int[] values, int fromMin, int fromMax, double toMin, double toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new double[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this int[] values, double toMin, double toMax)
{
double[] result = new double[values.Length];
int fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this int[] values, double toMin, double toMax, double[] result)
{
int fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this int[] values, IRange<int> fromRange, IRange<double> toRange, double[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this int[] values, IRange<int> fromRange, IRange<double> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new double[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this int[] values, IRange<double> toRange, double[] result)
{
int fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static short Scale(this int value, int fromMin, int fromMax, short toMin, short toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (short)value;
return (short)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this int[] values, int fromMin, int fromMax, short toMin, short toMax, short[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (short)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (short)((toMax - toMin) * (values[i] - fromMin) / (short)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short Scale(this int value, IRange<int> fromRange, IRange<short> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this int[] values, int fromMin, int fromMax, short toMin, short toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new short[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this int[] values, short toMin, short toMax)
{
short[] result = new short[values.Length];
int fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this int[] values, short toMin, short toMax, short[] result)
{
int fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this int[] values, IRange<int> fromRange, IRange<short> toRange, short[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this int[] values, IRange<int> fromRange, IRange<short> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new short[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this int[] values, IRange<short> toRange, short[] result)
{
int fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static byte Scale(this int value, int fromMin, int fromMax, byte toMin, byte toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (byte)value;
return (byte)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this int[] values, int fromMin, int fromMax, byte toMin, byte toMax, byte[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (byte)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (byte)((toMax - toMin) * (values[i] - fromMin) / (byte)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte Scale(this int value, IRange<int> fromRange, IRange<byte> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this int[] values, int fromMin, int fromMax, byte toMin, byte toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new byte[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this int[] values, byte toMin, byte toMax)
{
byte[] result = new byte[values.Length];
int fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this int[] values, byte toMin, byte toMax, byte[] result)
{
int fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this int[] values, IRange<int> fromRange, IRange<byte> toRange, byte[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this int[] values, IRange<int> fromRange, IRange<byte> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new byte[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this int[] values, IRange<byte> toRange, byte[] result)
{
int fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static sbyte Scale(this int value, int fromMin, int fromMax, sbyte toMin, sbyte toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (sbyte)value;
return (sbyte)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this int[] values, int fromMin, int fromMax, sbyte toMin, sbyte toMax, sbyte[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (sbyte)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (sbyte)((toMax - toMin) * (values[i] - fromMin) / (sbyte)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte Scale(this int value, IRange<int> fromRange, IRange<sbyte> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this int[] values, int fromMin, int fromMax, sbyte toMin, sbyte toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new sbyte[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this int[] values, sbyte toMin, sbyte toMax)
{
sbyte[] result = new sbyte[values.Length];
int fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this int[] values, sbyte toMin, sbyte toMax, sbyte[] result)
{
int fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this int[] values, IRange<int> fromRange, IRange<sbyte> toRange, sbyte[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this int[] values, IRange<int> fromRange, IRange<sbyte> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new sbyte[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this int[] values, IRange<sbyte> toRange, sbyte[] result)
{
int fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static long Scale(this int value, int fromMin, int fromMax, long toMin, long toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (long)value;
return (long)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this int[] values, int fromMin, int fromMax, long toMin, long toMax, long[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (long)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (long)((toMax - toMin) * (values[i] - fromMin) / (long)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long Scale(this int value, IRange<int> fromRange, IRange<long> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this int[] values, int fromMin, int fromMax, long toMin, long toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new long[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this int[] values, long toMin, long toMax)
{
long[] result = new long[values.Length];
int fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this int[] values, long toMin, long toMax, long[] result)
{
int fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this int[] values, IRange<int> fromRange, IRange<long> toRange, long[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this int[] values, IRange<int> fromRange, IRange<long> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new long[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this int[] values, IRange<long> toRange, long[] result)
{
int fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static int Scale(this float value, float fromMin, float fromMax, int toMin, int toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (int)value;
return (int)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this float[] values, float fromMin, float fromMax, int toMin, int toMax, int[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (int)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (int)((toMax - toMin) * (values[i] - fromMin) / (int)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int Scale(this float value, IRange<float> fromRange, IRange<int> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this float[] values, float fromMin, float fromMax, int toMin, int toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new int[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this float[] values, int toMin, int toMax)
{
int[] result = new int[values.Length];
float fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this float[] values, int toMin, int toMax, int[] result)
{
float fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this float[] values, IRange<float> fromRange, IRange<int> toRange, int[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this float[] values, IRange<float> fromRange, IRange<int> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new int[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this float[] values, IRange<int> toRange, int[] result)
{
float fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static float Scale(this float value, float fromMin, float fromMax, float toMin, float toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (float)value;
return (float)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this float[] values, float fromMin, float fromMax, float toMin, float toMax, float[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
return values;
}
for (int i = 0; i < values.Length; i++)
result[i] = (float)((toMax - toMin) * (values[i] - fromMin) / (float)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float Scale(this float value, IRange<float> fromRange, IRange<float> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this float[] values, float fromMin, float fromMax, float toMin, float toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new float[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this float[] values, float toMin, float toMax)
{
float[] result = new float[values.Length];
float fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this float[] values, float toMin, float toMax, float[] result)
{
float fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this float[] values, IRange<float> fromRange, IRange<float> toRange, float[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this float[] values, IRange<float> fromRange, IRange<float> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new float[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this float[] values, IRange<float> toRange, float[] result)
{
float fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static double Scale(this float value, float fromMin, float fromMax, double toMin, double toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (double)value;
return (double)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this float[] values, float fromMin, float fromMax, double toMin, double toMax, double[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (double)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (double)((toMax - toMin) * (values[i] - fromMin) / (double)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double Scale(this float value, IRange<float> fromRange, IRange<double> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this float[] values, float fromMin, float fromMax, double toMin, double toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new double[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this float[] values, double toMin, double toMax)
{
double[] result = new double[values.Length];
float fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this float[] values, double toMin, double toMax, double[] result)
{
float fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this float[] values, IRange<float> fromRange, IRange<double> toRange, double[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this float[] values, IRange<float> fromRange, IRange<double> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new double[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this float[] values, IRange<double> toRange, double[] result)
{
float fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static short Scale(this float value, float fromMin, float fromMax, short toMin, short toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (short)value;
return (short)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this float[] values, float fromMin, float fromMax, short toMin, short toMax, short[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (short)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (short)((toMax - toMin) * (values[i] - fromMin) / (short)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short Scale(this float value, IRange<float> fromRange, IRange<short> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this float[] values, float fromMin, float fromMax, short toMin, short toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new short[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this float[] values, short toMin, short toMax)
{
short[] result = new short[values.Length];
float fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this float[] values, short toMin, short toMax, short[] result)
{
float fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this float[] values, IRange<float> fromRange, IRange<short> toRange, short[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this float[] values, IRange<float> fromRange, IRange<short> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new short[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this float[] values, IRange<short> toRange, short[] result)
{
float fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static byte Scale(this float value, float fromMin, float fromMax, byte toMin, byte toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (byte)value;
return (byte)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this float[] values, float fromMin, float fromMax, byte toMin, byte toMax, byte[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (byte)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (byte)((toMax - toMin) * (values[i] - fromMin) / (byte)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte Scale(this float value, IRange<float> fromRange, IRange<byte> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this float[] values, float fromMin, float fromMax, byte toMin, byte toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new byte[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this float[] values, byte toMin, byte toMax)
{
byte[] result = new byte[values.Length];
float fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this float[] values, byte toMin, byte toMax, byte[] result)
{
float fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this float[] values, IRange<float> fromRange, IRange<byte> toRange, byte[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this float[] values, IRange<float> fromRange, IRange<byte> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new byte[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this float[] values, IRange<byte> toRange, byte[] result)
{
float fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static sbyte Scale(this float value, float fromMin, float fromMax, sbyte toMin, sbyte toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (sbyte)value;
return (sbyte)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this float[] values, float fromMin, float fromMax, sbyte toMin, sbyte toMax, sbyte[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (sbyte)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (sbyte)((toMax - toMin) * (values[i] - fromMin) / (sbyte)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte Scale(this float value, IRange<float> fromRange, IRange<sbyte> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this float[] values, float fromMin, float fromMax, sbyte toMin, sbyte toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new sbyte[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this float[] values, sbyte toMin, sbyte toMax)
{
sbyte[] result = new sbyte[values.Length];
float fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this float[] values, sbyte toMin, sbyte toMax, sbyte[] result)
{
float fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this float[] values, IRange<float> fromRange, IRange<sbyte> toRange, sbyte[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this float[] values, IRange<float> fromRange, IRange<sbyte> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new sbyte[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this float[] values, IRange<sbyte> toRange, sbyte[] result)
{
float fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static long Scale(this float value, float fromMin, float fromMax, long toMin, long toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (long)value;
return (long)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this float[] values, float fromMin, float fromMax, long toMin, long toMax, long[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (long)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (long)((toMax - toMin) * (values[i] - fromMin) / (long)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long Scale(this float value, IRange<float> fromRange, IRange<long> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this float[] values, float fromMin, float fromMax, long toMin, long toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new long[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this float[] values, long toMin, long toMax)
{
long[] result = new long[values.Length];
float fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this float[] values, long toMin, long toMax, long[] result)
{
float fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this float[] values, IRange<float> fromRange, IRange<long> toRange, long[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this float[] values, IRange<float> fromRange, IRange<long> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new long[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this float[] values, IRange<long> toRange, long[] result)
{
float fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static int Scale(this double value, double fromMin, double fromMax, int toMin, int toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (int)value;
return (int)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this double[] values, double fromMin, double fromMax, int toMin, int toMax, int[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (int)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (int)((toMax - toMin) * (values[i] - fromMin) / (int)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int Scale(this double value, IRange<double> fromRange, IRange<int> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this double[] values, double fromMin, double fromMax, int toMin, int toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new int[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this double[] values, int toMin, int toMax)
{
int[] result = new int[values.Length];
double fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this double[] values, int toMin, int toMax, int[] result)
{
double fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this double[] values, IRange<double> fromRange, IRange<int> toRange, int[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this double[] values, IRange<double> fromRange, IRange<int> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new int[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this double[] values, IRange<int> toRange, int[] result)
{
double fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static float Scale(this double value, double fromMin, double fromMax, float toMin, float toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (float)value;
return (float)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this double[] values, double fromMin, double fromMax, float toMin, float toMax, float[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (float)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (float)((toMax - toMin) * (values[i] - fromMin) / (float)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float Scale(this double value, IRange<double> fromRange, IRange<float> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this double[] values, double fromMin, double fromMax, float toMin, float toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new float[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this double[] values, float toMin, float toMax)
{
float[] result = new float[values.Length];
double fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this double[] values, float toMin, float toMax, float[] result)
{
double fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this double[] values, IRange<double> fromRange, IRange<float> toRange, float[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this double[] values, IRange<double> fromRange, IRange<float> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new float[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this double[] values, IRange<float> toRange, float[] result)
{
double fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static double Scale(this double value, double fromMin, double fromMax, double toMin, double toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (double)value;
return (double)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this double[] values, double fromMin, double fromMax, double toMin, double toMax, double[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
return values;
}
for (int i = 0; i < values.Length; i++)
result[i] = (double)((toMax - toMin) * (values[i] - fromMin) / (double)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double Scale(this double value, IRange<double> fromRange, IRange<double> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this double[] values, double fromMin, double fromMax, double toMin, double toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new double[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this double[] values, double toMin, double toMax)
{
double[] result = new double[values.Length];
double fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this double[] values, double toMin, double toMax, double[] result)
{
double fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this double[] values, IRange<double> fromRange, IRange<double> toRange, double[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this double[] values, IRange<double> fromRange, IRange<double> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new double[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this double[] values, IRange<double> toRange, double[] result)
{
double fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static short Scale(this double value, double fromMin, double fromMax, short toMin, short toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (short)value;
return (short)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this double[] values, double fromMin, double fromMax, short toMin, short toMax, short[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (short)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (short)((toMax - toMin) * (values[i] - fromMin) / (short)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short Scale(this double value, IRange<double> fromRange, IRange<short> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this double[] values, double fromMin, double fromMax, short toMin, short toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new short[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this double[] values, short toMin, short toMax)
{
short[] result = new short[values.Length];
double fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this double[] values, short toMin, short toMax, short[] result)
{
double fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this double[] values, IRange<double> fromRange, IRange<short> toRange, short[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this double[] values, IRange<double> fromRange, IRange<short> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new short[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this double[] values, IRange<short> toRange, short[] result)
{
double fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static byte Scale(this double value, double fromMin, double fromMax, byte toMin, byte toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (byte)value;
return (byte)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this double[] values, double fromMin, double fromMax, byte toMin, byte toMax, byte[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (byte)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (byte)((toMax - toMin) * (values[i] - fromMin) / (byte)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte Scale(this double value, IRange<double> fromRange, IRange<byte> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this double[] values, double fromMin, double fromMax, byte toMin, byte toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new byte[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this double[] values, byte toMin, byte toMax)
{
byte[] result = new byte[values.Length];
double fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this double[] values, byte toMin, byte toMax, byte[] result)
{
double fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this double[] values, IRange<double> fromRange, IRange<byte> toRange, byte[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this double[] values, IRange<double> fromRange, IRange<byte> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new byte[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this double[] values, IRange<byte> toRange, byte[] result)
{
double fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static sbyte Scale(this double value, double fromMin, double fromMax, sbyte toMin, sbyte toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (sbyte)value;
return (sbyte)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this double[] values, double fromMin, double fromMax, sbyte toMin, sbyte toMax, sbyte[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (sbyte)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (sbyte)((toMax - toMin) * (values[i] - fromMin) / (sbyte)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte Scale(this double value, IRange<double> fromRange, IRange<sbyte> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this double[] values, double fromMin, double fromMax, sbyte toMin, sbyte toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new sbyte[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this double[] values, sbyte toMin, sbyte toMax)
{
sbyte[] result = new sbyte[values.Length];
double fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this double[] values, sbyte toMin, sbyte toMax, sbyte[] result)
{
double fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this double[] values, IRange<double> fromRange, IRange<sbyte> toRange, sbyte[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this double[] values, IRange<double> fromRange, IRange<sbyte> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new sbyte[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this double[] values, IRange<sbyte> toRange, sbyte[] result)
{
double fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static long Scale(this double value, double fromMin, double fromMax, long toMin, long toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (long)value;
return (long)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this double[] values, double fromMin, double fromMax, long toMin, long toMax, long[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (long)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (long)((toMax - toMin) * (values[i] - fromMin) / (long)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long Scale(this double value, IRange<double> fromRange, IRange<long> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this double[] values, double fromMin, double fromMax, long toMin, long toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new long[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this double[] values, long toMin, long toMax)
{
long[] result = new long[values.Length];
double fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this double[] values, long toMin, long toMax, long[] result)
{
double fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this double[] values, IRange<double> fromRange, IRange<long> toRange, long[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this double[] values, IRange<double> fromRange, IRange<long> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new long[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this double[] values, IRange<long> toRange, long[] result)
{
double fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static int Scale(this short value, short fromMin, short fromMax, int toMin, int toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (int)value;
return (int)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this short[] values, short fromMin, short fromMax, int toMin, int toMax, int[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (int)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (int)((toMax - toMin) * (values[i] - fromMin) / (int)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int Scale(this short value, IRange<short> fromRange, IRange<int> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this short[] values, short fromMin, short fromMax, int toMin, int toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new int[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this short[] values, int toMin, int toMax)
{
int[] result = new int[values.Length];
short fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this short[] values, int toMin, int toMax, int[] result)
{
short fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this short[] values, IRange<short> fromRange, IRange<int> toRange, int[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this short[] values, IRange<short> fromRange, IRange<int> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new int[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this short[] values, IRange<int> toRange, int[] result)
{
short fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static float Scale(this short value, short fromMin, short fromMax, float toMin, float toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (float)value;
return (float)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this short[] values, short fromMin, short fromMax, float toMin, float toMax, float[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (float)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (float)((toMax - toMin) * (values[i] - fromMin) / (float)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float Scale(this short value, IRange<short> fromRange, IRange<float> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this short[] values, short fromMin, short fromMax, float toMin, float toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new float[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this short[] values, float toMin, float toMax)
{
float[] result = new float[values.Length];
short fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this short[] values, float toMin, float toMax, float[] result)
{
short fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this short[] values, IRange<short> fromRange, IRange<float> toRange, float[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this short[] values, IRange<short> fromRange, IRange<float> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new float[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static float[] Scale(this short[] values, IRange<float> toRange, float[] result)
{
short fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static double Scale(this short value, short fromMin, short fromMax, double toMin, double toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (double)value;
return (double)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this short[] values, short fromMin, short fromMax, double toMin, double toMax, double[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (double)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (double)((toMax - toMin) * (values[i] - fromMin) / (double)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double Scale(this short value, IRange<short> fromRange, IRange<double> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this short[] values, short fromMin, short fromMax, double toMin, double toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new double[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this short[] values, double toMin, double toMax)
{
double[] result = new double[values.Length];
short fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this short[] values, double toMin, double toMax, double[] result)
{
short fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this short[] values, IRange<short> fromRange, IRange<double> toRange, double[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this short[] values, IRange<short> fromRange, IRange<double> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new double[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static double[] Scale(this short[] values, IRange<double> toRange, double[] result)
{
short fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static short Scale(this short value, short fromMin, short fromMax, short toMin, short toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (short)value;
return (short)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this short[] values, short fromMin, short fromMax, short toMin, short toMax, short[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
return values;
}
for (int i = 0; i < values.Length; i++)
result[i] = (short)((toMax - toMin) * (values[i] - fromMin) / (short)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short Scale(this short value, IRange<short> fromRange, IRange<short> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this short[] values, short fromMin, short fromMax, short toMin, short toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new short[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this short[] values, short toMin, short toMax)
{
short[] result = new short[values.Length];
short fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this short[] values, short toMin, short toMax, short[] result)
{
short fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this short[] values, IRange<short> fromRange, IRange<short> toRange, short[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this short[] values, IRange<short> fromRange, IRange<short> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new short[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static short[] Scale(this short[] values, IRange<short> toRange, short[] result)
{
short fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static byte Scale(this short value, short fromMin, short fromMax, byte toMin, byte toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (byte)value;
return (byte)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this short[] values, short fromMin, short fromMax, byte toMin, byte toMax, byte[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (byte)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (byte)((toMax - toMin) * (values[i] - fromMin) / (byte)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte Scale(this short value, IRange<short> fromRange, IRange<byte> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this short[] values, short fromMin, short fromMax, byte toMin, byte toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new byte[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this short[] values, byte toMin, byte toMax)
{
byte[] result = new byte[values.Length];
short fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this short[] values, byte toMin, byte toMax, byte[] result)
{
short fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this short[] values, IRange<short> fromRange, IRange<byte> toRange, byte[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this short[] values, IRange<short> fromRange, IRange<byte> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new byte[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static byte[] Scale(this short[] values, IRange<byte> toRange, byte[] result)
{
short fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static sbyte Scale(this short value, short fromMin, short fromMax, sbyte toMin, sbyte toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (sbyte)value;
return (sbyte)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this short[] values, short fromMin, short fromMax, sbyte toMin, sbyte toMax, sbyte[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (sbyte)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (sbyte)((toMax - toMin) * (values[i] - fromMin) / (sbyte)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte Scale(this short value, IRange<short> fromRange, IRange<sbyte> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this short[] values, short fromMin, short fromMax, sbyte toMin, sbyte toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new sbyte[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this short[] values, sbyte toMin, sbyte toMax)
{
sbyte[] result = new sbyte[values.Length];
short fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this short[] values, sbyte toMin, sbyte toMax, sbyte[] result)
{
short fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this short[] values, IRange<short> fromRange, IRange<sbyte> toRange, sbyte[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this short[] values, IRange<short> fromRange, IRange<sbyte> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new sbyte[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static sbyte[] Scale(this short[] values, IRange<sbyte> toRange, sbyte[] result)
{
short fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static long Scale(this short value, short fromMin, short fromMax, long toMin, long toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (long)value;
return (long)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this short[] values, short fromMin, short fromMax, long toMin, long toMax, long[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (long)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (long)((toMax - toMin) * (values[i] - fromMin) / (long)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long Scale(this short value, IRange<short> fromRange, IRange<long> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this short[] values, short fromMin, short fromMax, long toMin, long toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new long[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this short[] values, long toMin, long toMax)
{
long[] result = new long[values.Length];
short fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this short[] values, long toMin, long toMax, long[] result)
{
short fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this short[] values, IRange<short> fromRange, IRange<long> toRange, long[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this short[] values, IRange<short> fromRange, IRange<long> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new long[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static long[] Scale(this short[] values, IRange<long> toRange, long[] result)
{
short fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static int Scale(this byte value, byte fromMin, byte fromMax, int toMin, int toMax)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
return (int)value;
return (int)((toMax - toMin) * (value - fromMin) / (fromMax - fromMin) + toMin);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this byte[] values, byte fromMin, byte fromMax, int toMin, int toMax, int[] result)
{
if (fromMin == fromMax && fromMin == toMin && fromMin == toMax)
{
for (int i = 0; i < values.Length; i++)
result[i] = (int)values[i];
return result;
}
for (int i = 0; i < values.Length; i++)
result[i] = (int)((toMax - toMin) * (values[i] - fromMin) / (int)(fromMax - fromMin) + toMin);
return result;
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int Scale(this byte value, IRange<byte> fromRange, IRange<int> toRange)
{
return Scale(value, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this byte[] values, byte fromMin, byte fromMax, int toMin, int toMax)
{
return Scale(values, fromMin, fromMax, toMin, toMax, new int[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this byte[] values, int toMin, int toMax)
{
int[] result = new int[values.Length];
byte fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this byte[] values, int toMin, int toMax, int[] result)
{
byte fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toMin, toMax, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this byte[] values, IRange<byte> fromRange, IRange<int> toRange, int[] result)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this byte[] values, IRange<byte> fromRange, IRange<int> toRange)
{
return Scale(values, fromRange.Min, fromRange.Max, toRange.Min, toRange.Max, new int[values.Length]);
}
/// <summary>
/// Converts values from one scale to another scale.
/// </summary>
///
public static int[] Scale(this byte[] values, IRange<int> toRange, int[] result)
{
byte fromMin, fromMax;
values.GetRange(out fromMin, out fromMax);
return Scale(values, fromMin, fromMax, toRange.Min, toRange.Max, result);
}
/// <summary>
/// Converts a value from one scale to another scale.
/// </summary>
///
public static