Iuvo Unity 0.5.1
This is library containing a variety of helper classes and extension methods for the Unity gane engine.
GitHub | Iuvo Unity Updates | Creator
Loading...
Searching...
No Matches
IuvoUnity.DataStructs.Chain< T > Class Template Reference

Public Member Functions

void PushFront (Link< T > toAdd)
void PushBack (Link< T > toAdd)
void RebuildLinks ()
void Remove (Link< T > toRemove)
void RemoveAll ()
Link< T > FindClosest (System.Func< T, float > distanceFunc)
Chain< T > Clone ()
void Reverse ()
void MakeCircular ()
void InsertAt (Link< T > toAdd, Link< T > prev, Link< T > next)
void ValidateLinks ()

Static Public Member Functions

static List< Link< T > > GetForwardPath (Link< T > start, int max=100)

Public Attributes

List< Link< T > > Links = new List<Link<T>>()

Member Function Documentation

◆ Clone()

Chain< T > IuvoUnity.DataStructs.Chain< T >.Clone ( )
105 {
106 var newChain = new Chain<T>();
107 foreach (var link in Links)
108 {
109 newChain.PushBack(link.Clone());
110 }
111 newChain.RebuildLinks();
112 return newChain;
113 }

References Links.

◆ FindClosest()

Link< T > IuvoUnity.DataStructs.Chain< T >.FindClosest ( System.Func< T, float > distanceFunc)
89 {
90 Link<T> closest = null;
91 float minDistance = float.MaxValue;
92 foreach (var link in Links)
93 {
94 float dist = distanceFunc(link.GetData());
95 if (dist < minDistance)
96 {
97 minDistance = dist;
98 closest = link;
99 }
100 }
101 return closest;
102 }

References Links.

◆ GetForwardPath()

List< Link< T > > IuvoUnity.DataStructs.Chain< T >.GetForwardPath ( Link< T > start,
int max = 100 )
static
116 {
117 var list = new List<Link<T>>();
118 var current = start;
119 int count = 0;
120 while (current != null && count++ < max)
121 {
122 list.Add(current);
123 current = current.TryGetNext();
124 }
125 return list;
126 }

◆ InsertAt()

void IuvoUnity.DataStructs.Chain< T >.InsertAt ( Link< T > toAdd,
Link< T > prev,
Link< T > next )
146 {
147 if (toAdd == null) return;
148 if (Links.Contains(toAdd)) return;
149
150 if (prev != null && !Links.Contains(prev))
151 {
152 IuvoDebug.DebugLogWarning("InsertAt: prev not in list");
153 return;
154 }
155 if (next != null && !Links.Contains(next))
156 {
157 IuvoDebug.DebugLogWarning("InsertAt: next not in list");
158 return;
159 }
160
161 if (prev != null)
162 prev.SetNext(toAdd);
163 if (next != null)
164 next.SetPrevious(toAdd);
165
166 toAdd.SetPrevious(prev);
167 toAdd.SetNext(next);
168
169 int index = Links.IndexOf(prev);
170 if (index >= 0)
171 Links.Insert(index + 1, toAdd);
172 else
173 Links.Add(toAdd);
174
175 RebuildLinks();
176 }

References IuvoUnity.Debug.IuvoDebug.DebugLogWarning(), Links, RebuildLinks(), IuvoUnity.DataStructs.Link< T >.SetNext(), and IuvoUnity.DataStructs.Link< T >.SetPrevious().

◆ MakeCircular()

void IuvoUnity.DataStructs.Chain< T >.MakeCircular ( )
135 {
136 if (Links.Count < 2) return;
137
138 var first = Links[0];
139 var last = Links[Links.Count - 1];
140
141 last.SetNext(first);
142 first.SetPrevious(last);
143 }

References Links.

◆ PushBack()

void IuvoUnity.DataStructs.Chain< T >.PushBack ( Link< T > toAdd)
32 {
33 if (Links.Contains(toAdd))
34 return;
35
36 if (Links.Count == 0)
37 {
38 Links.Add(toAdd);
39 return;
40 }
41
42 var last = Links[Links.Count - 1];
43 last.SetNext(toAdd);
44 toAdd.SetPrevious(last);
45 toAdd.SetNext(null);
46 Links.Add(toAdd);
47 }

References Links, IuvoUnity.DataStructs.Link< T >.SetNext(), and IuvoUnity.DataStructs.Link< T >.SetPrevious().

◆ PushFront()

void IuvoUnity.DataStructs.Chain< T >.PushFront ( Link< T > toAdd)
14 {
15 if (Links.Contains(toAdd))
16 return;
17
18 if (Links.Count == 0)
19 {
20 Links.Add(toAdd);
21 return;
22 }
23
24 var first = Links[0];
25 toAdd.SetNext(first);
26 first.SetPrevious(toAdd);
27 toAdd.SetPrevious(null);
28 Links.Insert(0, toAdd);
29 }

References Links, IuvoUnity.DataStructs.Link< T >.SetNext(), and IuvoUnity.DataStructs.Link< T >.SetPrevious().

◆ RebuildLinks()

void IuvoUnity.DataStructs.Chain< T >.RebuildLinks ( )
50 {
51 for (int i = 0; i < Links.Count; i++)
52 {
53 var current = Links[i];
54 Link<T> next = i < Links.Count - 1 ? Links[i + 1] : null;
55 Link<T> prev = i > 0 ? Links[i - 1] : null;
56
57 current.SetNext(next);
58 current.SetPrevious(prev);
59 }
60 }

References Links.

Referenced by InsertAt(), and Reverse().

◆ Remove()

void IuvoUnity.DataStructs.Chain< T >.Remove ( Link< T > toRemove)
63 {
64 if (!Links.Contains(toRemove)) return;
65
66 var prev = toRemove.TryGetPrevious();
67 var next = toRemove.TryGetNext();
68
69 if (prev != null) prev.SetNext(next);
70 if (next != null) next.SetPrevious(prev);
71
72 toRemove.SetNext(null);
73 toRemove.SetPrevious(null);
74
75 Links.Remove(toRemove);
76 }

References Links, IuvoUnity.DataStructs.Link< T >.SetNext(), IuvoUnity.DataStructs.Link< T >.SetPrevious(), IuvoUnity.DataStructs.Link< T >.TryGetNext(), and IuvoUnity.DataStructs.Link< T >.TryGetPrevious().

◆ RemoveAll()

void IuvoUnity.DataStructs.Chain< T >.RemoveAll ( )
79 {
80 foreach (var link in Links)
81 {
82 link.SetNext(null);
83 link.SetPrevious(null);
84 }
85 Links.Clear();
86 }

References Links.

◆ Reverse()

void IuvoUnity.DataStructs.Chain< T >.Reverse ( )
129 {
130 Links.Reverse();
131 RebuildLinks();
132 }

References Links, and RebuildLinks().

◆ ValidateLinks()

void IuvoUnity.DataStructs.Chain< T >.ValidateLinks ( )
179 {
180 for (int i = 0; i < Links.Count; i++)
181 {
182 var link = Links[i];
183
184 var next = link.TryGetNext();
185 if (next != null && next.TryGetPrevious() != link)
186 {
187 IuvoDebug.DebugLogWarning($"Next link mismatch at index {i}");
188 }
189
190 var prev = link.TryGetPrevious();
191 if (prev != null && prev.TryGetNext() != link)
192 {
193 IuvoDebug.DebugLogWarning($"Previous link mismatch at index {i}");
194 }
195 }
196 }

References IuvoUnity.Debug.IuvoDebug.DebugLogWarning(), and Links.

Member Data Documentation

◆ Links

List<Link<T> > IuvoUnity.DataStructs.Chain< T >.Links = new List<Link<T>>()

The documentation for this class was generated from the following file:
  • D:/Unity/IuvoUnityCore/Assets/IuvoUnity/Runtime/DataStructs/Chain.cs