Exemple #1
0
        private static void TestLineIntersect()
        {
            SegmentLine line = new SegmentLine(new NuGenSegment(0));

            line.StartPoint = new Point(13, 27);
            line.EndPoint   = new Point(19, 55);

            line.Intersects(16, 36, 2.0);
        }
Exemple #2
0
        public void AppendColumn(int x, int y, SegmentSettings seg)
        {
            SegmentLine line = new SegmentLine(this);

            line.StartPoint = new Point(x - 1, yLast);
            line.EndPoint   = new Point(x, y);

            // do not show this line or its segment. this is handled later
            lines.Add(line);

            // update total length using distance formula
            length += Math.Sqrt((1.0) * (1.0) + (y - yLast) * (y - yLast));

            yLast = y;
        }
Exemple #3
0
        public void RemoveUnneededLines()
        {
            // pathological case is y=0.001*x*x, since the small slope can fool a naive algorithm
            // into optimizing away all but one point at the origin and another point at the far right.
            // from this we see that we cannot simply throw away points that were optimized away since they
            // are needed later to see if we have diverged from the curve
            SegmentLine  lineOlder     = null;
            List <Point> removedPoints = new List <Point>();

            foreach (SegmentLine line in lines)
            {
                if (lineOlder != null)
                {
                    double xLeft = lineOlder.StartPoint.X;
                    double yLeft = lineOlder.StartPoint.Y;
                    double xInt  = lineOlder.StartPoint.X;
                    double yInt  = lineOlder.StartPoint.Y;

                    double xRight = line.EndPoint.X;
                    double yRight = line.EndPoint.Y;

                    if (PointIsCloseToLine(xLeft, yLeft, xInt, yInt, xRight, yRight) &&
                        (PointsAreCloseToLine(xLeft, yLeft, removedPoints, xRight, yRight)))
                    {
                        // remove intermediate point, by removing older line and stretching new line to first point
                        removedPoints.Add(new Point((int)(xInt + 0.5), (int)(yInt + 0.5)));

                        lines.Remove(lineOlder);
                        line.StartPoint = new Point((int)(xLeft + 0.5), (int)(yLeft + 0.5));
                        line.EndPoint   = new Point((int)(xRight + 0.5), (int)(yRight + 0.5));
                    }
                    else
                    {
                        //keeping this intermediate point and clear out the removed points list
                        removedPoints.Clear();
                    }
                }

                lineOlder = line;
            }
        }