Пример #1
0
        /// <summary>
        /// Returns the index of a scatter point that is nearest to the location <c>hitpoint</c>
        /// </summary>
        /// <param name="layer">The layer in which this plot item is drawn into.</param>
        /// <param name="hitpoint">The point where the mouse is pressed.</param>
        /// <returns>The information about the point that is nearest to the location, or null if it can not be determined.</returns>
        public XYScatterPointInformation GetNearestPlotPoint(IPlotArea layer, PointD2D hitpoint)
        {
            Processed2DPlotData pdata;

            if (null != (pdata = _cachedPlotDataUsedForPainting))
            {
                PlotRangeList rangeList   = pdata.RangeList;
                PointF[]      ptArray     = pdata.PlotPointsInAbsoluteLayerCoordinates;
                double        mindistance = double.MaxValue;
                int           minindex    = -1;
                for (int i = 1; i < ptArray.Length; i++)
                {
                    double distance = Math2D.SquareDistanceLineToPoint(hitpoint, ptArray[i - 1], ptArray[i]);
                    if (distance < mindistance)
                    {
                        mindistance = distance;
                        minindex    = Math2D.Distance(ptArray[i - 1], hitpoint) < Math2D.Distance(ptArray[i], hitpoint) ? i - 1 : i;
                    }
                }
                // ok, minindex is the point we are looking for
                // so we have a look in the rangeList, what row it belongs to
                int rowindex = rangeList.GetRowIndexForPlotIndex(minindex);

                return(new XYScatterPointInformation(ptArray[minindex], rowindex, minindex));
            }

            return(null);
        }
Пример #2
0
        /// <summary>
        /// Returns the index of a scatter point that is closest to the location <c>hitpoint</c>
        /// </summary>
        /// <param name="layer">The layer in which this plot item is drawn into.</param>
        /// <param name="hitpoint">The point where the mouse is pressed.</param>
        /// <returns>The information about the point that is nearest to the location, or null if it can not be determined.</returns>
        public XYZScatterPointInformation GetNearestPlotPoint(IPlotArea layer, HitTestPointData hitpoint)
        {
            Processed3DPlotData pdata;

            if (null != (pdata = _cachedPlotDataUsedForPainting))
            {
                PlotRangeList rangeList         = pdata.RangeList;
                var           ptArray           = pdata.PlotPointsInAbsoluteLayerCoordinates;
                double        mindistance       = double.MaxValue;
                int           minindex          = -1;
                var           hitTransformation = hitpoint.HitTransformation;
                var           lineStart         = hitTransformation.Transform(ptArray[0]).PointD2DWithoutZ;
                for (int i = 1; i < ptArray.Length; i++)
                {
                    var    lineEnd  = hitTransformation.Transform(ptArray[i]).PointD2DWithoutZ;
                    double distance = Math2D.SquareDistanceLineToPoint(PointD2D.Empty, lineStart, lineEnd);
                    if (distance < mindistance)
                    {
                        mindistance = distance;
                        minindex    = Math2D.Distance(lineStart, PointD2D.Empty) < Math2D.Distance(lineEnd, PointD2D.Empty) ? i - 1 : i;
                    }
                    lineStart = lineEnd;
                }
                // ok, minindex is the point we are looking for
                // so we have a look in the rangeList, what row it belongs to
                int rowindex = rangeList.GetRowIndexForPlotIndex(minindex);

                return(new XYZScatterPointInformation(ptArray[minindex], rowindex, minindex));
            }

            return(null);
        }