mirror of
https://github.com/neogeek23/Life.git
synced 2026-02-04 02:58:17 +00:00
Update Dimension.cs
This commit is contained in:
parent
6206eb24fe
commit
23ba664e9d
@ -1,7 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace N_Space {
|
||||
class Dimension {
|
||||
public class Dimension {
|
||||
private readonly int _index;
|
||||
private Dimension _parent; //These are the dimensional parents so in (1,2) the dimension that has the index=1 would be the parent of the dimention that has the index=2
|
||||
private List<Dimension> _child;
|
||||
@ -39,8 +40,43 @@ namespace N_Space {
|
||||
return _child;
|
||||
}
|
||||
|
||||
public Dimension GetChild(int? n) {
|
||||
if (n == null) {
|
||||
return null;
|
||||
}
|
||||
return _child[System.Convert.ToInt32(n)];
|
||||
}
|
||||
|
||||
public Location GetLocation() {
|
||||
return _location;
|
||||
}
|
||||
|
||||
public int? GetChildIndexOf(int n) {
|
||||
if (_child.Count > 0) {
|
||||
return FindChildIndexOf(n, _child, 0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private int? FindChildIndexOf(int n, List<Dimension> list, int indexHoldOver) {
|
||||
int breakpoint = list.Count / 2;
|
||||
List<Dimension> part = new List<Dimension>();
|
||||
if (n > list[breakpoint].GetIndex() && list.Count > 1) {
|
||||
for (int i = breakpoint; i < list.Count; i++) {
|
||||
part.Add(list[i]);
|
||||
}
|
||||
return FindChildIndexOf(n, part, breakpoint + indexHoldOver);
|
||||
} else if (n < list[breakpoint].GetIndex() && list.Count > 1) {
|
||||
for (int i = 0; i < breakpoint; i++) {
|
||||
part.Add(list[i]);
|
||||
}
|
||||
return FindChildIndexOf(n, part, indexHoldOver);
|
||||
} else if (n == list[breakpoint].GetIndex()) {
|
||||
return breakpoint + indexHoldOver;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user