Repository navigation
Expand file tree
/
Copy pathControlHelpers.Math.cs
More file actions
66 lines (62 loc) · 2.47 KB
/
Copy pathControlHelpers.Math.cs
File metadata and controls
66 lines (62 loc) · 2.47 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
namespace Microsoft.Toolkit.Uwp
{
/// <summary>
/// Internal class used to provide helpers for controls
/// </summary>
internal static partial class ControlHelpers
{
/// <summary>
/// Gets the positive modulo of an integer
/// </summary>
/// <param name="value">Value to use</param>
/// <param name="module">Module to use</param>
/// <returns>Positive modulo</returns>
public static int Mod(this int value, int module)
{
int result = value % module;
return result >= 0 ? result : (result + module) % module;
}
/// <summary>
/// Gets modulo of value + 1
/// </summary>
/// <param name="value">Value to use</param>
/// <param name="module">Module to use</param>
/// <returns>Modulo of value + 1</returns>
public static int IncMod(this int value, int module)
{
return (value + 1).Mod(module);
}
/// <summary>
/// Gets modulo of value - 1
/// </summary>
/// <param name="value">Value to use</param>
/// <param name="module">Module to use</param>
/// <returns>Modulo of value - 1</returns>
public static int DecMod(this int value, int module)
{
return (value - 1).Mod(module);
}
/// <summary>
/// Gets the positive modulo of a double
/// </summary>
/// <param name="value">Value to use</param>
/// <param name="module">Module to use</param>
/// <returns>Positive modulo</returns>
public static double Mod(this double value, double module)
{
double res = value % module;
return res >= 0 ? res : (res + module) % module;
}
}
}