Ejemplo n.º 1
0
        private void DrawDecartPoints(IEnumerable <Point> points, Canvas workField)
        {
            var xLimit = workField.ActualWidth;
            var yLimit = workField.ActualHeight;

            var pointsToDraw = points.Select(point => new Point(point.X, fieldController.YD2YP(point.Y))).ToList();

            var pointsToDraw0 = ClearAndCutTheLines(pointsToDraw, workField).Where(point => IsPointInField(point, xLimit, yLimit)).ToList();

            var polyLines = new List <Polyline> {
                new Polyline {
                    Stroke = Brushes.LightSeaGreen, StrokeThickness = 2
                }
            };

            var lastPoint = new Point();

            if (pointsToDraw0.Count != 0)
            {
                lastPoint = pointsToDraw0.First();
            }
            foreach (var point in pointsToDraw0)
            {
                if (Math.Abs(lastPoint.X - point.X) > 2 || ((int)fieldController.XD2XP(GraphicMaster.InfinityPoint())) == (int)lastPoint.X)
                {
                    polyLines.Add(new Polyline {
                        Stroke = Brushes.LightSeaGreen, StrokeThickness = 2
                    });
                }
                polyLines.Last().Points.Add(point);
                lastPoint = point;
            }

            polyLines.ForEach(line => workField.Children.Add(line));
        }
Ejemplo n.º 2
0
        private IEnumerable <Point> ClearAndCutTheLines(List <Point> points, Canvas workField)
        {
            var InZone = new bool[points.Count()];

            var lastPoint = points[0];

            var counter = 0;

            foreach (var point in points)
            {
                if (lastPoint.X - point.X < 2 && (0 < point.Y && point.Y < workField.ActualHeight))
                {
                    InZone[counter] = true;
                }
                lastPoint = point;
                counter++;
            }

            counter = 0;
            var pointsWithoutBlindSpots = new List <Point>();

            foreach (var point in points)
            {
                pointsWithoutBlindSpots.Add(point);

                if (counter > 0)
                {
                    if (!InZone[counter] && !InZone[counter - 1])
                    {
                        if ((pointsWithoutBlindSpots[counter - 1].Y > fieldController.MaxYP
                             &&
                             pointsWithoutBlindSpots[counter].Y < 0
                             ))
                        {
                            pointsWithoutBlindSpots[counter - 1] = new Point(pointsWithoutBlindSpots[counter - 1].X, fieldController.MaxYP);
                            pointsWithoutBlindSpots[counter]     = new Point(pointsWithoutBlindSpots[counter].X, 0);
                        }
                        else if ((pointsWithoutBlindSpots[counter - 1].Y <0
                                                                          &&
                                                                          pointsWithoutBlindSpots[counter].Y> fieldController.MaxYP
                                  ))
                        {
                            pointsWithoutBlindSpots[counter - 1] = new Point(pointsWithoutBlindSpots[counter - 1].X, 0);
                            pointsWithoutBlindSpots[counter]     = new Point(pointsWithoutBlindSpots[counter].X, fieldController.MaxYP);
                        }
                    }
                }
                counter++;
            }

            counter = 0;
            var pointsWithoutInfinitySyndrom = new List <Point>();

            foreach (var point in pointsWithoutBlindSpots)
            {
                pointsWithoutInfinitySyndrom.Add(point);

                counter++;
            }

            var infPixel = (int)fieldController.XD2XP(GraphicMaster.InfinityPoint());

            if (infPixel > 0 && infPixel < counter - 1)
            {
                pointsWithoutInfinitySyndrom[infPixel] = new Point(infPixel, fieldController.MaxYP);
            }
            if (infPixel + 1 > 0 && infPixel < counter - 1)
            {
                pointsWithoutInfinitySyndrom[infPixel + 1] = new Point(infPixel + 1, 0);
            }

            counter = 0;
            var pointsWithoutCuts = new List <Point>();

            foreach (var point in pointsWithoutInfinitySyndrom)
            {
                pointsWithoutCuts.Add(point);

                if (counter > 0)
                {
                    if (InZone[counter - 1] && !InZone[counter])
                    {
                        pointsWithoutCuts[counter] = new Point(pointsWithoutCuts[counter - 1].X, pointsWithoutCuts[counter].Y > 0 ? fieldController.MaxYP : 0);
                    }
                    if (!InZone[counter - 1] && InZone[counter])
                    {
                        pointsWithoutCuts[counter - 1] = new Point(pointsWithoutCuts[counter].X, pointsWithoutCuts[counter - 1].Y > 0 ? fieldController.MaxYP : 0);
                    }
                }
                counter++;
            }

            return(pointsWithoutCuts);
        }