/
tltprog
/
MATH
Обзор
Документация
Войти
/
tltprog
/
MATH
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
RDP-algorithm/DrawingVisualApp/UsefulTools.cs
29 строк
793 B
tltrus
up
11 мар 2024, 19:06
11 мар 2024, 19:06
8438126
Код
Авторство
О чём код?
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DrawingVisualApp { internal class UsefulTools { public static double Constrain(double n, double low, double high) => Math.Max(Math.Min(n, high), low); public static double Map(double n, double start1, double stop1, double start2, double stop2, bool withinBounds = false) { double num = (n - start1) / (stop1 - start1) * (stop2 - start2) + start2; if (!withinBounds) { return num; } if (start2 < stop2) { return Constrain(num, start2, stop2); } return Constrain(num, stop2, start2); } } }