This repository has been archived by the owner on Jan 28, 2019. It is now read-only.
forked from citizenfx/NativeUI
-
Notifications
You must be signed in to change notification settings - Fork 1
/
PointExtensions.cs
80 lines (67 loc) · 2.51 KB
/
PointExtensions.cs
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using CitizenFX.Core;
using System.Drawing;
namespace NativeUI
{
public static class MiscExtensions
{
public static Random SharedRandom = new Random();
public static Point AddPoints(this Point left, Point right)
{
return new Point(left.X + right.X, left.Y + right.Y);
}
public static Point SubtractPoints(this Point left, Point right)
{
return new Point(left.X - right.X, left.Y - right.Y);
}
public static PointF AddPoints(this PointF left, PointF right)
{
return new PointF(left.X + right.X, left.Y + right.Y);
}
public static PointF SubtractPoints(this PointF left, PointF right)
{
return new PointF(left.X - right.X, left.Y - right.Y);
}
public static float Clamp(this float val, float min, float max)
{
if (val > max)
return max;
if (val < min)
return min;
return val;
}
public static Vector3 LinearVectorLerp(Vector3 start, Vector3 end, int currentTime, int duration)
{
return new Vector3()
{
X = LinearFloatLerp(start.X, end.X, currentTime, duration),
Y = LinearFloatLerp(start.Y, end.Y, currentTime, duration),
Z = LinearFloatLerp(start.Z, end.Z, currentTime, duration),
};
}
public static Vector3 VectorLerp(Vector3 start, Vector3 end, int currentTime, int duration, Func<float, float, int, int, float> easingFunc)
{
return new Vector3()
{
X = easingFunc(start.X, end.X, currentTime, duration),
Y = easingFunc(start.Y, end.Y, currentTime, duration),
Z = easingFunc(start.Z, end.Z, currentTime, duration),
};
}
public static float LinearFloatLerp(float start, float end, int currentTime, int duration)
{
float change = end - start;
return change * currentTime / duration + start;
}
public static float QuadraticEasingLerp(float start, float end, int currentTime, int duration)
{
var time = (float)currentTime;
var dur = (float)duration;
float change = end - start;
time /= dur / 2;
if (time < 1) return change / 2 * time * time + start;
time--;
return -change / 2 * (time * (time - 2) - 1) + start;
}
}
}