com.wallstop-studios.unity-helpers 1.0.1-rc11 → 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 sealed class Parabola
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 || polygon[j].y < point.y && polygon[i].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) * (polygon[j].x - polygon[i].x) < point.x)
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
- public Range(T min, T max)
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(min, other.min) && Equals(max, other.max);
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
- if (value.CompareTo(min) < 0)
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 value.CompareTo(max) <= 0;
82
+ return true;
54
83
  }
55
84
  }
56
- }
85
+ }
@@ -6,18 +6,22 @@
6
6
 
7
7
  public sealed class SingleThreadedThreadPool : IDisposable
8
8
  {
9
+ public ConcurrentQueue<Exception> Exceptions => _exceptions;
10
+
9
11
  private int _active;
10
12
  private int _working;
11
13
  private Thread _worker;
12
14
  private readonly ConcurrentQueue<Action> _work;
13
15
  private AutoResetEvent _waitHandle;
14
16
  private bool _disposed;
17
+ private readonly ConcurrentQueue<Exception> _exceptions;
15
18
 
16
19
  public SingleThreadedThreadPool()
17
20
  {
18
21
  _active = 1;
19
22
  _working = 1;
20
23
  _work = new ConcurrentQueue<Action>();
24
+ _exceptions = new ConcurrentQueue<Exception>();
21
25
  _waitHandle = new AutoResetEvent(false);
22
26
  _worker = new Thread(DoWork);
23
27
  _worker.Start();
@@ -40,15 +44,16 @@
40
44
  {
41
45
  workItem();
42
46
  }
43
- catch
47
+ catch (Exception e)
44
48
  {
45
- // Ignore (TODO: Log to some output function? The downside here is that this is in another thread, which means standard Unity logging is a no-go)
49
+ _exceptions.Enqueue(e);
46
50
  }
47
51
  }
48
52
  else
49
53
  {
50
54
  _ = _waitHandle.WaitOne(TimeSpan.FromSeconds(1));
51
55
  }
56
+
52
57
  _ = Interlocked.Exchange(ref _working, 0);
53
58
  }
54
59
  }
@@ -92,6 +97,7 @@
92
97
  {
93
98
  // Swallow
94
99
  }
100
+
95
101
  _waitHandle = null;
96
102
  _worker = null;
97
103
  }
@@ -99,4 +105,4 @@
99
105
  _disposed = true;
100
106
  }
101
107
  }
102
- }
108
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.wallstop-studios.unity-helpers",
3
- "version": "1.0.1-rc11",
3
+ "version": "1.0.1-rc13",
4
4
  "displayName": "Unity Helpers",
5
5
  "description": "Various Unity Helper Library",
6
6
  "dependencies": {