private object RemoveOverlaps1() { OneWayFSAParameters params1 = new OneWayFSAParameters(); params1.HorizontalGap = 40; params1.VerticalGap = 40; var vertexRectangles = new Dictionary <string, Rectangle>(); for (int i = 0; i < vertexLabels.Length; ++i) { var vertex = vertexPositions[vertexLabels[i]]; var border = vertexBorders[vertexLabels[i]]; var rect = new Rectangle(); rect.Width = border.Right - border.Left; rect.Height = border.Bottom - border.Top; vertexRectangles.Add(vertexLabels[i], rect); } OneWayFSAAlgorithm <string> algo1; algo1 = new OneWayFSAAlgorithm <string>(null, params1); algo1.Compute(); return(null); }
public void Compute([NotNull] OneWayFSAParameters parameters) { Dictionary <int, Rect> rectangles = GetRectangles(); Dictionary <int, Rect> initialRectangles = rectangles.ToDictionary( pair => pair.Key, pair => new Rect(pair.Value.Location, pair.Value.Size)); var algorithm = new OneWayFSAAlgorithm <int>(rectangles, parameters); algorithm.Compute(); // Fulfill minimum spacing AssertNoOverlap(Distinct(algorithm.Rectangles.Values)); foreach (KeyValuePair <int, Rect> pair in algorithm.Rectangles) { Rect initialRectangle = initialRectangles[pair.Key]; // Size must not change Assert.AreEqual(initialRectangle.Size, pair.Value.Size); // X or Y must not change depending on the used Way if (parameters.Way == OneWayFSAWay.Horizontal) { Assert.AreEqual(initialRectangle.Y, pair.Value.Y); } else { Assert.AreEqual(initialRectangle.X, pair.Value.X); } } }
public void StandardFactory() { var rectangles = new Dictionary <int, Rect>(); var context = new TestOverlapRemovalContext(rectangles); var factory = new StandardOverlapRemovalAlgorithmFactory <int>(); CollectionAssert.AreEqual(new[] { "FSA", "OneWayFSA" }, factory.AlgorithmTypes); Assert.IsNull( factory.CreateAlgorithm( string.Empty, context, new OverlapRemovalParameters())); Assert.IsInstanceOf <FSAAlgorithm <int> >( factory.CreateAlgorithm( "FSA", context, new OverlapRemovalParameters())); Assert.IsInstanceOf <OneWayFSAAlgorithm <int> >( factory.CreateAlgorithm( "OneWayFSA", context, new OneWayFSAParameters())); var fsaParameters = new OverlapRemovalParameters(); IOverlapRemovalParameters createdParameters = factory.CreateParameters(string.Empty, fsaParameters); Assert.IsNull(createdParameters); createdParameters = factory.CreateParameters("fsa", fsaParameters); Assert.IsNull(createdParameters); createdParameters = factory.CreateParameters("FSA", fsaParameters); Assert.IsInstanceOf <OverlapRemovalParameters>(createdParameters); Assert.AreNotSame(fsaParameters, createdParameters); createdParameters = factory.CreateParameters("FSA", null); Assert.IsInstanceOf <OverlapRemovalParameters>(createdParameters); Assert.AreNotSame(fsaParameters, createdParameters); var oneWayFSAParameters = new OneWayFSAParameters(); createdParameters = factory.CreateParameters("OneWayFSA", oneWayFSAParameters); Assert.IsInstanceOf <OneWayFSAParameters>(createdParameters); Assert.AreNotSame(oneWayFSAParameters, createdParameters); createdParameters = factory.CreateParameters("OneWayFSA", null); Assert.IsInstanceOf <OneWayFSAParameters>(createdParameters); Assert.AreNotSame(oneWayFSAParameters, createdParameters); createdParameters = factory.CreateParameters("OneWayFSA", fsaParameters); Assert.IsInstanceOf <OneWayFSAParameters>(createdParameters); Assert.AreNotSame(fsaParameters, createdParameters); Assert.AreNotSame(oneWayFSAParameters, createdParameters); Assert.IsFalse(factory.IsValidAlgorithm(null)); Assert.IsFalse(factory.IsValidAlgorithm(string.Empty)); Assert.IsTrue(factory.IsValidAlgorithm("FSA")); Assert.IsTrue(factory.IsValidAlgorithm("OneWayFSA")); Assert.IsFalse(factory.IsValidAlgorithm("fsa")); var algorithm1 = new FSAAlgorithm <int, OverlapRemovalParameters>(rectangles, new OverlapRemovalParameters()); Assert.IsEmpty(factory.GetAlgorithmType(algorithm1)); var algorithm2 = new FSAAlgorithm <int>(rectangles, new OverlapRemovalParameters()); Assert.AreEqual("FSA", factory.GetAlgorithmType(algorithm2)); var algorithm3 = new OneWayFSAAlgorithm <int>(rectangles, new OneWayFSAParameters()); Assert.AreEqual("OneWayFSA", factory.GetAlgorithmType(algorithm3)); }