This repository was archived by the owner on Jan 3, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathHelper.cs
More file actions
493 lines (467 loc) · 16.8 KB
/
Copy pathHelper.cs
File metadata and controls
493 lines (467 loc) · 16.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
namespace RubiksCubeSolver
{
public static class Helper
{
/// <summary>
/// returns the opposite side
/// </summary>
/// <param name="relativeSide"></param>
/// <returns></returns>
public static RelativeSidePosition GetOppositeRelativeSide(RelativeSidePosition relativeSide)
{
switch (relativeSide)
{
case RelativeSidePosition.Bottom: return RelativeSidePosition.Top;
case RelativeSidePosition.Top: return RelativeSidePosition.Bottom;
case RelativeSidePosition.Left: return RelativeSidePosition.Right;
case RelativeSidePosition.Right: return RelativeSidePosition.Left;
case RelativeSidePosition.Opposite: return RelativeSidePosition.Self;
case RelativeSidePosition.Self: return RelativeSidePosition.Opposite;
default: return RelativeSidePosition.NotExisting;
}
}
/// <summary>
/// returns the opposite edge
/// </summary>
/// <param name="relativeEdge"></param>
/// <returns></returns>
public static RelativeEdgePosition GetOppositeRelativeEdge(RelativeEdgePosition relativeEdge)
{
switch (relativeEdge)
{
case RelativeEdgePosition.Bottom: return RelativeEdgePosition.Top;
case RelativeEdgePosition.Top: return RelativeEdgePosition.Bottom;
case RelativeEdgePosition.Left: return RelativeEdgePosition.Right;
case RelativeEdgePosition.Right: return RelativeEdgePosition.Left;
default: return RelativeEdgePosition.NotExisting;
}
}
/// <summary>
/// converts the relative side to the according relative edge
/// </summary>
/// <param name="relativeSide"></param>
/// <returns></returns>
public static RelativeEdgePosition ConvertRelativeSidePositionToRelativeEdgePosition(RelativeSidePosition relativeSide)
{
switch (relativeSide)
{
case RelativeSidePosition.Bottom: return RelativeEdgePosition.Bottom;
case RelativeSidePosition.Top: return RelativeEdgePosition.Top;
case RelativeSidePosition.Left: return RelativeEdgePosition.Left;
case RelativeSidePosition.Right: return RelativeEdgePosition.Right;
default: return RelativeEdgePosition.NotExisting;
}
}
/// <summary>
/// treats the cube as if it were rotated so that the relativeEdgePosition is bottom
/// and then returns the side that is given by relativeSidePosition
/// </summary>
/// <param name="startSide"></param>
/// <param name="relativeSidePosition"></param>
/// <param name="relativeEdgePosition"></param>
/// <returns></returns>
public static Side GetRotationNeutralRelativeSide(Side startSide,
RelativeSidePosition relativeSidePosition, RelativeEdgePosition relativeEdgePosition)
{
if (relativeEdgePosition == RelativeEdgePosition.Left)
{
if (relativeSidePosition == RelativeSidePosition.Left) return startSide.Top;
if (relativeSidePosition == RelativeSidePosition.Right) return startSide.Bottom;
if (relativeSidePosition == RelativeSidePosition.Bottom) return startSide.Left;
if (relativeSidePosition == RelativeSidePosition.Top) return startSide.Right;
if (relativeSidePosition == RelativeSidePosition.Opposite) return startSide.Opposite;
if (relativeSidePosition == RelativeSidePosition.Self) return startSide;
}
if (relativeEdgePosition == RelativeEdgePosition.Right)
{
if (relativeSidePosition == RelativeSidePosition.Left) return startSide.Bottom;
if (relativeSidePosition == RelativeSidePosition.Right) return startSide.Top;
if (relativeSidePosition == RelativeSidePosition.Bottom) return startSide.Right;
if (relativeSidePosition == RelativeSidePosition.Top) return startSide.Left;
if (relativeSidePosition == RelativeSidePosition.Opposite) return startSide.Opposite;
if (relativeSidePosition == RelativeSidePosition.Self) return startSide;
}
if (relativeEdgePosition == RelativeEdgePosition.Top)
{
if (relativeSidePosition == RelativeSidePosition.Left) return startSide.Right;
if (relativeSidePosition == RelativeSidePosition.Right) return startSide.Left;
if (relativeSidePosition == RelativeSidePosition.Bottom) return startSide.Top;
if (relativeSidePosition == RelativeSidePosition.Top) return startSide.Bottom;
if (relativeSidePosition == RelativeSidePosition.Opposite) return startSide.Opposite;
if (relativeSidePosition == RelativeSidePosition.Self) return startSide;
}
if (relativeEdgePosition == RelativeEdgePosition.Bottom)
{
if (relativeSidePosition == RelativeSidePosition.Left) return startSide.Left;
if (relativeSidePosition == RelativeSidePosition.Right) return startSide.Right;
if (relativeSidePosition == RelativeSidePosition.Bottom) return startSide.Bottom;
if (relativeSidePosition == RelativeSidePosition.Top) return startSide.Top;
if (relativeSidePosition == RelativeSidePosition.Opposite) return startSide.Opposite;
if (relativeSidePosition == RelativeSidePosition.Self) return startSide;
}
return null;
}
/// <summary>
/// treats the cube as if it were rotated so that the relativeEdgePosition is bottom
/// and then returns the side relation of the start side and the relative side
/// </summary>
/// <param name="startSide"></param>
/// <param name="relativeSidePosition"></param>
/// <param name="relativeEdgePosition"></param>
/// <returns></returns>
public static RelativeSidePosition GetRotationNeutralRelativeSidePosition(Side startSide,
RelativeSidePosition relativeSidePosition, RelativeEdgePosition relativeEdgePosition)
{
return GetSideRelation(startSide.CubeSide, GetRotationNeutralRelativeSide(startSide, relativeSidePosition, relativeEdgePosition).CubeSide);
}
/// <summary>
/// gets the relation of the two given Sides
/// </summary>
/// <param name="startSide"></param>
/// <param name="relationSide"></param>
/// <returns></returns>
public static RelativeSidePosition GetSideRelation(Sides startSide, Sides relationSide)
{
if (startSide == Sides.Front)
{
if (relationSide == Sides.Front)
{
return RelativeSidePosition.Self;
}
if (relationSide == Sides.Back)
{
return RelativeSidePosition.Opposite;
}
if (relationSide == Sides.Left)
{
return RelativeSidePosition.Left;
}
if (relationSide == Sides.Right)
{
return RelativeSidePosition.Right;
}
if (relationSide == Sides.Top)
{
return RelativeSidePosition.Top;
}
if (relationSide == Sides.Bottom)
{
return RelativeSidePosition.Bottom;
}
}
if (startSide == Sides.Left)
{
if (relationSide == Sides.Front)
{
return RelativeSidePosition.Right;
}
if (relationSide == Sides.Back)
{
return RelativeSidePosition.Left;
}
if (relationSide == Sides.Left)
{
return RelativeSidePosition.Self;
}
if (relationSide == Sides.Right)
{
return RelativeSidePosition.Opposite;
}
if (relationSide == Sides.Top)
{
return RelativeSidePosition.Top;
}
if (relationSide == Sides.Bottom)
{
return RelativeSidePosition.Bottom;
}
}
if (startSide == Sides.Right)
{
if (relationSide == Sides.Front)
{
return RelativeSidePosition.Left;
}
if (relationSide == Sides.Back)
{
return RelativeSidePosition.Right;
}
if (relationSide == Sides.Left)
{
return RelativeSidePosition.Opposite;
}
if (relationSide == Sides.Right)
{
return RelativeSidePosition.Self;
}
if (relationSide == Sides.Top)
{
return RelativeSidePosition.Top;
}
if (relationSide == Sides.Bottom)
{
return RelativeSidePosition.Bottom;
}
}
if (startSide == Sides.Back)
{
if (relationSide == Sides.Front)
{
return RelativeSidePosition.Opposite;
}
if (relationSide == Sides.Back)
{
return RelativeSidePosition.Self;
}
if (relationSide == Sides.Left)
{
return RelativeSidePosition.Right;
}
if (relationSide == Sides.Right)
{
return RelativeSidePosition.Left;
}
if (relationSide == Sides.Top)
{
return RelativeSidePosition.Top;
}
if (relationSide == Sides.Bottom)
{
return RelativeSidePosition.Bottom;
}
}
if (startSide == Sides.Top)
{
if (relationSide == Sides.Front)
{
return RelativeSidePosition.Bottom;
}
if (relationSide == Sides.Back)
{
return RelativeSidePosition.Top;
}
if (relationSide == Sides.Left)
{
return RelativeSidePosition.Left;
}
if (relationSide == Sides.Right)
{
return RelativeSidePosition.Right;
}
if (relationSide == Sides.Top)
{
return RelativeSidePosition.Self;
}
if (relationSide == Sides.Bottom)
{
return RelativeSidePosition.Opposite;
}
}
if (startSide == Sides.Bottom)
{
if (relationSide == Sides.Front)
{
return RelativeSidePosition.Top;
}
if (relationSide == Sides.Back)
{
return RelativeSidePosition.Bottom;
}
if (relationSide == Sides.Left)
{
return RelativeSidePosition.Left;
}
if (relationSide == Sides.Right)
{
return RelativeSidePosition.Right;
}
if (relationSide == Sides.Top)
{
return RelativeSidePosition.Opposite;
}
if (relationSide == Sides.Bottom)
{
return RelativeSidePosition.Self;
}
}
return RelativeSidePosition.NotExisting; //default to satisfy the compiler, should never occur
}
/// <summary>
/// gets the side relative to startSide according to relativeSide
/// </summary>
/// <param name="startSide"></param>
/// <param name="relativeSide"></param>
/// <returns></returns>
public static Sides GetRelativeSide(Sides startSide, RelativeSidePosition relativeSide)
{
Debug.Assert(relativeSide != RelativeSidePosition.NotExisting);
if (startSide == Sides.Front)
{
if (relativeSide == RelativeSidePosition.Self) return Sides.Front;
if (relativeSide == RelativeSidePosition.Opposite) return Sides.Back;
if (relativeSide == RelativeSidePosition.Left) return Sides.Left;
if (relativeSide == RelativeSidePosition.Right) return Sides.Right;
if (relativeSide == RelativeSidePosition.Top) return Sides.Top;
if (relativeSide == RelativeSidePosition.Bottom) return Sides.Bottom;
}
if (startSide == Sides.Back)
{
if (relativeSide == RelativeSidePosition.Self) return Sides.Back;
if (relativeSide == RelativeSidePosition.Opposite) return Sides.Front;
if (relativeSide == RelativeSidePosition.Left) return Sides.Right;
if (relativeSide == RelativeSidePosition.Right) return Sides.Left;
if (relativeSide == RelativeSidePosition.Top) return Sides.Top;
if (relativeSide == RelativeSidePosition.Bottom) return Sides.Bottom;
}
if (startSide == Sides.Left)
{
if (relativeSide == RelativeSidePosition.Self) return Sides.Left;
if (relativeSide == RelativeSidePosition.Opposite) return Sides.Right;
if (relativeSide == RelativeSidePosition.Left) return Sides.Back;
if (relativeSide == RelativeSidePosition.Right) return Sides.Front;
if (relativeSide == RelativeSidePosition.Top) return Sides.Top;
if (relativeSide == RelativeSidePosition.Bottom) return Sides.Bottom;
}
if (startSide == Sides.Right)
{
if (relativeSide == RelativeSidePosition.Self) return Sides.Right;
if (relativeSide == RelativeSidePosition.Opposite) return Sides.Left;
if (relativeSide == RelativeSidePosition.Left) return Sides.Front;
if (relativeSide == RelativeSidePosition.Right) return Sides.Back;
if (relativeSide == RelativeSidePosition.Top) return Sides.Top;
if (relativeSide == RelativeSidePosition.Bottom) return Sides.Bottom;
}
if (startSide == Sides.Top)
{
if (relativeSide == RelativeSidePosition.Self) return Sides.Top;
if (relativeSide == RelativeSidePosition.Opposite) return Sides.Bottom;
if (relativeSide == RelativeSidePosition.Left) return Sides.Left;
if (relativeSide == RelativeSidePosition.Right) return Sides.Right;
if (relativeSide == RelativeSidePosition.Top) return Sides.Back;
if (relativeSide == RelativeSidePosition.Bottom) return Sides.Front;
}
if (startSide == Sides.Bottom)
{
if (relativeSide == RelativeSidePosition.Self) return Sides.Bottom;
if (relativeSide == RelativeSidePosition.Opposite) return Sides.Top;
if (relativeSide == RelativeSidePosition.Left) return Sides.Left;
if (relativeSide == RelativeSidePosition.Right) return Sides.Right;
if (relativeSide == RelativeSidePosition.Top) return Sides.Front;
if (relativeSide == RelativeSidePosition.Bottom) return Sides.Back;
}
return startSide; //default value to satisfy the compiler, should never be used
}
/// <summary>
/// gets the edge relative to startEdge according to relativeEdge
/// e.g. startEdge = Left and relativeEdge = Top, result = Right
/// </summary>
/// <param name="startEdge"></param>
/// <param name="relativeEdge"></param>
/// <returns></returns>
public static RelativeEdgePosition GetRelativeEdge(RelativeEdgePosition startEdge, RelativeEdgePosition relativeEdge)
{
if (relativeEdge == RelativeEdgePosition.Bottom) return startEdge;
if (relativeEdge == RelativeEdgePosition.Left)
{
if (startEdge == RelativeEdgePosition.Bottom) return RelativeEdgePosition.Left;
if (startEdge == RelativeEdgePosition.Left) return RelativeEdgePosition.Top;
if (startEdge == RelativeEdgePosition.Top) return RelativeEdgePosition.Right;
if (startEdge == RelativeEdgePosition.Right) return RelativeEdgePosition.Bottom;
}
if (relativeEdge == RelativeEdgePosition.Top)
{
if (startEdge == RelativeEdgePosition.Bottom) return RelativeEdgePosition.Top;
if (startEdge == RelativeEdgePosition.Left) return RelativeEdgePosition.Right;
if (startEdge == RelativeEdgePosition.Top) return RelativeEdgePosition.Bottom;
if (startEdge == RelativeEdgePosition.Right) return RelativeEdgePosition.Left;
}
if (relativeEdge == RelativeEdgePosition.Right)
{
if (startEdge == RelativeEdgePosition.Bottom) return RelativeEdgePosition.Right;
if (startEdge == RelativeEdgePosition.Left) return RelativeEdgePosition.Bottom;
if (startEdge == RelativeEdgePosition.Top) return RelativeEdgePosition.Left;
if (startEdge == RelativeEdgePosition.Right) return RelativeEdgePosition.Top;
}
return RelativeEdgePosition.NotExisting;
}
/// <summary>
/// swaps top and bottom, leaves the other options as they are
/// </summary>
/// <param name="?"></param>
/// <returns></returns>
public static RelativeEdgePosition SwapTopBottom(RelativeEdgePosition startPosition)
{
if (startPosition == RelativeEdgePosition.Top) return RelativeEdgePosition.Bottom;
if (startPosition == RelativeEdgePosition.Bottom) return RelativeEdgePosition.Top;
return startPosition;
}
/// <summary>
/// swaps top and bottom, leaves the other options as they are
/// </summary>
/// <param name="?"></param>
/// <returns></returns>
public static RelativeCornerPosition SwapTopBottom(RelativeCornerPosition startPosition)
{
if (startPosition == RelativeCornerPosition.TopLeft) return RelativeCornerPosition.BottomLeft;
if (startPosition == RelativeCornerPosition.TopRight) return RelativeCornerPosition.BottomRight;
if (startPosition == RelativeCornerPosition.BottomLeft) return RelativeCornerPosition.TopLeft;
if (startPosition == RelativeCornerPosition.BottomRight) return RelativeCornerPosition.TopRight;
return startPosition;
}
/// <summary>
/// swaps left and right, leaves the other options as they are
/// </summary>
/// <param name="?"></param>
/// <returns></returns>
public static RelativeEdgePosition SwapLeftRight(RelativeEdgePosition startPosition)
{
if (startPosition == RelativeEdgePosition.Left) return RelativeEdgePosition.Right;
if (startPosition == RelativeEdgePosition.Right) return RelativeEdgePosition.Left;
return startPosition;
}
/// <summary>
/// returns the sides that would be front and left
/// if the cube was rotated so that the corner is the left bottom corner
/// </summary>
/// <param name="corner"></param>
/// <param name="front"></param>
/// <param name="left"></param>
public static void GetFrontLeftFromCorner(RelativeCornerPosition corner, out Sides front, out Sides left)
{
//default
front = Sides.Front;
left = Sides.Left;
if (corner == RelativeCornerPosition.BottomLeft)
{
front = Sides.Front;
left = Sides.Left;
}
if (corner == RelativeCornerPosition.BottomRight)
{
front = Sides.Right;
left = Sides.Front;
}
if (corner == RelativeCornerPosition.TopRight)
{
front = Sides.Back;
left = Sides.Right;
}
if (corner == RelativeCornerPosition.TopLeft)
{
front = Sides.Left;
left = Sides.Back;
}
}
public static bool IsOfColor(Brush testcolor, params Brush[] colors)
{
return colors.Contains(testcolor);
}
}
}