com.wallstop-studios.unity-helpers 2.0.0-rc13 → 2.0.0-rc15
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.
- package/Editor/EnsureTextureSizeWizard.cs +110 -0
- package/Editor/EnsureTextureSizeWizard.cs.meta +3 -0
- package/README.md +1 -1
- package/Runtime/Core/DataStructure/KDTree.cs +123 -19
- package/Runtime/Core/DataStructure/QuadTree.cs +118 -23
- package/Runtime/Core/DataStructure/RTree.cs +140 -51
- package/Runtime/Core/Extension/ColorExtensions.cs +267 -1
- package/Runtime/Core/Extension/UnityExtensions.cs +10 -0
- package/Runtime/Core/Helper/Geometry.cs +17 -0
- package/Runtime/Core/Helper/SpriteHelpers.cs +36 -3
- package/Runtime/Core/Random/PcgRandom.cs +2 -2
- package/Runtime/Core/Random/RomuDuo.cs +116 -0
- package/Runtime/Core/Random/RomuDuo.cs.meta +3 -0
- package/Runtime/Core/Random/SplitMix64.cs +94 -0
- package/Runtime/Core/Random/SplitMix64.cs.meta +3 -0
- package/Runtime/Core/Random/XorShiroRandom.cs +117 -0
- package/Runtime/Core/Random/XorShiroRandom.cs.meta +3 -0
- package/Runtime/UI/LayeredImage.cs +364 -0
- package/Runtime/UI/LayeredImage.cs.meta +3 -0
- package/Runtime/UI.meta +3 -0
- package/Tests/Runtime/Performance/RandomPerformanceTests.cs +3 -0
- package/Tests/Runtime/Random/RomuDuoRandomTests.cs +9 -0
- package/Tests/Runtime/Random/RomuDuoRandomTests.cs.meta +3 -0
- package/Tests/Runtime/Random/SplitMix64RandomTests.cs +9 -0
- package/Tests/Runtime/Random/SplitMix64RandomTests.cs.meta +3 -0
- package/Tests/Runtime/Random/XorShiroRandomTests.cs +9 -0
- package/Tests/Runtime/Random/XorShiroRandomTests.cs.meta +3 -0
- package/package.json +1 -1
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
{
|
|
18
18
|
public static IRandom Instance => ThreadLocalRandom<PcgRandom>.Instance;
|
|
19
19
|
|
|
20
|
+
public override RandomState InternalState => new(_state, _increment, _cachedGaussian);
|
|
21
|
+
|
|
20
22
|
internal readonly ulong _increment;
|
|
21
23
|
|
|
22
24
|
internal ulong _state;
|
|
@@ -53,8 +55,6 @@
|
|
|
53
55
|
_increment = NextUlong();
|
|
54
56
|
}
|
|
55
57
|
|
|
56
|
-
public override RandomState InternalState => new(_state, _increment, _cachedGaussian);
|
|
57
|
-
|
|
58
58
|
public override uint NextUint()
|
|
59
59
|
{
|
|
60
60
|
unchecked
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
namespace UnityHelpers.Core.Random
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
using System.Runtime.CompilerServices;
|
|
5
|
+
using System.Runtime.Serialization;
|
|
6
|
+
using System.Text.Json.Serialization;
|
|
7
|
+
using Extension;
|
|
8
|
+
using Helper;
|
|
9
|
+
|
|
10
|
+
[Serializable]
|
|
11
|
+
[DataContract]
|
|
12
|
+
public sealed class RomuDuo
|
|
13
|
+
: AbstractRandom,
|
|
14
|
+
IEquatable<RomuDuo>,
|
|
15
|
+
IComparable,
|
|
16
|
+
IComparable<RomuDuo>
|
|
17
|
+
{
|
|
18
|
+
public static IRandom Instance => ThreadLocalRandom<RomuDuo>.Instance;
|
|
19
|
+
public override RandomState InternalState => new(_x, _y, _cachedGaussian);
|
|
20
|
+
|
|
21
|
+
internal ulong _x;
|
|
22
|
+
internal ulong _y;
|
|
23
|
+
|
|
24
|
+
public RomuDuo()
|
|
25
|
+
: this(Guid.NewGuid()) { }
|
|
26
|
+
|
|
27
|
+
public RomuDuo(Guid guid)
|
|
28
|
+
{
|
|
29
|
+
byte[] bytes = guid.ToByteArray();
|
|
30
|
+
_x = BitConverter.ToUInt64(bytes, 0);
|
|
31
|
+
_y = BitConverter.ToUInt64(bytes, sizeof(ulong));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public RomuDuo(ulong seedX, ulong seedY)
|
|
35
|
+
{
|
|
36
|
+
_x = seedX;
|
|
37
|
+
_y = seedY;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
[JsonConstructor]
|
|
41
|
+
public RomuDuo(RandomState internalState)
|
|
42
|
+
{
|
|
43
|
+
_x = internalState.State1;
|
|
44
|
+
_y = internalState.State2;
|
|
45
|
+
_cachedGaussian = internalState.Gaussian;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public override uint NextUint()
|
|
49
|
+
{
|
|
50
|
+
unchecked
|
|
51
|
+
{
|
|
52
|
+
ulong xp = _x;
|
|
53
|
+
_x = 15241094284759029579UL * _y;
|
|
54
|
+
_y = Rol64(_y, 27) + xp;
|
|
55
|
+
return (uint)xp;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public override IRandom Copy()
|
|
60
|
+
{
|
|
61
|
+
return new RomuDuo(InternalState);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
65
|
+
private static ulong Rol64(ulong x, int k)
|
|
66
|
+
{
|
|
67
|
+
return (x << k) | (x >> (64 - k));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public override bool Equals(object obj)
|
|
71
|
+
{
|
|
72
|
+
return Equals(obj as RomuDuo);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public bool Equals(RomuDuo other)
|
|
76
|
+
{
|
|
77
|
+
if (other == null)
|
|
78
|
+
{
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return _x == other._x && _y == other._y;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public override int GetHashCode()
|
|
86
|
+
{
|
|
87
|
+
return Objects.ValueTypeHashCode(_x, _y);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public override string ToString()
|
|
91
|
+
{
|
|
92
|
+
return this.ToJson();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public int CompareTo(object obj)
|
|
96
|
+
{
|
|
97
|
+
return CompareTo(obj as RomuDuo);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public int CompareTo(RomuDuo other)
|
|
101
|
+
{
|
|
102
|
+
if (other == null)
|
|
103
|
+
{
|
|
104
|
+
return -1;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
int comparison = _x.CompareTo(other._x);
|
|
108
|
+
if (comparison != 0)
|
|
109
|
+
{
|
|
110
|
+
return comparison;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return _y.CompareTo(other._y);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
namespace UnityHelpers.Core.Random
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
using System.Runtime.Serialization;
|
|
5
|
+
using System.Text.Json.Serialization;
|
|
6
|
+
|
|
7
|
+
[Serializable]
|
|
8
|
+
[DataContract]
|
|
9
|
+
public sealed class SplitMix64
|
|
10
|
+
: AbstractRandom,
|
|
11
|
+
IEquatable<SplitMix64>,
|
|
12
|
+
IComparable,
|
|
13
|
+
IComparable<SplitMix64>
|
|
14
|
+
{
|
|
15
|
+
public static IRandom Instance => ThreadLocalRandom<SplitMix64>.Instance;
|
|
16
|
+
|
|
17
|
+
public override RandomState InternalState => new(_state, 0, _cachedGaussian);
|
|
18
|
+
|
|
19
|
+
internal ulong _state;
|
|
20
|
+
|
|
21
|
+
public SplitMix64()
|
|
22
|
+
: this(Guid.NewGuid()) { }
|
|
23
|
+
|
|
24
|
+
public SplitMix64(Guid guid)
|
|
25
|
+
: this(BitConverter.ToUInt64(guid.ToByteArray(), 0)) { }
|
|
26
|
+
|
|
27
|
+
public SplitMix64(ulong seed)
|
|
28
|
+
{
|
|
29
|
+
_state = seed;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
[JsonConstructor]
|
|
33
|
+
public SplitMix64(RandomState internalState)
|
|
34
|
+
{
|
|
35
|
+
_state = internalState.State1;
|
|
36
|
+
_cachedGaussian = internalState.Gaussian;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public override uint NextUint()
|
|
40
|
+
{
|
|
41
|
+
unchecked
|
|
42
|
+
{
|
|
43
|
+
_state += 0x9E3779B97F4A7C15UL;
|
|
44
|
+
|
|
45
|
+
ulong z = _state;
|
|
46
|
+
z = (z ^ (z >> 30)) * 0xBF58476D1CE4E5B9UL;
|
|
47
|
+
z = (z ^ (z >> 27)) * 0x94D049BB133111EBUL;
|
|
48
|
+
z ^= (z >> 31);
|
|
49
|
+
|
|
50
|
+
return (uint)z;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public override IRandom Copy()
|
|
55
|
+
{
|
|
56
|
+
return new SplitMix64(InternalState);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public bool Equals(SplitMix64 other)
|
|
60
|
+
{
|
|
61
|
+
if (other == null)
|
|
62
|
+
{
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return _state == other._state;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public int CompareTo(object obj)
|
|
70
|
+
{
|
|
71
|
+
return CompareTo(obj as SplitMix64);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public int CompareTo(SplitMix64 other)
|
|
75
|
+
{
|
|
76
|
+
if (other == null)
|
|
77
|
+
{
|
|
78
|
+
return -1;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return _state.CompareTo(other._state);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public override int GetHashCode()
|
|
85
|
+
{
|
|
86
|
+
return _state.GetHashCode();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public override string ToString()
|
|
90
|
+
{
|
|
91
|
+
return $"{{\"State\": {_state}}}";
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
namespace UnityHelpers.Core.Random
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
using System.Runtime.CompilerServices;
|
|
5
|
+
using System.Text.Json.Serialization;
|
|
6
|
+
using Extension;
|
|
7
|
+
using Helper;
|
|
8
|
+
|
|
9
|
+
public sealed class XorShiroRandom
|
|
10
|
+
: AbstractRandom,
|
|
11
|
+
IEquatable<XorShiroRandom>,
|
|
12
|
+
IComparable,
|
|
13
|
+
IComparable<XorShiroRandom>
|
|
14
|
+
{
|
|
15
|
+
public override RandomState InternalState => new(_s0, _s1, _cachedGaussian);
|
|
16
|
+
|
|
17
|
+
internal ulong _s0;
|
|
18
|
+
internal ulong _s1;
|
|
19
|
+
|
|
20
|
+
public XorShiroRandom()
|
|
21
|
+
: this(Guid.NewGuid()) { }
|
|
22
|
+
|
|
23
|
+
public XorShiroRandom(Guid guid)
|
|
24
|
+
{
|
|
25
|
+
byte[] bytes = guid.ToByteArray();
|
|
26
|
+
_s0 = BitConverter.ToUInt64(bytes, 0);
|
|
27
|
+
_s1 = BitConverter.ToUInt64(bytes, 8);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public XorShiroRandom(ulong seed1, ulong seed2)
|
|
31
|
+
{
|
|
32
|
+
_s0 = seed1;
|
|
33
|
+
_s1 = seed2;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
[JsonConstructor]
|
|
37
|
+
public XorShiroRandom(RandomState internalState)
|
|
38
|
+
{
|
|
39
|
+
_s0 = internalState.State1;
|
|
40
|
+
_s1 = internalState.State2;
|
|
41
|
+
_cachedGaussian = internalState.Gaussian;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public override uint NextUint()
|
|
45
|
+
{
|
|
46
|
+
unchecked
|
|
47
|
+
{
|
|
48
|
+
ulong s0 = _s0;
|
|
49
|
+
ulong s1 = _s1;
|
|
50
|
+
ulong result = s0 + s1;
|
|
51
|
+
|
|
52
|
+
s1 ^= s0;
|
|
53
|
+
_s0 = Rotl(s0, 24) ^ s1 ^ (s1 << 16);
|
|
54
|
+
_s1 = Rotl(s1, 37);
|
|
55
|
+
|
|
56
|
+
return (uint)result;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public override IRandom Copy()
|
|
61
|
+
{
|
|
62
|
+
return new XorShiroRandom(InternalState);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
66
|
+
private static ulong Rotl(ulong x, int k)
|
|
67
|
+
{
|
|
68
|
+
return (x << k) | (x >> (64 - k));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public override bool Equals(object obj)
|
|
72
|
+
{
|
|
73
|
+
return Equals(obj as XorShiroRandom);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public bool Equals(XorShiroRandom other)
|
|
77
|
+
{
|
|
78
|
+
if (other == null)
|
|
79
|
+
{
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return _s0 == other._s0 && _s1 == other._s1;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public override int GetHashCode()
|
|
87
|
+
{
|
|
88
|
+
return Objects.ValueTypeHashCode(_s0, _s1);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public override string ToString()
|
|
92
|
+
{
|
|
93
|
+
return this.ToJson();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public int CompareTo(object obj)
|
|
97
|
+
{
|
|
98
|
+
return CompareTo(obj as XorShiroRandom);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public int CompareTo(XorShiroRandom other)
|
|
102
|
+
{
|
|
103
|
+
if (other == null)
|
|
104
|
+
{
|
|
105
|
+
return -1;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
int comparison = _s0.CompareTo(other._s0);
|
|
109
|
+
if (comparison != 0)
|
|
110
|
+
{
|
|
111
|
+
return comparison;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return _s1.CompareTo(other._s1);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|