Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Fragment.cs
Go to the documentation of this file.
1using System;
3
5
6public class Fragment
7{
8 public readonly Vector4[] Colors;
9
10 private readonly Vector2[] _canvasPositions;
11
12 private readonly Point[] _gridPositions;
13
14 public readonly int Count;
15
16 public Vector2 CanvasTopLeft { get; private set; }
17
18 public Vector2 CanvasBottomRight { get; private set; }
19
20 public Vector2 CanvasSize { get; private set; }
21
22 public Vector2 CanvasCenter { get; private set; }
23
24 private Fragment(Point[] gridPositions)
25 : this(gridPositions, CreateCanvasPositions(gridPositions))
26 {
27 }
28
29 private Fragment(Point[] gridPositions, Vector2[] canvasPositions)
30 {
31 Count = gridPositions.Length;
32 _gridPositions = gridPositions;
33 _canvasPositions = canvasPositions;
34 Colors = (Vector4[])(object)new Vector4[Count];
36 }
37
38 public static Fragment FromGrid(Rectangle grid)
39 {
40 //IL_0000: Unknown result type (might be due to invalid IL or missing references)
41 //IL_0006: Unknown result type (might be due to invalid IL or missing references)
42 //IL_004f: Unknown result type (might be due to invalid IL or missing references)
43 //IL_0042: Unknown result type (might be due to invalid IL or missing references)
44 //IL_0023: Unknown result type (might be due to invalid IL or missing references)
45 //IL_002b: Unknown result type (might be due to invalid IL or missing references)
46 //IL_0033: Unknown result type (might be due to invalid IL or missing references)
47 //IL_0038: Unknown result type (might be due to invalid IL or missing references)
48 Point[] array = (Point[])(object)new Point[grid.Width * grid.Height];
49 int num = 0;
50 for (int i = 0; i < grid.Height; i++)
51 {
52 for (int j = 0; j < grid.Width; j++)
53 {
54 array[num++] = new Point(grid.X + j, grid.Y + i);
55 }
56 }
57 return new Fragment(array);
58 }
59
60 public static Fragment FromCustom(Point[] gridPositions)
61 {
62 return new Fragment(gridPositions);
63 }
64
65 public static Fragment FromCustom(Point[] gridPositions, Vector2[] canvasPositions)
66 {
67 return new Fragment(gridPositions, canvasPositions);
68 }
69
71 {
73 }
74
76 {
77 //IL_0007: Unknown result type (might be due to invalid IL or missing references)
78 return _canvasPositions[index];
79 }
80
82 {
83 //IL_0007: Unknown result type (might be due to invalid IL or missing references)
84 return _gridPositions[index];
85 }
86
87 public void Clear()
88 {
89 //IL_000b: Unknown result type (might be due to invalid IL or missing references)
90 //IL_0010: Unknown result type (might be due to invalid IL or missing references)
91 for (int i = 0; i < Colors.Length; i++)
92 {
93 Colors[i] = Vector4.Zero;
94 }
95 }
96
97 public void SetColor(int index, Vector4 color)
98 {
99 //IL_0007: Unknown result type (might be due to invalid IL or missing references)
100 //IL_0008: Unknown result type (might be due to invalid IL or missing references)
101 Colors[index] = color;
102 }
103
104 public void SetColor(int index, float r, float g, float b, float a = 1f)
105 {
106 //IL_000d: Unknown result type (might be due to invalid IL or missing references)
107 //IL_0012: Unknown result type (might be due to invalid IL or missing references)
108 Colors[index] = new Vector4(r, g, b, a);
109 }
110
112 {
113 //IL_0000: Unknown result type (might be due to invalid IL or missing references)
114 //IL_0005: Unknown result type (might be due to invalid IL or missing references)
115 //IL_000a: Unknown result type (might be due to invalid IL or missing references)
116 //IL_0012: Unknown result type (might be due to invalid IL or missing references)
117 //IL_0017: Unknown result type (might be due to invalid IL or missing references)
118 //IL_001c: Unknown result type (might be due to invalid IL or missing references)
119 //IL_002c: Unknown result type (might be due to invalid IL or missing references)
120 //IL_0036: Unknown result type (might be due to invalid IL or missing references)
121 Vector4 zero = Vector4.Zero;
122 for (int i = 0; i < Colors.Length; i++)
123 {
124 zero += Colors[i];
125 }
126 return zero / (float)Colors.Length;
127 }
128
129 private void SetupCanvasBounds()
130 {
131 //IL_00d2: Unknown result type (might be due to invalid IL or missing references)
132 //IL_00df: Unknown result type (might be due to invalid IL or missing references)
133 //IL_00f0: Unknown result type (might be due to invalid IL or missing references)
134 //IL_00fc: Unknown result type (might be due to invalid IL or missing references)
135 //IL_0102: Unknown result type (might be due to invalid IL or missing references)
136 //IL_010c: Unknown result type (might be due to invalid IL or missing references)
137 //IL_0111: Unknown result type (might be due to invalid IL or missing references)
138 if (_canvasPositions.Length != 0)
139 {
140 float num = _canvasPositions[0].X;
141 float num2 = _canvasPositions[0].X;
142 float num3 = _canvasPositions[0].Y;
143 float num4 = _canvasPositions[0].Y;
144 for (int i = 1; i < _canvasPositions.Length; i++)
145 {
146 num = Math.Min(num, _canvasPositions[i].X);
147 num3 = Math.Min(num3, _canvasPositions[i].Y);
148 num2 = Math.Max(num2, _canvasPositions[i].X);
149 num4 = Math.Max(num4, _canvasPositions[i].Y);
150 }
151 CanvasTopLeft = new Vector2(num, num3);
152 CanvasBottomRight = new Vector2(num2, num4);
153 CanvasSize = new Vector2(num2 - num, num4 - num3);
155 }
156 }
157
158 private static Vector2[] CreateCanvasPositions(Point[] gridPositions)
159 {
160 //IL_00d4: Unknown result type (might be due to invalid IL or missing references)
161 //IL_00db: Unknown result type (might be due to invalid IL or missing references)
162 //IL_00e0: Unknown result type (might be due to invalid IL or missing references)
163 //IL_00e2: Unknown result type (might be due to invalid IL or missing references)
164 //IL_00e7: Unknown result type (might be due to invalid IL or missing references)
165 Vector2[] array = (Vector2[])(object)new Vector2[gridPositions.Length];
166 int num = gridPositions[0].Y;
167 int num2 = gridPositions[0].Y;
168 int num3 = gridPositions[0].X;
169 for (int i = 1; i < gridPositions.Length; i++)
170 {
171 num3 = Math.Min(num3, gridPositions[i].X);
172 num = Math.Min(num, gridPositions[i].Y);
173 num2 = Math.Max(num2, gridPositions[i].Y);
174 }
175 float num4 = 1f;
176 if (num2 != num)
177 {
178 num4 = 1f / (float)(num2 - num);
179 }
180 Vector2 vector = default(Vector2);
181 ((Vector2)(ref vector))._002Ector((float)num3 * (1f / 6f), (float)num * (1f / 6f));
182 for (int j = 0; j < gridPositions.Length; j++)
183 {
184 array[j] = new Vector2((float)(gridPositions[j].X - num3), (float)(gridPositions[j].Y - num)) * num4 + vector;
185 }
186 return array;
187 }
188}
Fragment(Point[] gridPositions)
Definition Fragment.cs:24
static Fragment FromCustom(Point[] gridPositions, Vector2[] canvasPositions)
Definition Fragment.cs:65
Point GetGridPositionOfIndex(int index)
Definition Fragment.cs:81
readonly Vector2[] _canvasPositions
Definition Fragment.cs:10
readonly Vector4[] Colors
Definition Fragment.cs:8
readonly Point[] _gridPositions
Definition Fragment.cs:12
static Fragment FromCustom(Point[] gridPositions)
Definition Fragment.cs:60
void SetColor(int index, Vector4 color)
Definition Fragment.cs:97
static Fragment FromGrid(Rectangle grid)
Definition Fragment.cs:38
Vector2 GetCanvasPositionOfIndex(int index)
Definition Fragment.cs:75
static Vector2[] CreateCanvasPositions(Point[] gridPositions)
Definition Fragment.cs:158
void SetColor(int index, float r, float g, float b, float a=1f)
Definition Fragment.cs:104
Fragment(Point[] gridPositions, Vector2[] canvasPositions)
Definition Fragment.cs:29
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static byte Max(byte val1, byte val2)
Definition Math.cs:738