Files
2026-06-04 11:42:34 +02:00

383 lines
11 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ProBuilder2.Common
{
// Token: 0x0200002B RID: 43
public static class pb_IntArrayUtility
{
// Token: 0x060000D5 RID: 213 RVA: 0x00010B40 File Offset: 0x0000EF40
public static int[][] ToArray(this pb_IntArray[] val)
{
int[][] array = new int[val.Length][];
for (int i = 0; i < array.Length; i++)
{
array[i] = val[i].array;
}
return array;
}
// Token: 0x060000D6 RID: 214 RVA: 0x00010B78 File Offset: 0x0000EF78
public static Dictionary<int, int> ToDictionary(this pb_IntArray[] array)
{
Dictionary<int, int> dictionary = new Dictionary<int, int>();
for (int i = 0; i < array.Length; i++)
{
for (int j = 0; j < array[i].array.Length; j++)
{
if (!dictionary.ContainsKey(array[i][j]))
{
dictionary.Add(array[i][j], i);
}
}
}
return dictionary;
}
// Token: 0x060000D7 RID: 215 RVA: 0x00010BE0 File Offset: 0x0000EFE0
public static pb_IntArray[] ToSharedIndices(this IEnumerable<KeyValuePair<int, int>> lookup)
{
Dictionary<int, int> dictionary = new Dictionary<int, int>();
List<List<int>> list = new List<List<int>>();
foreach (KeyValuePair<int, int> keyValuePair in lookup)
{
if (keyValuePair.Value < 0)
{
list.Add(new List<int> { keyValuePair.Key });
}
else
{
int num = -1;
if (dictionary.TryGetValue(keyValuePair.Value, out num))
{
list[num].Add(keyValuePair.Key);
}
else
{
dictionary.Add(keyValuePair.Value, list.Count);
list.Add(new List<int> { keyValuePair.Key });
}
}
}
return list.ToPbIntArray();
}
// Token: 0x060000D8 RID: 216 RVA: 0x00010CD0 File Offset: 0x0000F0D0
public static pb_IntArray[] ToPbIntArray(this int[][] val)
{
pb_IntArray[] array = new pb_IntArray[val.Length];
for (int i = 0; i < array.Length; i++)
{
array[i] = (pb_IntArray)val[i];
}
return array;
}
// Token: 0x060000D9 RID: 217 RVA: 0x00010D08 File Offset: 0x0000F108
public static pb_IntArray[] ToPbIntArray(this List<List<int>> val)
{
pb_IntArray[] array = new pb_IntArray[val.Count];
for (int i = 0; i < array.Length; i++)
{
array[i] = (pb_IntArray)val[i].ToArray();
}
return array;
}
// Token: 0x060000DA RID: 218 RVA: 0x00010D4C File Offset: 0x0000F14C
public static List<List<int>> ToList(this pb_IntArray[] val)
{
List<List<int>> list = new List<List<int>>();
for (int i = 0; i < val.Length; i++)
{
list.Add(val[i].ToList());
}
return list;
}
// Token: 0x060000DB RID: 219 RVA: 0x00010D84 File Offset: 0x0000F184
public static string ToFormattedString(this pb_IntArray[] arr)
{
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < arr.Length; i++)
{
stringBuilder.Append("[" + arr[i].array.ToString(", ") + "] ");
}
return stringBuilder.ToString();
}
// Token: 0x060000DC RID: 220 RVA: 0x00010DDC File Offset: 0x0000F1DC
public static int IndexOf(this int[] array, int val, pb_IntArray[] sharedIndices)
{
int num = sharedIndices.IndexOf(val);
if (num < 0)
{
return -1;
}
int[] array2 = sharedIndices[num];
for (int i = 0; i < array.Length; i++)
{
if (Array.IndexOf<int>(array2, array[i]) > -1)
{
return i;
}
}
return -1;
}
// Token: 0x060000DD RID: 221 RVA: 0x00010E2C File Offset: 0x0000F22C
public static int IndexOf(this IList<int> indices, int triangle, ref Dictionary<int, int> lookup)
{
int num = lookup[triangle];
if (num < 0)
{
return -1;
}
int num2 = indices.Count<int>();
for (int i = 0; i < num2; i++)
{
if (lookup[indices[i]] == num)
{
return i;
}
}
return -1;
}
// Token: 0x060000DE RID: 222 RVA: 0x00010E7C File Offset: 0x0000F27C
public static int IndexOf(this pb_IntArray[] intArray, int index)
{
if (intArray == null)
{
return -1;
}
for (int i = 0; i < intArray.Length; i++)
{
for (int j = 0; j < intArray[i].Length; j++)
{
if (intArray[i][j] == index)
{
return i;
}
}
}
return -1;
}
// Token: 0x060000DF RID: 223 RVA: 0x00010ED0 File Offset: 0x0000F2D0
public static IList<int> AllIndicesWithValues(this pb_IntArray[] pbIntArr, IList<int> indices)
{
int[] array = pbIntArr.GetCommonIndices(indices).ToArray<int>();
List<int> list = new List<int>();
for (int i = 0; i < array.Length; i++)
{
list.AddRange(pbIntArr[array[i]].array);
}
return list;
}
// Token: 0x060000E0 RID: 224 RVA: 0x00010F18 File Offset: 0x0000F318
public static IList<int> AllIndicesWithValues(this pb_IntArray[] pbIntArr, Dictionary<int, int> lookup, IList<int> indices)
{
int[] array = pb_IntArrayUtility.GetCommonIndices(lookup, indices).ToArray<int>();
List<int> list = new List<int>();
for (int i = 0; i < array.Length; i++)
{
list.AddRange(pbIntArr[array[i]].array);
}
return list;
}
// Token: 0x060000E1 RID: 225 RVA: 0x00010F60 File Offset: 0x0000F360
public static IList<int> UniqueIndicesWithValues(this pb_IntArray[] pbIntArr, IList<int> indices)
{
Dictionary<int, int> dictionary = pbIntArr.ToDictionary();
HashSet<int> hashSet = new HashSet<int>();
foreach (int num in indices)
{
hashSet.Add(dictionary[num]);
}
List<int> list = new List<int>();
foreach (int num2 in hashSet)
{
list.Add(pbIntArr[num2][0]);
}
return list;
}
// Token: 0x060000E2 RID: 226 RVA: 0x00011024 File Offset: 0x0000F424
public static HashSet<int> GetCommonIndices(this pb_IntArray[] pbIntArr, IList<int> indices)
{
return pb_IntArrayUtility.GetCommonIndices(pbIntArr.ToDictionary(), indices);
}
// Token: 0x060000E3 RID: 227 RVA: 0x00011034 File Offset: 0x0000F434
public static HashSet<int> GetCommonIndices(Dictionary<int, int> lookup, IList<int> indices)
{
HashSet<int> hashSet = new HashSet<int>();
foreach (int num in indices)
{
hashSet.Add(lookup[num]);
}
return hashSet;
}
// Token: 0x060000E4 RID: 228 RVA: 0x00011098 File Offset: 0x0000F498
public static IEnumerable<int> GetIndicesWithCommon(this pb_IntArray[] pbIntArr, IEnumerable<int> common)
{
return common.Select((int x) => pbIntArr[x][0]);
}
// Token: 0x060000E5 RID: 229 RVA: 0x000110C4 File Offset: 0x0000F4C4
public static pb_IntArray[] ExtractSharedIndices(Vector3[] v)
{
Dictionary<pb_IntVec3, List<int>> dictionary = new Dictionary<pb_IntVec3, List<int>>();
for (int i = 0; i < v.Length; i++)
{
List<int> list;
if (dictionary.TryGetValue(v[i], out list))
{
list.Add(i);
}
else
{
dictionary.Add(new pb_IntVec3(v[i]), new List<int> { i });
}
}
pb_IntArray[] array = new pb_IntArray[dictionary.Count];
int num = 0;
foreach (KeyValuePair<pb_IntVec3, List<int>> keyValuePair in dictionary)
{
array[num++] = new pb_IntArray(keyValuePair.Value.ToArray());
}
return array;
}
// Token: 0x060000E6 RID: 230 RVA: 0x000111AC File Offset: 0x0000F5AC
public static int MergeSharedIndices(ref pb_IntArray[] sharedIndices, int[] indices)
{
if (indices.Length < 2)
{
return -1;
}
if (sharedIndices == null)
{
sharedIndices = new pb_IntArray[] { (pb_IntArray)indices };
return 0;
}
List<int> list = new List<int>();
List<int> list2 = new List<int>();
for (int i = 0; i < indices.Length; i++)
{
int num = sharedIndices.IndexOf(indices[i]);
if (!list.Contains(num))
{
if (num > -1)
{
list2.AddRange(sharedIndices[num].array);
list.Add(num);
}
else
{
list2.Add(indices[i]);
}
}
}
int num2 = sharedIndices.Length - list.Count;
pb_IntArray[] array = new pb_IntArray[num2];
int num3 = 0;
for (int j = 0; j < sharedIndices.Length; j++)
{
if (!list.Contains(j))
{
array[num3++] = sharedIndices[j];
}
}
sharedIndices = array.Add(new pb_IntArray(list2.ToArray()));
return sharedIndices.Length - 1;
}
// Token: 0x060000E7 RID: 231 RVA: 0x000112A8 File Offset: 0x0000F6A8
public static void MergeSharedIndices(ref pb_IntArray[] sharedIndices, int a, int b)
{
int num = sharedIndices.IndexOf(a);
int num2 = sharedIndices.IndexOf(b);
pb_IntArrayUtility.AddValueAtIndex(ref sharedIndices, num, b);
int[] array = sharedIndices[num2].array;
sharedIndices[num2].array = array.RemoveAt(Array.IndexOf<int>(array, b));
pb_IntArray.RemoveEmptyOrNull(ref sharedIndices);
}
// Token: 0x060000E8 RID: 232 RVA: 0x000112F8 File Offset: 0x0000F6F8
public static int AddValueAtIndex(ref pb_IntArray[] sharedIndices, int sharedIndex, int value)
{
if (sharedIndex > -1)
{
sharedIndices[sharedIndex].array = sharedIndices[sharedIndex].array.Add(value);
}
else
{
sharedIndices = sharedIndices.Add(new pb_IntArray(new int[] { value }));
}
return (sharedIndex <= -1) ? (sharedIndices.Length - 1) : sharedIndex;
}
// Token: 0x060000E9 RID: 233 RVA: 0x00011354 File Offset: 0x0000F754
public static int AddRangeAtIndex(ref pb_IntArray[] sharedIndices, int sharedIndex, int[] indices)
{
if (sharedIndex > -1)
{
sharedIndices[sharedIndex].array = sharedIndices[sharedIndex].array.AddRange(indices);
}
else
{
sharedIndices = sharedIndices.Add(new pb_IntArray(indices));
}
return (sharedIndex <= -1) ? (sharedIndices.Length - 1) : sharedIndex;
}
// Token: 0x060000EA RID: 234 RVA: 0x000113A8 File Offset: 0x0000F7A8
public static void RemoveValues(ref pb_IntArray[] sharedIndices, int[] remove)
{
for (int i = 0; i < sharedIndices.Length; i++)
{
for (int j = 0; j < remove.Length; j++)
{
int num = Array.IndexOf<int>(sharedIndices[i], remove[j]);
if (num > -1)
{
sharedIndices[i].array = sharedIndices[i].array.RemoveAt(num);
}
}
}
pb_IntArray.RemoveEmptyOrNull(ref sharedIndices);
}
// Token: 0x060000EB RID: 235 RVA: 0x00011418 File Offset: 0x0000F818
public static void RemoveValuesAndShift(ref pb_IntArray[] sharedIndices, IEnumerable<int> remove)
{
Dictionary<int, int> dictionary = sharedIndices.ToDictionary();
foreach (int num in remove)
{
dictionary[num] = -1;
}
sharedIndices = dictionary.Where((KeyValuePair<int, int> x) => x.Value > -1).ToSharedIndices();
List<int> list = new List<int>(remove);
list.Sort();
for (int i = 0; i < sharedIndices.Length; i++)
{
for (int j = 0; j < sharedIndices[i].Length; j++)
{
int num2 = pbUtil.NearestIndexPriorToValue<int>(list, sharedIndices[i][j]);
pb_IntArray pb_IntArray;
int num3;
(pb_IntArray = sharedIndices[i])[num3 = j] = pb_IntArray[num3] - (num2 + 1);
}
}
}
}
}