com.wallstop-studios.unity-helpers 1.0.1-rc12 → 1.0.1-rc13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
namespace UnityHelpers.Core.Math
|
|
2
2
|
{
|
|
3
|
+
using System;
|
|
4
|
+
using System.Runtime.Serialization;
|
|
3
5
|
using Extension;
|
|
4
6
|
using UnityEngine;
|
|
5
7
|
|
|
6
8
|
// https://pastebin.com/iQDhQTFN
|
|
9
|
+
[Serializable]
|
|
10
|
+
[DataContract]
|
|
7
11
|
public readonly struct Line
|
|
8
12
|
{
|
|
9
13
|
public readonly Vector2 from;
|
|
@@ -48,4 +52,4 @@
|
|
|
48
52
|
return true;
|
|
49
53
|
}
|
|
50
54
|
}
|
|
51
|
-
}
|
|
55
|
+
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
[DataContract]
|
|
7
7
|
[Serializable]
|
|
8
|
-
public
|
|
8
|
+
public readonly struct Parabola
|
|
9
9
|
{
|
|
10
10
|
public readonly float Length;
|
|
11
11
|
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
{
|
|
24
24
|
throw new ArgumentException($"Expected a length greater than 0, but found: {length:0.00}.");
|
|
25
25
|
}
|
|
26
|
+
|
|
26
27
|
Length = length;
|
|
27
28
|
|
|
28
29
|
A = -4 * max / (length * length);
|
|
@@ -41,4 +42,4 @@
|
|
|
41
42
|
return true;
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
|
-
}
|
|
45
|
+
}
|
|
@@ -10,16 +10,20 @@
|
|
|
10
10
|
int j = polygon.Length - 1;
|
|
11
11
|
for (int i = 0; i < polygon.Length; i++)
|
|
12
12
|
{
|
|
13
|
-
if (polygon[i].y < point.y && polygon[j].y >= point.y ||
|
|
13
|
+
if (polygon[i].y < point.y && polygon[j].y >= point.y ||
|
|
14
|
+
polygon[j].y < point.y && polygon[i].y >= point.y)
|
|
14
15
|
{
|
|
15
|
-
if (polygon[i].x + (point.y - polygon[i].y) / (polygon[j].y - polygon[i].y) *
|
|
16
|
+
if (polygon[i].x + (point.y - polygon[i].y) / (polygon[j].y - polygon[i].y) *
|
|
17
|
+
(polygon[j].x - polygon[i].x) < point.x)
|
|
16
18
|
{
|
|
17
19
|
result = !result;
|
|
18
20
|
}
|
|
19
21
|
}
|
|
22
|
+
|
|
20
23
|
j = i;
|
|
21
24
|
}
|
|
25
|
+
|
|
22
26
|
return result;
|
|
23
27
|
}
|
|
24
28
|
}
|
|
25
|
-
}
|
|
29
|
+
}
|
|
@@ -10,22 +10,34 @@
|
|
|
10
10
|
/// </summary>
|
|
11
11
|
[Serializable]
|
|
12
12
|
[DataContract]
|
|
13
|
-
public struct Range<T> : IEquatable<Range<T>> where T: IEquatable<T>, IComparable<T>
|
|
13
|
+
public struct Range<T> : IEquatable<Range<T>> where T : IEquatable<T>, IComparable<T>
|
|
14
14
|
{
|
|
15
15
|
[DataMember]
|
|
16
16
|
public T min;
|
|
17
|
+
|
|
17
18
|
[DataMember]
|
|
18
19
|
public T max;
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
[DataMember]
|
|
22
|
+
public bool startInclusive;
|
|
23
|
+
|
|
24
|
+
[DataMember]
|
|
25
|
+
public bool endInclusive;
|
|
26
|
+
|
|
27
|
+
public Range(T min, T max, bool startInclusive = true, bool endInclusive = true)
|
|
21
28
|
{
|
|
22
29
|
this.min = min;
|
|
23
30
|
this.max = max;
|
|
31
|
+
this.startInclusive = startInclusive;
|
|
32
|
+
this.endInclusive = endInclusive;
|
|
24
33
|
}
|
|
25
34
|
|
|
26
35
|
public bool Equals(Range<T> other)
|
|
27
36
|
{
|
|
28
|
-
return Equals(
|
|
37
|
+
return min.Equals(other.min) &&
|
|
38
|
+
max.Equals(other.max) &&
|
|
39
|
+
startInclusive == other.startInclusive &&
|
|
40
|
+
endInclusive == other.endInclusive;
|
|
29
41
|
}
|
|
30
42
|
|
|
31
43
|
public override bool Equals(object obj)
|
|
@@ -35,7 +47,7 @@
|
|
|
35
47
|
|
|
36
48
|
public override int GetHashCode()
|
|
37
49
|
{
|
|
38
|
-
return Objects.HashCode(min, max);
|
|
50
|
+
return Objects.HashCode(min, max, startInclusive, endInclusive);
|
|
39
51
|
}
|
|
40
52
|
|
|
41
53
|
public override string ToString()
|
|
@@ -45,12 +57,29 @@
|
|
|
45
57
|
|
|
46
58
|
public bool WithinRange(T value)
|
|
47
59
|
{
|
|
48
|
-
|
|
60
|
+
int comparison = value.CompareTo(min);
|
|
61
|
+
if (comparison < 0)
|
|
62
|
+
{
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!startInclusive && comparison == 0)
|
|
67
|
+
{
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
comparison = value.CompareTo(max);
|
|
72
|
+
if (0 < comparison)
|
|
73
|
+
{
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (!endInclusive && comparison == 0)
|
|
49
78
|
{
|
|
50
79
|
return false;
|
|
51
80
|
}
|
|
52
81
|
|
|
53
|
-
return
|
|
82
|
+
return true;
|
|
54
83
|
}
|
|
55
84
|
}
|
|
56
|
-
}
|
|
85
|
+
}
|