コード例 #1
0
 public int GetErrorDeltaWhenPolygonAdded(IList<Polygon> polygonOrder, Polygon addedPolygon, int addedIndex)
 {
     int topIndex = GetTopIndex(polygonOrder);
     int currentError = GetError(polygonOrder,topIndex);
     if (topIndex <= addedIndex)
     {
         int errorAfterAdded = GetError(addedPolygon);
         return errorAfterAdded - currentError;
     }
     return 0;
 }
コード例 #2
0
 public void AddPolygon(Polygon polygon, int index)
 {
     foreach(var x in GetPolygonPoints(polygon))
     {
         ((Action<IntVector2>)(point =>
         {
             TotalError += this[point].GetErrorDeltaWhenPolygonAdded(polygonOrder, polygon, index);
             this[point].AddPolygon(polygon);
         }))(x);
     }
     polygonOrder.Insert(index,polygon);
 }
コード例 #3
0
 public override VectorPicture GetInitialPicture(IAlgorithm algorithm)
 {
     var picture = new VectorPicture();
     var polygon = new Polygon(Color.White);
     picture.Polygons.Add(polygon);
     var x0 = (int) (algorithm.SourceData.Width*0.25);
     var x1 = (int) (algorithm.SourceData.Width*0.75);
     var y0 = (int) (algorithm.SourceData.Height*0.25);
     var y1 = (int) (algorithm.SourceData.Height*0.75);
     polygon.Points.Add(new IntVector2(x0, y0));
     polygon.Points.Add(new IntVector2(x0, y1));
     polygon.Points.Add(new IntVector2(x1, y1));
     polygon.Points.Add(new IntVector2(x1, y0));
     polygon.Color = new VColor(Color.White);
     return picture;
 }
コード例 #4
0
 public int TotalErrorWhenPolygonChanged(Polygon polygon, int index)
 {
     int totalError = TotalError;
     var newPoints = GetPolygonPoints(polygon).ToHashSet();
     var oldPoints = GetPolygonPoints(polygonOrder[index]).ToHashSet();
     var addedPoints = newPoints.Difference(oldPoints);
     var removedPoints = oldPoints.Difference(newPoints);
     foreach(var x in removedPoints)
     {
         ((Action<IntVector2>)(point => { totalError += this[point].GetErrorDeltaWhenPolygonRemoved(polygonOrder, index); }))(x);
     }
     foreach(var x in addedPoints)
     {
         ((Action<IntVector2>)(point => { totalError += this[point].GetErrorDeltaWhenPolygonAdded(polygonOrder, polygon, index); }))(x);
     }
     return totalError;
 }
コード例 #5
0
 public static Polygon GetRandomPolygon(Random random, IntVector2 max, int maxPointCount)
 {
     var result = new Polygon(Color.White);
     int pointCount = random.Next(3, maxPointCount);
     result.Points = new List<IntVector2>(maxPointCount);
     for (int pointId = 0; pointId < pointCount; pointId++)
     {
         int x = (int) random.RandomBetween(0, max.X);
         int y = (int) random.RandomBetween(0, max.Y);
         result.Points.Add(new IntVector2(x, y));
     }
     var colorComponents = new Byte[VColor.COMPONENT_COUNT];
     for (int i = 0; i < VColor.COMPONENT_COUNT; i++)
     {
         colorComponents[i] = (Byte) random.Next(0, 255);
     }
     result.Color = new VColor(colorComponents);
     return result;
 }
コード例 #6
0
 public override VectorPicture GetInitialPicture(IAlgorithm algorithm)
 {
     var source = algorithm.SourceData;
     var result = new VectorPicture();
     int x0 = (int) (source.Width*0.25);
     int x1 = (int) (source.Width*0.75);
     int y0 = (int) (source.Height*0.25);
     int y1 = (int) (source.Height*0.75);
     var points = new List<IntVector2>
         {
             new IntVector2(x0, y0),
             new IntVector2(x0, y1),
             new IntVector2(x1, y1),
             new IntVector2(x1 + 2, y1),
             new IntVector2(x1, y0),
             new IntVector2(x1 + 2, y0)
         };
     var polygon = new Polygon(points, new VColor(Color.White));
     result.Polygons.Add(polygon);
     return result;
 }
コード例 #7
0
 public void FindIntersection2()
 {
     var polygon = new Polygon(Color.White);
     polygon.AddPoint(23, 4);
     polygon.AddPoint(12, 36);
     polygon.AddPoint(36, 34); //edge1
     polygon.AddPoint(23, 13); //edge1
     polygon.AddPoint(28,24); //edge2
     polygon.AddPoint(28,18); //edge2
     Assert.IsTrue(polygon.IsSelfIntersecting());
 }
コード例 #8
0
 private Polygon RightPolygon()
 {
     var result = new Polygon(Color.White);
     result.Points.Add(new IntVector2(5, 0));
     result.Points.Add(new IntVector2(10, 0));
     result.Points.Add(new IntVector2(10, 10));
     result.Points.Add(new IntVector2(5, 10));
     return result;
 }
コード例 #9
0
 private Polygon MidPolygon()
 {
     var result = new Polygon(Color.White);
     result.Points.Add(new IntVector2(3, 0));
     result.Points.Add(new IntVector2(8, 0));
     result.Points.Add(new IntVector2(8, 10));
     result.Points.Add(new IntVector2(3, 10));
     return result;
 }
コード例 #10
0
 private static Polygon LeftPolygon()
 {
     var result = new Polygon(Color.White);
     result.Points.Add(new IntVector2(0, 0));
     result.Points.Add(new IntVector2(5, 0));
     result.Points.Add(new IntVector2(5, 10));
     result.Points.Add(new IntVector2(0, 10));
     return result;
 }
コード例 #11
0
 public void ScoreMethodsAreEquivalentCase2()
 {
     var polygon = new Polygon(Color.White);
     polygon.AddPoint(5, 7);
     polygon.AddPoint(10, 5);
     polygon.AddPoint(7, 15);
     var picture = new VectorPicture();
     picture.Polygons.Add(polygon);
     var mutationPolygon = new Polygon(Color.White);
     mutationPolygon.AddPoint(6, 0);
     mutationPolygon.AddPoint(5, 0);
     mutationPolygon.AddPoint(19, 18);
     mutationPolygon.AddPoint(18, 1);
     var mutation = new PolygonChanged(mutationPolygon, 0);
     CompareScoreMethods(picture, mutation, Resources.Polygon);
 }
コード例 #12
0
 public void ScoreMethodsAreEquivalentCase1()
 {
     var polygon = new Polygon(Color.White);
     polygon.AddPoint(8,13);
     polygon.AddPoint(7,1);
     polygon.AddPoint(11,14);
     var picture = new VectorPicture();
     picture.Polygons.Add(polygon);
     var mutationPolygon = new Polygon(Color.White);
     mutationPolygon.AddPoint(1, 4);
     mutationPolygon.AddPoint(13, 0);
     mutationPolygon.AddPoint(17, 15);
     mutationPolygon.AddPoint(2, 10);
     var mutation = new PolygonChanged(mutationPolygon, 0);
     CompareScoreMethods(picture,mutation,Resources.Polygon);
 }
コード例 #13
0
 public void FindIntersection1()
 {
     var polygon = new Polygon(Color.White);
     polygon.AddPoint(33,18);
     polygon.AddPoint(25, 1);
     polygon.AddPoint(8, 13);
     polygon.AddPoint(13, 26);
     polygon.AddPoint(34, 36);
     polygon.AddPoint(28, 14);
     polygon.AddPoint(30, 19);
     polygon.AddPoint(30, 9);
     Assert.IsTrue(polygon.IsSelfIntersecting());
 }
コード例 #14
0
 private int GetError(Polygon polygon)
 {
     return targetColor.GetAbsColorError(polygon.Color);
 }
コード例 #15
0
 public void RemovePolygon(Polygon polygon)
 {
     polygons.Remove(polygon);
 }
コード例 #16
0
 private static IEnumerable<IntVector2> GetPolygonPoints(Polygon polygon)
 {
     //return PerYPolygonDrawer.GetPoints(polygon);
     return new BoxPolygonDrawer(polygon).GetPoints();
 }
コード例 #17
0
 public void AddPolygon(Polygon polygon)
 {
     polygons.Add(polygon);
 }