Esempio n. 1
0
        bool PointIsCloseToLine(double xLeft, double yLeft, double xInt, double yInt,
                                double xRight, double yRight)
        {
            double xProj, yProj;

            NuGenMath.ProjectPointOnToLine(xInt, yInt, xLeft, yLeft, xRight, yRight, out xProj, out yProj);

            return(
                (xInt - xProj) * (xInt - xProj) +
                (yInt - yProj) * (yInt - yProj) < 0.5 * 0.5);
        }
Esempio n. 2
0
        // add point to pointset, not worrying about keeping the pointset single valued (which is for
        // curves only). if new point is on the line between two points then insert it between
        // those two points (desired behavior for curve and measure pointsets, which happens to not affect
        // axes and scale pointsets)
        public void AddPoint(NuGenPoint point)
        {
            // insert point between two other points if it lies on the line between the two points
            const int  LineEpsilonPixels = 2;
            int        index             = 0;
            double     x    = point.XScreen;
            double     y    = point.YScreen;
            NuGenPoint pOld = null;

            foreach (NuGenPoint pNew in points)
            {
                double xNew = pNew.XScreen;
                double yNew = pNew.YScreen;

                if (pOld != null)
                {
                    double xOld = pOld.XScreen;
                    double yOld = pOld.YScreen;

                    double xProj, yProj;
                    NuGenMath.ProjectPointOnToLine(x, y, xOld, yOld, xNew, yNew, out xProj, out yProj);

                    double diff = Math.Sqrt((x - xProj) * (x - xProj) + (y - yProj) * (y - yProj));
                    if (diff < LineEpsilonPixels)
                    {
                        points.Insert(index, point);
                        point.PointSet = this;

                        RemoveLine(pOld, pNew);
                        AddLine(pOld, point);
                        AddLine(point, pNew);

                        return;
                    }
                }

                pOld = pNew;
                index++;
            }

            points.Add(point);
            point.PointSet = this;

            if (pOld != null)
            {
                AddLine(pOld, point);
            }
        }