public void TestBreakAndCreateNew() { SLAV slav = new SLAV(); //NEED TO MAINTAIN THIS LIST FOR TESTING PURPOSES LAV localLav = new LAV(); Vertex v1 = new Vertex(0, 3); Vertex v2 = new Vertex(2, 0); Vertex v3 = new Vertex(4, 2); Vertex v4 = new Vertex(6, 0); Vertex v5 = new Vertex(8, 3); localLav.Add(v1); localLav.Add(v2); localLav.Add(v3); localLav.Add(v4); localLav.Add(v5); SSLOperations.SetVertexType(localLav); SSLOperations.ComputeAngleBisectors(localLav); slav.Insert(v1, 0); slav.Insert(v2, 0); slav.Insert(v3, 0); slav.Insert(v4, 0); slav.Insert(v5, 0); SSLOperations.SetVertexType(slav.Get(0)); SSLOperations.ComputeAngleBisectors(slav.Get(0)); LAV lav = slav.Get(0); Assert.AreEqual(v1, lav.Get(1)); Assert.AreEqual(v2, lav.Get(2)); Assert.AreEqual(v3, lav.Get(3)); Assert.AreEqual(Vertex.VertexType.Split, lav.Get(3).Type); Assert.AreEqual(v4, lav.Get(4)); Assert.AreEqual(v5, lav.Get(5)); slav.BreakAndCreateNew(v3, 0); lav = slav.Get(0); Assert.AreEqual(v1, lav.Get(1)); Assert.AreEqual(v2, lav.Get(2)); Assert.AreEqual(new Vertex(4, 3), lav.Get(3)); Assert.AreEqual(v1, lav.Get(3).GetNextVertex()); lav = slav.Get(1); Assert.AreEqual(new Vertex(4, 3), lav.Get(1)); Assert.AreEqual(v4, lav.Get(2)); Assert.AreEqual(v5, lav.Get(3)); Assert.AreEqual(new Vertex(4, 3), lav.Get(3).GetNextVertex()); }
static void Main(string[] args) { string input = string.Empty; string output = string.Empty; for (int i = 0; i < args.Length; i++) { if (args[i].ToUpper() == "-INPUT") { input = args[i + 1]; i++; } else if (args[i].ToUpper() == "-OUTPUT") { output = args[i + 1]; i++; } } IInputReader reader = null; if (input.EndsWith(".xml")) reader = new XMLReader(input); SLAV slav = new SLAV(); //LAV listOfActiveVertices = new LAV(); while (reader.IsNotEmpty()) slav.Insert(reader.GetCurrentVertex(), 0); SSLOperations.SetVertexType(slav.Get(0)); SSLOperations.ComputeAngleBisectors(slav.Get(0)); List<LineSegment> result = SSLOperations.GenerateSkeleton(slav); using (StreamWriter sw = new StreamWriter(output)) { sw.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>"); sw.WriteLine("<linesegments>"); foreach (LineSegment ls in result) { sw.WriteLine("\t<linesegment>"); sw.WriteLine("\t\t<x>" + ls.Start.GetX() + "</x><y>" + ls.Start.GetY() + "</y>"); sw.WriteLine("\t\t<x>" + ls.End.GetX() + "</x><y>" + ls.End.GetY() + "</y>"); sw.WriteLine("\t</linesegment>"); } sw.WriteLine("</linesegments>"); } }
public static List<LineSegment> GenerateSkeleton(SLAV setListOfActiveVertices) { List<LineSegment> result = new List<LineSegment>(); int lavIndex = 0; if (queue.IsEmpty()) SSLOperations.GeneratePriorityQueue(setListOfActiveVertices.Get(lavIndex)); while (!queue.IsEmpty()) { while (!queue.IsEmpty()) { Intersection intersection = GetMinIntersection(); if (intersection.Type == Vertex.VertexType.Undefined) { throw new Exception("Undefined vertex type."); } if (!intersection.GetVA().Processed && !intersection.GetVB().Processed) { double intersectionX = Math.Round(intersection.GetX(), 2); double intersectionY = Math.Round(intersection.GetY(), 2); Vertex intersectionVertex = new Vertex(intersectionX, intersectionY); if (intersection.Type == Vertex.VertexType.Edge || intersection.Type == Vertex.VertexType.Split) { result.Add(new LineSegment(intersection.GetVB(), intersectionVertex)); result.Add(new LineSegment(intersection.GetVA(), intersectionVertex)); setListOfActiveVertices.Get(lavIndex).Insert(intersectionVertex, intersection.GetVB(), intersection.GetVA()); intersectionVertex.NextLineSegment = intersection.GetLSVA(); intersectionVertex.PrevLineSegment = intersection.GetLSVB(); SetVertexType(intersectionVertex); intersectionVertex.AngleBisector = MathLibrary.GetAngleBisectorVertex(intersectionVertex.PrevLineSegment, intersectionVertex.NextLineSegment); if (intersectionVertex.AngleBisector == null) //THE LINES ARE PARALLEL { intersectionVertex.AngleBisector = MathLibrary.Rotate(intersectionVertex, MathLibrary.GetAngleBisectorVertex(new LineSegment(intersectionVertex, intersection.GetVB()), new LineSegment(intersectionVertex, intersection.GetVA())), 180); } } intersection.GetVA().SetProcessed(); intersection.GetVB().SetProcessed(); } } Vertex startVertex = setListOfActiveVertices.Get(lavIndex).GetStart(); if (startVertex.GetNextVertex().GetNextVertex().Equals(startVertex)) { result.Add(new LineSegment(startVertex, startVertex.GetNextVertex())); } else { SSLOperations.GeneratePriorityQueue(setListOfActiveVertices.Get(lavIndex)); } } return result; }
public void TestQuad() { SLAV slav = new SLAV(); //NEED TO MAINTAIN THIS LIST FOR TESTING PURPOSES LAV localLav = new LAV(); Vertex v1 = new Vertex(0, 6); Vertex v2 = new Vertex(0, 0); Vertex v3 = new Vertex(2, 0); Vertex v4 = new Vertex(4, 2); Vertex v5 = new Vertex(6, 2); Vertex v6 = new Vertex(9, 0); Vertex v7 = new Vertex(5, 6); Vertex v8 = new Vertex(3.5, 4); Vertex v9 = new Vertex(3, 6); localLav.Add(v1); localLav.Add(v2); localLav.Add(v3); localLav.Add(v4); localLav.Add(v5); localLav.Add(v6); localLav.Add(v7); localLav.Add(v8); localLav.Add(v9); slav.Insert(v1, 0); slav.Insert(v2, 0); slav.Insert(v3, 0); slav.Insert(v4, 0); slav.Insert(v5, 0); slav.Insert(v6, 0); slav.Insert(v7, 0); slav.Insert(v8, 0); slav.Insert(v9, 0); SSLOperations.SetVertexType(localLav); SSLOperations.ComputeAngleBisectors(localLav); SSLOperations.SetVertexType(slav.Get(0)); SSLOperations.ComputeAngleBisectors(slav.Get(0)); LAV lav = slav.Get(0); Assert.AreEqual(v1, lav.Get(1)); Assert.AreEqual(v2, lav.Get(2)); Assert.AreEqual(v3, lav.Get(3)); Assert.AreEqual(v4, lav.Get(4)); Assert.AreEqual(v5, lav.Get(5)); Assert.AreEqual(v6, lav.Get(6)); Assert.AreEqual(v7, lav.Get(7)); Assert.AreEqual(v8, lav.Get(8)); Assert.AreEqual(v9, lav.Get(9)); slav.BreakAndCreateNew(v8, 0); lav = slav.Get(0); Assert.AreEqual(v1, lav.Get(1)); Assert.AreEqual(v2, lav.Get(2)); Assert.AreEqual(v3, lav.Get(3)); Assert.AreEqual(v4, lav.Get(4)); Assert.AreEqual(3.30, Math.Round(lav.Get(5).GetX(), 2)); Assert.AreEqual(3.02, Math.Round(lav.Get(5).GetY(), 2)); Assert.AreEqual(v9, lav.Get(6)); Assert.AreEqual(v1, lav.Get(6).GetNextVertex()); lav = slav.Get(1); Assert.AreEqual(3.30, Math.Round(lav.Get(1).GetX(), 2)); Assert.AreEqual(3.02, Math.Round(lav.Get(1).GetY(), 2)); Assert.AreEqual(v5, lav.Get(2)); Assert.AreEqual(v6, lav.Get(3)); Assert.AreEqual(v7, lav.Get(4)); Assert.AreEqual(3.30, Math.Round(lav.Get(4).GetNextVertex().GetX(), 2)); }
public void TestSLAVInsertSingleList() { SLAV slav = new SLAV(); Vertex v1 = new Vertex(0, 3); slav.Insert(v1, 0); LAV lav = slav.Get(0); Assert.AreEqual(v1, lav.GetStart()); }
protected void SetUp() { setListOfActiveVertices = new SLAV(); setListOfActiveVertices.Insert(new Vertex(2, 6), 0); setListOfActiveVertices.Insert(new Vertex(2, 2), 0); setListOfActiveVertices.Insert(new Vertex(15, 2), 0); setListOfActiveVertices.Insert(new Vertex(15, 6), 0); listOfActiveVertices = new LAV(); listOfActiveVertices.Add(new Vertex(2, 6)); listOfActiveVertices.Add(new Vertex(2, 2)); listOfActiveVertices.Add(new Vertex(15, 2)); listOfActiveVertices.Add(new Vertex(15, 6)); SSLOperations.SetVertexType(setListOfActiveVertices.Get(0)); SSLOperations.ComputeAngleBisectors(setListOfActiveVertices.Get(0)); SSLOperations.SetVertexType(listOfActiveVertices); SSLOperations.ComputeAngleBisectors(listOfActiveVertices); }
public void TestGetResult4() { SLAV slav4 = new SLAV(); slav4.Insert(new Vertex(0, 3), 0); slav4.Insert(new Vertex(2, 0), 0); slav4.Insert(new Vertex(4, 1), 0); slav4.Insert(new Vertex(6, 0), 0); slav4.Insert(new Vertex(8, 3), 0); SSLOperations.ComputeAngleBisectors(slav4.Get(0)); List<LineSegment> result = SSLOperations.GenerateSkeleton(slav4); Assert.AreEqual(new LineSegment(new Vertex(6, 0), new Vertex(5.55, 1.69)), result[0]); Assert.AreEqual(new LineSegment(new Vertex(8, 3), new Vertex(5.55, 1.69)), result[1]); Assert.AreEqual(new LineSegment(new Vertex(0, 3), new Vertex(2.45, 1.69)), result[2]); Assert.AreEqual(new LineSegment(new Vertex(2, 0), new Vertex(2.45, 1.69)), result[3]); Assert.AreEqual(new LineSegment(new Vertex(5.55, 1.69), new Vertex(4, 2.06)), result[4]); Assert.AreEqual(new LineSegment(new Vertex(2.45, 1.69), new Vertex(4, 2.06)), result[5]); Assert.AreEqual(new LineSegment(new Vertex(4, 1), new Vertex(4, 2.06)), result[6]); }
public void TestGetResult3() { SLAV slav3 = new SLAV(); slav3.Insert(new Vertex(0, 6), 0); slav3.Insert(new Vertex(0, 0), 0); slav3.Insert(new Vertex(4, 0), 0); slav3.Insert(new Vertex(4, 3), 0); slav3.Insert(new Vertex(8, 3), 0); slav3.Insert(new Vertex(8, 6), 0); SSLOperations.ComputeAngleBisectors(slav3.Get(0)); List<LineSegment> result = SSLOperations.GenerateSkeleton(slav3); Assert.AreEqual(new LineSegment(new Vertex(8, 3), new Vertex(6.5, 4.5)), result[0]); Assert.AreEqual(new LineSegment(new Vertex(8, 6), new Vertex(6.5, 4.5)), result[1]); Assert.AreEqual(new LineSegment(new Vertex(0, 0), new Vertex(2, 2)), result[2]); Assert.AreEqual(new LineSegment(new Vertex(4, 0), new Vertex(2, 2)), result[3]); Assert.AreEqual(new LineSegment(new Vertex(0, 6), new Vertex(2, 4)), result[4]); Assert.AreEqual(new LineSegment(new Vertex(2, 2), new Vertex(2, 4)), result[5]); Assert.AreEqual(new LineSegment(new Vertex(4, 3), new Vertex(2.5, 4.5)), result[6]); Assert.AreEqual(new LineSegment(new Vertex(6.5, 4.5), new Vertex(2.5, 4.5)), result[7]); Assert.AreEqual(new LineSegment(new Vertex(2, 4), new Vertex(2.5, 4.5)), result[8]); }
public void TestGetResult2() { SLAV slav2 = new SLAV(); slav2.Insert(new Vertex(3, 10), 0); slav2.Insert(new Vertex(0, 7), 0); slav2.Insert(new Vertex(0, 3), 0); slav2.Insert(new Vertex(3, 0), 0); slav2.Insert(new Vertex(7, 0), 0); slav2.Insert(new Vertex(10, 3), 0); slav2.Insert(new Vertex(10, 7), 0); slav2.Insert(new Vertex(7, 10), 0); SSLOperations.ComputeAngleBisectors(slav2.Get(0)); List<LineSegment> result = SSLOperations.GenerateSkeleton(slav2); foreach (LineSegment ls in result) Console.WriteLine(ls.ToString()); }