forked from klokantech/VectorTileRenderer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cs
More file actions
46 lines (42 loc) · 1.3 KB
/
Utils.cs
File metadata and controls
46 lines (42 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VectorTileRenderer
{
static class Utils
{
public static double ConvertRange(double oldValue, double oldMin, double oldMax, double newMin, double newMax, bool clamp = false)
{
double NewRange;
double NewValue;
double OldRange = (oldMax - oldMin);
if (OldRange == 0)
{
NewValue = newMin;
}
else
{
NewRange = (newMax - newMin);
NewValue = (((oldValue - oldMin) * NewRange) / OldRange) + newMin;
}
if (clamp)
{
NewValue = Math.Min(Math.Max(NewValue, newMin), newMax);
}
return NewValue;
}
public static string Sha256(string randomString)
{
var crypt = new System.Security.Cryptography.SHA256Managed();
var hash = new System.Text.StringBuilder();
byte[] crypto = crypt.ComputeHash(Encoding.UTF8.GetBytes(randomString));
foreach (byte theByte in crypto)
{
hash.Append(theByte.ToString("x2"));
}
return hash.ToString();
}
}
}