public void Add(UIObject newObj, UIDir dir) { Vector2 rel = Vector2.zero; if (list.Size() > 0) { UIObject last = list.Last(); switch (dir) { case UIDir.W: rel = last.GetRelative() + new Vector2(last.GetWidth(), 0); break; case UIDir.S: rel = new Vector2(origin.x, last.GetRelative().y - last.GetHeight()); break; default: UT.assert(false, "button: invalid direction"); break; } } UT.print("REL: " + rel); newObj.SetRelative(rel); list.AddLast(newObj); UpdateBounds(); UT.print("New bounds: " + bounds); }
private static void UtilTest() { Rect r1 = Rect.MinMaxRect(0, 0, 3, 5); Rect r2 = Rect.MinMaxRect(1, 1, 6, 2); Rect u = AMenu.Union(r1, r2); UT.assert(u.x == 0 && u.y == 0 && u.width == 6f && u.height == 5f); UT.print("Union: " + u); }
public T GetAt(int index) { UT.assert(index >= 0 && index < size); var it = Iterator(); while (index-- >= 0) { it.Next(); } return(it.Value()); }
public MListNode <T> InsertAfter(MListNode <T> position, T t) { // add a node after 'position', which can't be null // special cases: first, only one, last UT.assert(position != null); MListNode <T> node = new MListNode <T> { value = t, Next = position.Next }; position.Next = node; if (tail == position) { tail = node; } size++; return(node); }
static public float linearInterpolation(float x, float x0, float x1, float y0, float y1) { // | / (x1,y1) // | /_____________ return value y // | /| // | / | // | (x0,y0) / | // | x UT.assert(x >= x0 && x <= x1); UT.assert(x0 <= x1); if ((x1 - x0) == 0) { return((y0 + y1) / 2); } return(y0 + (x - x0) * (y1 - y0) / (x1 - x0)); }
public static MList <Int2> getNeighbors(Int2 p, int max, int min) { UT.assert(max >= 1 && min >= 1 && max >= min); // get set of neighbors in min/max range MList <Int2> l = new MList <Int2>(); for (int y = p.y - max; y <= p.y + max; y++) { for (int x = p.x - max; x <= p.x + max; x++) { if (p.chess(x, y) >= min) { l.Add(new Int2(x, y)); } } } return(l); }
public void AssertValid() { if (size == 0) { UT.assert(tail == null); UT.assert(root.Next == null); } else { int n = 0; var it = Iterator(); while (it.Next()) { it.AssertValid(); n++; } UT.assert(it.Value().Equals(tail.value)); UT.assert(n == size); UT.assert(it.Finished()); } }
public void AssertValid() { if (previous != null) { if (current == null) { UT.assert(previous.Next == next); } else { UT.assert(previous.Next == current); } } else if (current != null) { UT.assert(current.Next == next); } else { UT.assert(next == null); } }
public void InsertBefore(T t) { UT.assert(current != null); // can't be beginning or end of list, or just deleted previous = list.InsertAfter(previous, t); // add new node and update iterator's previous }
public void Remove() { UT.assert(current != null); list.Remove(this); }
private static void RunTest() { UT.print("-------- MListTest start --------"); MList <int> l = new MList <int>(); // insert first l.AddLast(1); l.AssertValid(); print(l); l.AddFirst(2); l.AssertValid(); print(l); l.AddFirst(3); print(l); // insert before var it = l.Iterator(); it.AssertValid(); it.Next(); it.InsertBefore(-1); it.AssertValid(); print(l); it.InsertBefore(0); it.AssertValid(); l.AssertValid(); print(l); // "-1 0 1 2 3" while (it.HasNext()) { it.Next(); } it.InsertBefore(2); it.AssertValid(); l.AssertValid(); print(l); // "-1 0 1 2 2 3" l = new MList <int>(); // fill list for (int i = 0; i < FILL_SIZE; i++) { l.AddLast(100 + i); } print(l); UT.assert(l.Size() == FILL_SIZE); // iterator insert and remove it = l.Iterator(); while (it.Next()) { it.InsertAfter(555555); l.AssertValid(); if (it.Next()) { it.Remove(); } l.AssertValid(); } it.InsertAfter(123456); print(l); l.AssertValid(); // remove last it = l.Iterator(); while (it.HasNext()) { it.Next(); } it.Remove(); l.AssertValid(); l.RemoveAll(); l.AssertValid(); UT.assert(l.Size() == 0); // empty by iterator l = new MList <int>(); for (int i = 0; i < 2; i++) { l.AddLast(10 + i); } it = l.Iterator(); while (it.Next()) { l.AssertValid(); it.AssertValid(); it.Remove(); l.AssertValid(); it.AssertValid(); } // test remove last iterator l = new MList <int>(); for (int i = 0; i < 2; i++) { l.AddLast(10 + i); } it = l.Iterator(); it.Next(); l.Remove(it); l.AssertValid(); UT.print("-------- MListTest end --------"); }
void OnDestroy() { UT.assert(closed == true); }