Beispiel #1
0
        /// <summary>
        /// draw the path to a target
        /// </summary>
        /// <param name="target">the draw target</param>
        /// <param name="strokeSize">the stroke size, 0-1</param>
        public void DrawTo(IDrawTarget target, float strokeSize = 1)
        {
            // set the color and stroke
            target.SetPrimaryColor(color);
            target.SetStroke(strokeSize);

            // draw the path
            target.DrawPoly(Vertices);
        }
Beispiel #2
0
        /// <summary>
        /// Draw a list of dots by drawing polygons
        /// </summary>
        /// <param name="target">draw target</param>
        /// <param name="dots">the dot list</param>
        /// <param name="totalDots">the total number of dots (progress reporting)</param>
        /// <param name="dotsDrawn">the total number of dots drawn (progress reporting)</param>
        /// <returns>the number of dots drawn</returns>
        private int DrawUsingPolys(IDrawTarget target, List <PointF> dots, double totalDots, double dotsDrawn)
        {
            // sort dots by x, then y
            dots.Sort((d1, d2) =>
            {
                // Y 0 ==> Y 1
                if (d1.X.Equals(d2.X))
                {
                    return(d1.Y.CompareTo(d2.Y));
                }

                // X 0 ==> X 1
                return(d1.X.CompareTo(d2.X));
            });

            // get the size of one dot
            // keep the sizes squared to safe (a few) sqrts
            float dotW             = 1 / mapSize.Width;
            float dotH             = 1 / mapSize.Height;
            float oneDotDiagonally = MathF.Abs((dotW * dotW) + (dotH * dotH));

            // enumerate all dots, top to bottom and left to right
            List <PointF> poly = new List <PointF>();

            foreach (PointF dot in dots)
            {
                // first dot requires special handling...
                if (poly.Count <= 0)
                {
                    poly.Add(dot);
                    continue;
                }

                // get distance to last dot
                float dist = DotDistanceSq(dot, poly.Last());

                // if the dot is less than 1 dot (diagonally) away from the last, just add it to the polygon
                // otherwise, draw the polygon, and start a new one
                if (MathF.Abs(dist) > oneDotDiagonally)
                {
                    //remove all dots in the poly that are in a direct line to another dot in the poly
                    //such that they are not needed for drawing
                    PointF l = poly[0];
                    for (int i = 1; i < (poly.Count - 1); i++)
                    {
                        PointF c = poly[i];

                        if (MathF.Abs(c.X - l.X) < dotW ||
                            MathF.Abs(c.Y - l.Y) < dotH)
                        {
                            poly.RemoveAt(i);
                            continue;
                        }

                        l = c;
                    }

                    // draw and reset poly
                    target.DrawPoly(poly.ToArray());
                    poly.Clear();

                    // report progress
                    ReportProgress(dotsDrawn / totalDots);
                }

                // add dot to poly
                poly.Add(dot);
                dotsDrawn++;
            }

            // draw the last polygon
            target.DrawPoly(poly.ToArray());
            return(dots.Count);
        }