public static Knot <TItem> GetUnique <TItem>(this Knot <TItem> source) { var result = new Knot <TItem>(); var current = source.Start; var history = new List <TItem>(); while (current != null) { if (!history.Contains(current.Data)) { result.Add(current.Data); history.Add(current.Data); } current = current.Next; } return(result.Count() > 0 ? result : null); }
private Vector3 KnotCenter(Knot knot) { Grid nodeMap = new Grid (screen: this); nodeMap.Knot = knot; nodeMap.Update (); Vector3 center = Vector3.Zero; foreach (Edge edge in knot) { center += nodeMap.NodeBeforeEdge (edge); } center /= knot.Count (); return center; }
public void Knot_Construct_Test() { Edge[] edges = new Edge[] { Edge.Up, Edge.Left, Edge.Down, Edge.Right }; string name = "test"; KnotMetaData metaData = new KnotMetaData (name: name, countEdges: () => edges.Length); Knot knot = new Knot (metaData, edges); Assert.AreEqual (knot.Count (), edges.Length, "Knotenlänge #1"); Assert.AreEqual (knot.MetaData.CountEdges, edges.Length, "Knotenlänge #2"); Assert.AreEqual (knot.Name, name, "Knotenname #1"); Assert.AreEqual (knot.MetaData.Name, name, "Knotenname #2"); Assert.Catch (() => { KnotGenerator.generateInvalidKnot (); }, "invalid Knot construction"); }
public void Knot_Move_Test() { Edge[] edges = new Edge[] { Edge.Up, Edge.Left, Edge.Down, Edge.Right }; string name = "test"; KnotMetaData metaData = new KnotMetaData (name: name, countEdges: () => edges.Length); Knot knot = new Knot (metaData, edges); knot.AddToSelection (edges [1]); // Edge.Left Log.Debug ("Selected: ", knot.SelectedEdges); bool success; success = knot.IsValidDirection (direction: Direction.Left); Assert.IsFalse (success); success = knot.IsValidDirection (direction: Direction.Right); Assert.IsFalse (success); success = knot.IsValidDirection (direction: Direction.Up); Assert.IsTrue (success); success = knot.IsValidDirection (direction: Direction.Down); Assert.IsTrue (success); success = knot.IsValidDirection (direction: Direction.Forward); Assert.IsTrue (success); success = knot.IsValidDirection (direction: Direction.Backward); Assert.IsTrue (success); success = knot.Move (direction: Direction.Down, distance: 1); Assert.IsFalse (success, "Nicht möglich! Knoten würde zu zwei Kanten zusammenfallen!"); success = knot.Move (direction: Direction.Left, distance: 1); Assert.IsFalse (success, "Ungültige Richtung!"); success = knot.Move (direction: Direction.Right, distance: 1); Assert.IsFalse (success, "Ungültige Richtung!"); // nach oben schieben (1x) success = knot.Move (direction: Direction.Up, distance: 1); Assert.IsTrue (success, "Gültige Richtung!"); Assert.AreEqual (knot.Count (), edges.Length + 2, "Knotenlänge nach Verschiebung #1"); // noch mal nach oben schieben (2x) success = knot.Move (direction: Direction.Up, distance: 2); Assert.AreEqual (knot.Count (), edges.Length + 2 * 3, "Knotenlänge nach Verschiebung #2"); // wieder nach unten schieben (3x) success = knot.Move (direction: Direction.Down, distance: 3); Assert.IsTrue (success, "Gültige Richtung!"); Assert.AreEqual (knot.Count (), edges.Length, "Knotenlänge nach Verschiebung #3"); success = knot.Move (direction: Direction.Zero, distance: 3); Assert.AreEqual (knot.Count (), edges.Length, "Null-Move"); success = knot.Move (direction: Direction.Left, distance: 0); Assert.AreEqual (knot.Count (), edges.Length, "Null-Move"); success = knot.Move (direction: Direction.Zero, distance: 0); Assert.AreEqual (knot.Count (), edges.Length, "Null-Move"); }
/* public void Dispose () { // Undo, Redo, knot ... } */ private void OnKnotMoved(Knot newKnot) { if (!knot.Equals (newKnot)) { knot = newKnot; OnEdgesChanged (); Log.Debug ("=> set Knot #", knot.Count (), " = ", string.Join (", ", from c in knot select c.Direction)); } registerCurrentKnot (); }