示例#1
0
        /// <summary>
        /// Subdivides a line by a given number of subdivisions
        /// </summary>
        /// <param name="line">line to subdivide</param>
        /// <param name="subDividionCount">number of subdivisions</param>
        /// <returns>multidimensional array of start and end points of subdivision lines</returns>
        public static System.Drawing.Point[] SubdivideLine(Line2d line, int subDividionCount)
        {
            // create an array for subdivision points
            System.Drawing.Point[] points = new System.Drawing.Point[subDividionCount - 1];

            // calculate length of a single subdivision step
            // there is a possiblity of a round of error here
            // e.g.: 95 / 10 = 9
            int divisionLength = line.Length / subDividionCount;

            int[] divisionStepLengths = Enumerable.Repeat(divisionLength, points.Length).ToArray();

            // clean up round error if any
            if (divisionLength * subDividionCount != line.Length)
            {
                var i = 0;
                while (divisionStepLengths.Sum() + divisionLength < line.Length)
                {
                    if (i % 2 == 0)
                    {
                        divisionStepLengths[i] += 1;
                    }
                    else
                    {
                        divisionStepLengths[divisionStepLengths.Length - i] += 1;
                    }

                    i += 1;
                }
            }

            // iterate over points array and fill it
            var startPoint = line.From;

            for (int i = 0; i < divisionStepLengths.Length; i++)
            {
                points[i]  = new System.Drawing.Point(startPoint.X - divisionStepLengths[i], line.From.Y);
                startPoint = points[i];
            }

            return(points);
        }
示例#2
0
 public static void DrawLine2d(this DisplayPipeline pipeline, Line2d line, Color lineColor, int lineThickness)
 {
     pipeline.Draw2dLine(line.From, line.To, lineColor, lineThickness);
 }