@@ -140,190 +140,225 @@ public static Vector2 SuperUnpacker(float f, float GridSizeAndPackMagic)
140
140
// return (ax * bx + ay * by + az * bz);
141
141
//}
142
142
143
- public static void ShuffleInPlace ( params IList [ ] arrays )
144
- {
145
- //ResetRandom();
143
+ // public static void ShuffleInPlace(params IList[] arrays)
144
+ // {
145
+ // //ResetRandom();
146
146
147
- // Assume all lists are the same length
148
- if ( arrays . Length == 0 || arrays [ 0 ] == null )
149
- return ;
147
+ // // Assume all lists are the same length
148
+ // if (arrays.Length == 0 || arrays[0] == null)
149
+ // return;
150
150
151
- int count = arrays [ 0 ] . Count ;
151
+ // int count = arrays[0].Count;
152
152
153
- for ( int i = count - 1 ; i > 0 ; i -- )
154
- {
155
- int rand = frnd . Next ( 0 , i + 1 ) ;
153
+ // for (int i = count - 1; i > 0; i--)
154
+ // {
155
+ // int rand = frnd.Next(0, i + 1);
156
156
157
- foreach ( var list in arrays )
158
- {
159
- if ( list == null || list . Count <= i || list . Count <= rand )
160
- continue ;
157
+ // foreach (var list in arrays)
158
+ // {
159
+ // if (list == null || list.Count <= i || list.Count <= rand)
160
+ // continue;
161
161
162
- object temp = list [ i ] ;
163
- list [ i ] = list [ rand ] ;
164
- list [ rand ] = temp ;
165
- }
166
- }
167
- }
162
+ // object temp = list[i];
163
+ // list[i] = list[rand];
164
+ // list[rand] = temp;
165
+ // }
166
+ // }
167
+ // }
168
168
169
+ private static readonly ThreadLocal < Random > threadRand = new ( ( ) => new Random ( ) ) ;
169
170
170
- public static void Shuffle ( ref List < float > array )
171
+ public static void ShufflePointAttributes ( int count ,
172
+ List < float > x , List < float > y , List < float > z ,
173
+ List < float > ? r = null , List < float > ? g = null , List < float > ? b = null ,
174
+ List < ushort > ? intensity = null ,
175
+ List < byte > ? classification = null ,
176
+ List < double > ? time = null )
171
177
{
172
- ResetRandom ( ) ;
173
- int index = array . Count ;
174
- while ( index > 1 )
178
+ var rand = threadRand . Value ! ;
179
+ for ( int i = count - 1 ; i > 0 ; i -- )
175
180
{
176
- int rand = frnd . Next ( 0 , index -- ) ;
177
- ( array [ index ] , array [ rand ] ) = ( array [ rand ] , array [ index ] ) ;
178
- }
179
- }
181
+ int j = rand . Next ( i + 1 ) ;
180
182
181
- public static void Shuffle ( ref List < byte > array )
182
- {
183
- ResetRandom ( ) ;
184
- int index = array . Count ;
185
- while ( index > 1 )
186
- {
187
- int rand = frnd . Next ( 0 , index -- ) ;
188
- ( array [ index ] , array [ rand ] ) = ( array [ rand ] , array [ index ] ) ;
189
- }
190
- }
183
+ // Swap X/Y/Z
184
+ ( x [ i ] , x [ j ] ) = ( x [ j ] , x [ i ] ) ;
185
+ ( y [ i ] , y [ j ] ) = ( y [ j ] , y [ i ] ) ;
186
+ ( z [ i ] , z [ j ] ) = ( z [ j ] , z [ i ] ) ;
191
187
192
- public static void Shuffle ( ref List < double > array )
193
- {
194
- ResetRandom ( ) ;
195
- int index = array . Count ;
196
- while ( index > 1 )
197
- {
198
- int rand = frnd . Next ( 0 , index -- ) ;
199
- ( array [ index ] , array [ rand ] ) = ( array [ rand ] , array [ index ] ) ;
200
- }
201
- }
188
+ // RGB
189
+ if ( r != null ) ( r [ i ] , r [ j ] ) = ( r [ j ] , r [ i ] ) ;
190
+ if ( g != null ) ( g [ i ] , g [ j ] ) = ( g [ j ] , g [ i ] ) ;
191
+ if ( b != null ) ( b [ i ] , b [ j ] ) = ( b [ j ] , b [ i ] ) ;
202
192
193
+ // Intensity
194
+ if ( intensity != null ) ( intensity [ i ] , intensity [ j ] ) = ( intensity [ j ] , intensity [ i ] ) ;
203
195
196
+ // Classification
197
+ if ( classification != null ) ( classification [ i ] , classification [ j ] ) = ( classification [ j ] , classification [ i ] ) ;
204
198
205
- // x,y,z,r,g,b
206
- public static void Shuffle ( ref List < float > x , ref List < float > y , ref List < float > z , ref List < float > r , ref List < float > g , ref List < float > b )
207
- {
208
- int index = x . Count ;
209
- while ( index > 1 )
210
- {
211
- //int rand = rnd.Next(index--);
212
- int rand = frnd . Next ( 0 , index -- ) ;
213
-
214
- // Swap using tuple assignment
215
- ( x [ index ] , x [ rand ] ) = ( x [ rand ] , x [ index ] ) ;
216
- ( y [ index ] , y [ rand ] ) = ( y [ rand ] , y [ index ] ) ;
217
- ( z [ index ] , z [ rand ] ) = ( z [ rand ] , z [ index ] ) ;
218
- ( r [ index ] , r [ rand ] ) = ( r [ rand ] , r [ index ] ) ;
219
- ( g [ index ] , g [ rand ] ) = ( g [ rand ] , g [ index ] ) ;
220
- ( b [ index ] , b [ rand ] ) = ( b [ rand ] , b [ index ] ) ;
199
+ // Time
200
+ if ( time != null ) ( time [ i ] , time [ j ] ) = ( time [ j ] , time [ i ] ) ;
221
201
}
222
202
}
223
203
224
- // x,y,z,r,g,b,i,t,c
225
- public static void Shuffle ( ref List < float > x , ref List < float > y , ref List < float > z , ref List < float > r , ref List < float > g , ref List < float > b , ref List < float > i , ref List < double > t , ref List < float > c )
226
- {
227
- int index = x . Count ;
228
- while ( index > 1 )
229
- {
230
- //int rand = rnd.Next(index--);
231
- int rand = frnd . Next ( 0 , index -- ) ;
232
-
233
- ( x [ index ] , x [ rand ] ) = ( x [ rand ] , x [ index ] ) ;
234
- ( y [ index ] , y [ rand ] ) = ( y [ rand ] , y [ index ] ) ;
235
- ( z [ index ] , z [ rand ] ) = ( z [ rand ] , z [ index ] ) ;
236
- ( r [ index ] , r [ rand ] ) = ( r [ rand ] , r [ index ] ) ;
237
- ( g [ index ] , g [ rand ] ) = ( g [ rand ] , g [ index ] ) ;
238
- ( b [ index ] , b [ rand ] ) = ( b [ rand ] , b [ index ] ) ;
239
- ( i [ index ] , i [ rand ] ) = ( i [ rand ] , i [ index ] ) ;
240
- ( c [ index ] , c [ rand ] ) = ( c [ rand ] , c [ index ] ) ;
241
- }
242
- }
243
204
244
- // x,y,z,r,g,b,i,c
245
- public static void Shuffle ( ref List < float > x , ref List < float > y , ref List < float > z , ref List < float > r , ref List < float > g , ref List < float > b , ref List < float > i , ref List < float > c )
246
- {
247
- int index = x . Count ;
248
- while ( index > 1 )
249
- {
250
- //int rand = rnd.Next(index--);
251
- int rand = frnd . Next ( 0 , index -- ) ;
252
- ( x [ index ] , x [ rand ] ) = ( x [ rand ] , x [ index ] ) ;
253
- ( y [ index ] , y [ rand ] ) = ( y [ rand ] , y [ index ] ) ;
254
- ( z [ index ] , z [ rand ] ) = ( z [ rand ] , z [ index ] ) ;
255
- ( r [ index ] , r [ rand ] ) = ( r [ rand ] , r [ index ] ) ;
256
- ( g [ index ] , g [ rand ] ) = ( g [ rand ] , g [ index ] ) ;
257
- ( b [ index ] , b [ rand ] ) = ( b [ rand ] , b [ index ] ) ;
258
- ( i [ index ] , i [ rand ] ) = ( i [ rand ] , i [ index ] ) ;
259
- ( c [ index ] , c [ rand ] ) = ( c [ rand ] , c [ index ] ) ;
260
- }
261
- }
205
+ //public static void Shuffle(ref List<float> array)
206
+ //{
207
+ // ResetRandom();
208
+ // int index = array.Count;
209
+ // while (index > 1)
210
+ // {
211
+ // int rand = frnd.Next(0, index--);
212
+ // (array[index], array[rand]) = (array[rand], array[index]);
213
+ // }
214
+ //}
262
215
263
- // x,y,z,r,g,b,i
264
- public static void Shuffle ( ref List < float > x , ref List < float > y , ref List < float > z , ref List < float > r , ref List < float > g , ref List < float > b , ref List < float > i )
265
- {
266
- int index = x . Count ;
267
- while ( index > 1 )
268
- {
269
- //int rand = rnd.Next(index--);
270
- int rand = frnd . Next ( 0 , index -- ) ;
271
-
272
-
273
- // Swap using tuple assignment
274
- ( x [ index ] , x [ rand ] ) = ( x [ rand ] , x [ index ] ) ;
275
- ( y [ index ] , y [ rand ] ) = ( y [ rand ] , y [ index ] ) ;
276
- ( z [ index ] , z [ rand ] ) = ( z [ rand ] , z [ index ] ) ;
277
- ( r [ index ] , r [ rand ] ) = ( r [ rand ] , r [ index ] ) ;
278
- ( g [ index ] , g [ rand ] ) = ( g [ rand ] , g [ index ] ) ;
279
- ( b [ index ] , b [ rand ] ) = ( b [ rand ] , b [ index ] ) ;
280
- ( i [ index ] , i [ rand ] ) = ( i [ rand ] , i [ index ] ) ;
281
- }
282
- }
216
+ //public static void Shuffle(ref List<byte> array)
217
+ //{
218
+ // ResetRandom();
219
+ // int index = array.Count;
220
+ // while (index > 1)
221
+ // {
222
+ // int rand = frnd.Next(0, index--);
223
+ // (array[index], array[rand]) = (array[rand], array[index]);
224
+ // }
225
+ //}
283
226
284
- // x,y,z,r,g,b,i,t
285
- public static void Shuffle ( ref List < float > x , ref List < float > y , ref List < float > z , ref List < float > r , ref List < float > g , ref List < float > b , ref List < float > i , ref List < double > t )
286
- {
287
- int index = x . Count ;
288
- while ( index > 1 )
289
- {
290
- //int rand = rnd.Next(index--);
291
- int rand = frnd . Next ( 0 , index -- ) ;
292
-
293
- // Swap using tuple assignment
294
- ( x [ index ] , x [ rand ] ) = ( x [ rand ] , x [ index ] ) ;
295
- ( y [ index ] , y [ rand ] ) = ( y [ rand ] , y [ index ] ) ;
296
- ( z [ index ] , z [ rand ] ) = ( z [ rand ] , z [ index ] ) ;
297
- ( r [ index ] , r [ rand ] ) = ( r [ rand ] , r [ index ] ) ;
298
- ( g [ index ] , g [ rand ] ) = ( g [ rand ] , g [ index ] ) ;
299
- ( b [ index ] , b [ rand ] ) = ( b [ rand ] , b [ index ] ) ;
300
- ( i [ index ] , i [ rand ] ) = ( i [ rand ] , i [ index ] ) ;
301
-
302
- // Handle double separately since it's a different type
303
- ( t [ index ] , t [ rand ] ) = ( t [ rand ] , t [ index ] ) ;
304
- }
305
- }
227
+ //public static void Shuffle(ref List<double> array)
228
+ //{
229
+ // ResetRandom();
230
+ // int index = array.Count;
231
+ // while (index > 1)
232
+ // {
233
+ // int rand = frnd.Next(0, index--);
234
+ // (array[index], array[rand]) = (array[rand], array[index]);
235
+ // }
236
+ //}
306
237
307
- // x,y,z,r,g,b,t
308
- public static void Shuffle ( ref List < float > x , ref List < float > y , ref List < float > z , ref List < float > r , ref List < float > g , ref List < float > b , ref List < double > t )
309
- {
310
- int index = x . Count ;
311
238
312
- while ( index > 1 )
313
- {
314
- //int rand = rnd.Next(index--);
315
- int rand = frnd . Next ( 0 , index -- ) ;
316
-
317
- // Swapping using tuples
318
- ( x [ index ] , x [ rand ] ) = ( x [ rand ] , x [ index ] ) ;
319
- ( y [ index ] , y [ rand ] ) = ( y [ rand ] , y [ index ] ) ;
320
- ( z [ index ] , z [ rand ] ) = ( z [ rand ] , z [ index ] ) ;
321
- ( r [ index ] , r [ rand ] ) = ( r [ rand ] , r [ index ] ) ;
322
- ( g [ index ] , g [ rand ] ) = ( g [ rand ] , g [ index ] ) ;
323
- ( b [ index ] , b [ rand ] ) = ( b [ rand ] , b [ index ] ) ;
324
- ( t [ index ] , t [ rand ] ) = ( t [ rand ] , t [ index ] ) ;
325
- }
326
- }
239
+
240
+ //// x,y,z,r,g,b
241
+ //public static void Shuffle(ref List<float> x, ref List<float> y, ref List<float> z, ref List<float> r, ref List<float> g, ref List<float> b)
242
+ //{
243
+ // int index = x.Count;
244
+ // while (index > 1)
245
+ // {
246
+ // //int rand = rnd.Next(index--);
247
+ // int rand = frnd.Next(0, index--);
248
+
249
+ // // Swap using tuple assignment
250
+ // (x[index], x[rand]) = (x[rand], x[index]);
251
+ // (y[index], y[rand]) = (y[rand], y[index]);
252
+ // (z[index], z[rand]) = (z[rand], z[index]);
253
+ // (r[index], r[rand]) = (r[rand], r[index]);
254
+ // (g[index], g[rand]) = (g[rand], g[index]);
255
+ // (b[index], b[rand]) = (b[rand], b[index]);
256
+ // }
257
+ //}
258
+
259
+ //// x,y,z,r,g,b,i,t,c
260
+ //public static void Shuffle(ref List<float> x, ref List<float> y, ref List<float> z, ref List<float> r, ref List<float> g, ref List<float> b, ref List<float> i, ref List<double> t, ref List<float> c)
261
+ //{
262
+ // int index = x.Count;
263
+ // while (index > 1)
264
+ // {
265
+ // //int rand = rnd.Next(index--);
266
+ // int rand = frnd.Next(0, index--);
267
+
268
+ // (x[index], x[rand]) = (x[rand], x[index]);
269
+ // (y[index], y[rand]) = (y[rand], y[index]);
270
+ // (z[index], z[rand]) = (z[rand], z[index]);
271
+ // (r[index], r[rand]) = (r[rand], r[index]);
272
+ // (g[index], g[rand]) = (g[rand], g[index]);
273
+ // (b[index], b[rand]) = (b[rand], b[index]);
274
+ // (i[index], i[rand]) = (i[rand], i[index]);
275
+ // (c[index], c[rand]) = (c[rand], c[index]);
276
+ // }
277
+ //}
278
+
279
+ //// x,y,z,r,g,b,i,c
280
+ //public static void Shuffle(ref List<float> x, ref List<float> y, ref List<float> z, ref List<float> r, ref List<float> g, ref List<float> b, ref List<float> i, ref List<float> c)
281
+ //{
282
+ // int index = x.Count;
283
+ // while (index > 1)
284
+ // {
285
+ // //int rand = rnd.Next(index--);
286
+ // int rand = frnd.Next(0, index--);
287
+ // (x[index], x[rand]) = (x[rand], x[index]);
288
+ // (y[index], y[rand]) = (y[rand], y[index]);
289
+ // (z[index], z[rand]) = (z[rand], z[index]);
290
+ // (r[index], r[rand]) = (r[rand], r[index]);
291
+ // (g[index], g[rand]) = (g[rand], g[index]);
292
+ // (b[index], b[rand]) = (b[rand], b[index]);
293
+ // (i[index], i[rand]) = (i[rand], i[index]);
294
+ // (c[index], c[rand]) = (c[rand], c[index]);
295
+ // }
296
+ //}
297
+
298
+ //// x,y,z,r,g,b,i
299
+ //public static void Shuffle(ref List<float> x, ref List<float> y, ref List<float> z, ref List<float> r, ref List<float> g, ref List<float> b, ref List<float> i)
300
+ //{
301
+ // int index = x.Count;
302
+ // while (index > 1)
303
+ // {
304
+ // //int rand = rnd.Next(index--);
305
+ // int rand = frnd.Next(0, index--);
306
+
307
+
308
+ // // Swap using tuple assignment
309
+ // (x[index], x[rand]) = (x[rand], x[index]);
310
+ // (y[index], y[rand]) = (y[rand], y[index]);
311
+ // (z[index], z[rand]) = (z[rand], z[index]);
312
+ // (r[index], r[rand]) = (r[rand], r[index]);
313
+ // (g[index], g[rand]) = (g[rand], g[index]);
314
+ // (b[index], b[rand]) = (b[rand], b[index]);
315
+ // (i[index], i[rand]) = (i[rand], i[index]);
316
+ // }
317
+ //}
318
+
319
+ //// x,y,z,r,g,b,i,t
320
+ //public static void Shuffle(ref List<float> x, ref List<float> y, ref List<float> z, ref List<float> r, ref List<float> g, ref List<float> b, ref List<float> i, ref List<double> t)
321
+ //{
322
+ // int index = x.Count;
323
+ // while (index > 1)
324
+ // {
325
+ // //int rand = rnd.Next(index--);
326
+ // int rand = frnd.Next(0, index--);
327
+
328
+ // // Swap using tuple assignment
329
+ // (x[index], x[rand]) = (x[rand], x[index]);
330
+ // (y[index], y[rand]) = (y[rand], y[index]);
331
+ // (z[index], z[rand]) = (z[rand], z[index]);
332
+ // (r[index], r[rand]) = (r[rand], r[index]);
333
+ // (g[index], g[rand]) = (g[rand], g[index]);
334
+ // (b[index], b[rand]) = (b[rand], b[index]);
335
+ // (i[index], i[rand]) = (i[rand], i[index]);
336
+
337
+ // // Handle double separately since it's a different type
338
+ // (t[index], t[rand]) = (t[rand], t[index]);
339
+ // }
340
+ //}
341
+
342
+ //// x,y,z,r,g,b,t
343
+ //public static void Shuffle(ref List<float> x, ref List<float> y, ref List<float> z, ref List<float> r, ref List<float> g, ref List<float> b, ref List<double> t)
344
+ //{
345
+ // int index = x.Count;
346
+
347
+ // while (index > 1)
348
+ // {
349
+ // //int rand = rnd.Next(index--);
350
+ // int rand = frnd.Next(0, index--);
351
+
352
+ // // Swapping using tuples
353
+ // (x[index], x[rand]) = (x[rand], x[index]);
354
+ // (y[index], y[rand]) = (y[rand], y[index]);
355
+ // (z[index], z[rand]) = (z[rand], z[index]);
356
+ // (r[index], r[rand]) = (r[rand], r[index]);
357
+ // (g[index], g[rand]) = (g[rand], g[index]);
358
+ // (b[index], b[rand]) = (b[rand], b[index]);
359
+ // (t[index], t[rand]) = (t[rand], t[index]);
360
+ // }
361
+ //}
327
362
328
363
// https://stackoverflow.com/a/110570/5452781
329
364
public static void ShuffleXYZ ( ref float [ ] array1 )
0 commit comments