Exemplo n.º 1
0
        private void GenerateGrid(Canvas canvas)
        {
            PointsArray   = new SimplePoint[GridRows + 1, GridColumns + 1];
            EdgesList     = new List <Edge>();
            TrianglesList = new List <Triangle>();
            double widthStep  = canvas.ActualWidth / (double)GridColumns;
            double heightStep = canvas.ActualHeight / (double)GridRows;
            double pointX     = widthStep;
            double pointY     = 0d;

            //frame
            for (int i = 0; i < PointsArray.GetLength(0); i++)
            {
                PointsArray[i, 0] = new SimplePoint(0d, pointY, canvas, false);
                PointsArray[i, PointsArray.GetLength(1) - 1] = new SimplePoint(canvas.ActualWidth, pointY, canvas, false);
                pointY += heightStep;
            }
            for (int j = 1; j < PointsArray.GetLength(1) - 1; j++)
            {
                PointsArray[0, j] = new SimplePoint(pointX, 0d, canvas, false);
                PointsArray[PointsArray.GetLength(0) - 1, j] = new SimplePoint(pointX, canvas.ActualHeight, canvas, false);
                pointX += widthStep;
            }
            //middle
            pointX = widthStep;
            pointY = heightStep;
            for (int i = 1; i < PointsArray.GetLength(0) - 1; i++)
            {
                for (int j = 1; j < PointsArray.GetLength(1) - 1; j++)
                {
                    PointsArray[i, j] = new SimplePoint(pointX, pointY, canvas);
                    pointX           += widthStep;
                }
                pointX  = widthStep;
                pointY += heightStep;
            }
            //edges and triangles
            for (int i = 0; i < PointsArray.GetLength(0) - 1; i++)
            {
                for (int j = 0; j < PointsArray.GetLength(1) - 1; j++)
                {
                    TrianglesList.Add(new Triangle(PointsArray[i, j], PointsArray[i + 1, j], PointsArray[i, j + 1], canvas, triangleFillingMode));
                    TrianglesList.Add(new Triangle(PointsArray[i + 1, j + 1], PointsArray[i, j + 1], PointsArray[i + 1, j], canvas, triangleFillingMode));
                    EdgesList.Add(new Edge(PointsArray[i, j], PointsArray[i, j + 1], canvas));
                    EdgesList.Add(new Edge(PointsArray[i, j], PointsArray[i + 1, j], canvas));
                    EdgesList.Add(new Edge(PointsArray[i + 1, j], PointsArray[i, j + 1], canvas));
                }
            }
            //right and down of frame
            for (int i = 0; i < PointsArray.GetLength(0) - 1; i++)
            {
                EdgesList.Add(new Edge(PointsArray[i, PointsArray.GetLength(1) - 1], PointsArray[i + 1, PointsArray.GetLength(1) - 1], canvas));
            }
            for (int j = 0; j < PointsArray.GetLength(1) - 1; j++)
            {
                EdgesList.Add(new Edge(PointsArray[PointsArray.GetLength(0) - 1, j], PointsArray[PointsArray.GetLength(0) - 1, j + 1], canvas));
            }
        }
Exemplo n.º 2
0
 public Edge(SimplePoint first, SimplePoint second, Canvas canvas)
 {
     First       = first;
     Second      = second;
     this.canvas = canvas;
     Draw();
     First.PropertyChanged  += MoveWithPoints;
     Second.PropertyChanged += MoveWithPoints;
 }
Exemplo n.º 3
0
 public Triangle(SimplePoint p1, SimplePoint p2, SimplePoint p3, Canvas canvas, TriangleFillingMode fillingMode)
 {
     this.p1             = p1;
     this.p2             = p2;
     this.p3             = p3;
     p1.PropertyChanged += RedrawTriangleEventResponder;
     p2.PropertyChanged += RedrawTriangleEventResponder;
     p3.PropertyChanged += RedrawTriangleEventResponder;
     this.canvas         = canvas;
     this.fillingMode    = fillingMode;
     RenewRand();
 }
Exemplo n.º 4
0
 public IntPoint(SimplePoint p)
 {
     X = (int)Math.Round(p.X);
     Y = (int)Math.Round(p.Y);
 }