3 protected ref array<ref array<vector>> m_aOutlineSegments = {};
4 protected ref array<vector> m_aOutlineCentres = {};
5 protected ref array<float> m_aOutlineRadii = {};
6 protected float m_fSetDistanceSq;
12 bool IsPosDistanceEqualOrCloserThan(vector pos,
float distance)
17 foreach (
int i, array<vector> segment : m_aOutlineSegments)
19 if (Math3D.PointLineSegmentDistanceSqr(pos, segment[0], segment[1]) <=
distance)
30 bool IsPosWithinSetDistance(vector pos)
34 foreach (
int i, array<vector> segment : m_aOutlineSegments)
36 if (Math3D.PointLineSegmentDistanceSqr(pos, segment[0], segment[1]) <= m_fSetDistanceSq)
45 protected static array<float> GetOutlineDiffLines(notnull array<float> oldPoints, notnull array<float> newPoints)
51 int oldCount = oldPoints.Count();
52 int newCount = newPoints.Count();
54 if (newCount > oldCount)
55 return GetOutlineDiffLines_PointAdded(oldPoints, newPoints);
57 if (newCount < oldCount)
58 return GetOutlineDiffLines_PointsRemoved(oldPoints, newPoints);
60 return GetOutlineDiffLines_PointsMoved(oldPoints, newPoints);
71 protected static array<float> GetOutlineDiffLines_PointsRemoved(notnull array<float> oldPoints, notnull array<float> newPoints)
73 int oldCount = oldPoints.Count();
74 int newCount = newPoints.Count();
79 array<int> removedIndices = {};
80 array<int> relatedIndices = {};
84 for (
int i; i < newCount; i += 2)
86 bool isRelated =
false;
88 for (; indexOld < oldCount; indexOld += 2)
90 if (newPoints[i] != oldPoints[indexOld] || newPoints[i + 1] != oldPoints[indexOld + 1])
92 removedIndices.Insert(indexOld * 0.5);
103 relatedIndices.Insert(i * 0.5);
106 if (indexOld < oldCount)
108 if (!relatedIndices.Contains(0))
109 relatedIndices.Insert(0);
111 if (!relatedIndices.Contains(newCount * 0.5 - 1))
112 relatedIndices.Insert(newCount * 0.5 - 1);
117 array<float> result = {};
118 foreach (
int removedIndex : removedIndices)
120 int floatIndex = removedIndex * 2;
124 oldPoints[oldCount - 2], oldPoints[oldCount - 1], oldPoints[0], oldPoints[1],
125 oldPoints[0], oldPoints[1], oldPoints[2], oldPoints[3],
128 else if (floatIndex == oldCount - 2)
131 oldPoints[oldCount - 4], oldPoints[oldCount - 3], oldPoints[oldCount - 2], oldPoints[oldCount - 1],
132 oldPoints[oldCount - 2], oldPoints[oldCount - 1], oldPoints[0], oldPoints[1],
138 oldPoints[floatIndex - 2], oldPoints[floatIndex - 1], oldPoints[floatIndex], oldPoints[floatIndex + 1],
139 oldPoints[floatIndex], oldPoints[floatIndex + 1], oldPoints[floatIndex + 2], oldPoints[floatIndex + 3],
143 foreach (
float value : tmp)
145 result.Insert(value);
151 foreach (
int relatedIndex : relatedIndices)
153 int floatIndex = relatedIndex * 2;
157 newPoints[newCount - 2], newPoints[newCount - 1], newPoints[0], newPoints[1],
158 newPoints[0], newPoints[1], newPoints[2], newPoints[3],
161 else if (floatIndex == newCount - 2)
164 newPoints[newCount - 4], newPoints[newCount - 3], newPoints[newCount - 2], newPoints[newCount - 1],
165 newPoints[newCount - 2], newPoints[newCount - 1], newPoints[0], newPoints[1],
171 newPoints[floatIndex - 2], newPoints[floatIndex - 1], newPoints[floatIndex], newPoints[floatIndex + 1],
172 newPoints[floatIndex], newPoints[floatIndex + 1], newPoints[floatIndex + 2], newPoints[floatIndex + 3],
176 foreach (
float value : tmp)
178 result.Insert(value);
188 protected static array<float> GetOutlineDiffLines_PointsMoved(notnull array<float> oldPoints, notnull array<float> newPoints)
191 int count = oldPoints.Count();
195 int lastIndex = count - 2;
197 float prevOldPoint[2];
198 float currOldPoint[2];
199 float nextOldPoint[2];
201 float prevNewPoint[2];
202 float currNewPoint[2];
203 float nextNewPoint[2];
206 array<float> result = {};
207 for (
int i; i < count; i += 2)
209 if (oldPoints[i] != newPoints[i] || newPoints[i + 1] != newPoints[i + 1])
211 currOldPoint = { oldPoints[i], oldPoints[i + 1] };
212 currNewPoint = { newPoints[i], newPoints[i + 1] };
216 prevOldPoint = { oldPoints[lastIndex], oldPoints[lastIndex + 1] };
217 nextOldPoint = { oldPoints[i + 2], oldPoints[i + 3] };
219 prevNewPoint = { newPoints[lastIndex], newPoints[lastIndex + 1] };
220 nextNewPoint = { newPoints[i + 2], newPoints[i + 3] };
222 else if (i == lastIndex)
224 prevOldPoint = { oldPoints[i - 2], oldPoints[i - 1] };
225 nextOldPoint = { oldPoints[0], oldPoints[1] };
227 prevNewPoint = { newPoints[i - 2], oldPoints[i - 1] };
228 nextNewPoint = { newPoints[0], oldPoints[1] };
232 prevOldPoint = { oldPoints[i - 2], oldPoints[i - 1] };
233 nextOldPoint = { oldPoints[i + 2], oldPoints[i + 3] };
235 prevNewPoint = { newPoints[i - 2], oldPoints[i - 1] };
236 nextNewPoint = { newPoints[i + 2], newPoints[i + 3] };
240 prevOldPoint[0], prevOldPoint[1], currOldPoint[0], currOldPoint[1],
241 nextOldPoint[0], nextOldPoint[1], currOldPoint[0], currOldPoint[1],
243 prevNewPoint[0], prevNewPoint[1], currNewPoint[0], currNewPoint[1],
244 nextNewPoint[0], nextNewPoint[1], currNewPoint[0], currNewPoint[1],
247 foreach (
float value : tmp)
249 result.Insert(value);
266 protected static array<float> GetOutlineDiffLines_PointAdded(notnull array<float> oldPoints, notnull array<float> newPoints)
268 int newCount = newPoints.Count();
272 int oldCount = oldPoints.Count();
274 for (
int i; i < oldCount; i += 2)
276 if (oldPoints[i] != newPoints[i] || oldPoints[i + 1] != newPoints[i + 1])
283 bool isLastPoint =
false;
287 index = oldCount + 2;
290 float newPoint[2] = { newPoints[
index], newPoints[
index + 1] };
297 prevPoint = { oldPoints[oldCount - 2], oldPoints[oldCount - 1] };
298 nextPoint = { oldPoints[
index + 2], oldPoints[
index + 3] };
300 else if (isLastPoint)
302 prevPoint = { newPoints[
index - 2], oldPoints[
index - 1] };
303 nextPoint = { oldPoints[0], oldPoints[1] };
307 prevPoint = { oldPoints[
index - 2], oldPoints[
index - 1] };
308 nextPoint = { oldPoints[
index + 2], oldPoints[
index + 3] };
311 float oldPoint[2] = {
312 nextPoint[0] + 0.5 * (nextPoint[0] - prevPoint[0]),
313 nextPoint[1] + 0.5 * (nextPoint[1] - prevPoint[1]),
317 prevPoint[0], prevPoint[1], oldPoint[0], oldPoint[1],
318 nextPoint[0], nextPoint[1], oldPoint[0], oldPoint[1],
320 prevPoint[0], prevPoint[1], newPoint[0], newPoint[1],
321 nextPoint[0], nextPoint[1], newPoint[0], newPoint[1],
328 array<float> allOutlinePoints = GetOutlineDiffLines(oldPoints, newPoints);
330 array<vector> segment;
331 for (
int i, count = allOutlinePoints.Count(); i < count; i += 4)
334 { allOutlinePoints[i], 0, allOutlinePoints[i + 1] },
335 { allOutlinePoints[i + 2], 0, allOutlinePoints[i + 3] },
338 m_aOutlineSegments.Insert(segment);
339 m_aOutlineCentres.Insert(vector.Lerp(segment[0], segment[1], 0.5));
340 m_aOutlineRadii.Insert(vector.DistanceXZ(segment[0], segment[1]) * 0.5);
343 m_fSetDistanceSq = setDistance * setDistance;