Пример #1
0
 public Graph AddEdge(int vInIndex, int vOutIndex, double weight, PointF[] points)
 {
     AddEdge(
         new Edge(this[vInIndex], this[vOutIndex], weight) { Points = points.ToList() }
         );
     return this;
 }
Пример #2
0
 public Graph AddEdge(Vertex vIn, Vertex vOut, double weight, PointF[] points)
 {
     AddEdge(
         new Edge(vIn, vOut, weight) { Points = points.ToList() }
         );
     return this;
 }
Пример #3
0
        private static float CalcCircumference(PointF[] points)
        {
            List<PointF> pointsList = new List<PointF>();
            pointsList = points.ToList();

            pointsList.Add(pointsList[0]);
            double result = 0;
            for (int i = 0; i < pointsList.Count - 1; i++)
            {
                result += Distance(pointsList[i + 1], pointsList[i]);
            }
            pointsList.RemoveAt(pointsList.Count - 1);
            return (float)result;
        }
Пример #4
0
        public void getConvexHullTest()
        {


            PointF[] polygons = new PointF[] { new Point(0,0), new Point(0, 2), new Point(2, 2),
                                                new Point(2,0), new Point(1,1) };
            List<PointF> convexHull = Utils.getConvexHull(polygons.ToList());
            List<PointF> trueConvexHull = new PointF[] {new Point(0,0), new Point(0, 2), new Point(2, 2),
                                                new Point(2,0)}.ToList();
            Assert.AreEqual(trueConvexHull.Except(convexHull).Count(), 0);
            Assert.AreEqual(convexHull.Except(trueConvexHull).Count(), 0);

            polygons = new PointF[] { new Point(0,0), new Point(0, 4), new Point(1, 3), new Point(2, 2), new Point(4, 5),
                                                new Point(4,1), new Point(5,0) };
            convexHull = Utils.getConvexHull(polygons.ToList());
            trueConvexHull = new PointF[] {new Point(0,0), new Point(0, 4), new Point(4, 5),
                                                new Point(5,0) }.ToList();

            Assert.AreEqual(trueConvexHull.Except(convexHull).Count(), 0);
            Assert.AreEqual(convexHull.Except(trueConvexHull).Count(), 0);
        }
Пример #5
0
 public static double DistancePointToPolygonBound(PointF[] points, PointF p, double min)
 {
     double mindis = min + 1;
     PointF linePoint = points[points.Length - 1];
     points.ToList().ForEach(linePoint2 =>
     {
         mindis = Math.Min(mindis,
             DistancePointToLine(linePoint, linePoint2, p));
         linePoint = linePoint2;
     });
     return mindis;
 }
Пример #6
0
        //Allow the user to import an array of points to be used to draw a signature in the view, with new
        //lines indicated by a PointF.Empty in the array.
        public void LoadPoints(PointF[] loadedPoints)
        {
            if (loadedPoints == null || loadedPoints.Count () == 0)
                return;

            var startIndex = 0;
            var emptyIndex = loadedPoints.ToList ().IndexOf (PointF.Empty);

            if (emptyIndex == -1)
                emptyIndex = loadedPoints.Count ();

            //Clear any existing paths or points.
            paths = new List<UIBezierPath> ();
            points = new List<PointF[]> ();

            do {
                //Create a new path and set the line options
                currentPath = UIBezierPath.Create ();
                currentPath.LineWidth = StrokeWidth;
                currentPath.LineJoinStyle = CGLineJoin.Round;

                currentPoints = new List<PointF> ();

                //Move to the first point and add that point to the current_points array.
                currentPath.MoveTo (loadedPoints [startIndex]);
                currentPoints.Add (loadedPoints [startIndex]);

                //Iterate through the array until an empty point (or the end of the array) is reached,
                //adding each point to the current_path and to the current_points array.
                for (var i = startIndex + 1; i < emptyIndex; i++) {
                    currentPath.AddLineTo (loadedPoints [i]);
                    currentPoints.Add (loadedPoints [i]);
                }

                //Add the current_path and current_points list to their respective Lists before
                //starting on the next line to be drawn.
                paths.Add (currentPath);
                points.Add (currentPoints.ToArray ());

                //Obtain the indices for the next line to be drawn.
                startIndex = emptyIndex + 1;
                if (startIndex < loadedPoints.Count () - 1) {
                    emptyIndex = loadedPoints.ToList ().IndexOf (PointF.Empty, startIndex);

                    if (emptyIndex == -1)
                        emptyIndex = loadedPoints.Count ();
                } else
                    emptyIndex = startIndex;
            } while (startIndex < emptyIndex);

            //Obtain the image for the imported signature and display it in the image view.
            imageView.Image = GetImage (false);
            //Display the clear button.
            btnClear.Hidden = false;
            SetNeedsDisplay ();
        }
Пример #7
0
        public void DrawSegments(PointF[] Stroke)
        {
            if (RenderMethod == RenderMode.Standard)
            {
                // Ensure that surface is visible
                if (!this.Visible)
                {
                    this.TopMost = true;
                    this.Show();
                }

                // Create list of points that are new this draw
                List<PointF> NewPoints = new List<PointF>();

                // Get number of points added since last draw including last point of last stroke and add new points to new points list
                int iDelta = Stroke.Count() - LastStroke.Count() + 1;
                NewPoints.AddRange(Stroke.Skip(Stroke.Count() - iDelta).Take(iDelta));

                // Draw new line segments to main drawing surface
                SurfaceGraphics.DrawLines(DrawingPen, NewPoints.Select(p => TranslatePoint(p)).ToArray());

                // Set last stroke to copy of current stroke
                // ToList method creates value copy of stroke list and assigns it to last stroke
                LastStroke = Stroke.ToList();
            }
            else
            {
                foreach (CompatibilitySurface surface in CompatibilitySurfaces)
                    surface.SurfaceGraphics.DrawLines(DrawingPen, surface.OffsetPoints(Stroke));
            }
        }