Esempio n. 1
0
        /// <summary>
        /// Finds the point nearest to a specified point on a screen.
        /// </summary>
        /// <param name="screenPoint">The point to search nearest for.</param>
        /// <param name="nearest">The out parameter to handle the founded point.</param>
        /// <param name="vd">The out parameter to handle data of founded point.</param>
        /// <returns>Boolen value indicating whether the nearest point was found or not.</returns>
        public bool GetNearestPointAndValue(Point screenPoint, out Point nearest, out double vd)
        {
            nearest = new Point(Double.NaN, Double.NaN);
            vd      = Double.NaN;
            if (data == null || xArr == null || yArr == null)
            {
                return(false);
            }
            Point dataPoint = new Point(XDataTransform.PlotToData(XFromLeft(screenPoint.X)), YDataTransform.PlotToData(YFromTop(screenPoint.Y)));//PlotContext.ScreenToData(screenPoint);
            int   i         = ArrayExtensions.GetNearestIndex(xArr, dataPoint.X);

            if (i < 0)
            {
                return(false);
            }
            int j = ArrayExtensions.GetNearestIndex(yArr, dataPoint.Y);

            if (j < 0)
            {
                return(false);
            }
            if (IsBitmap)
            {
                if (i > 0 && xArr[i - 1] > dataPoint.X)
                {
                    i--;
                }
                if (j > 0 && yArr[j - 1] > dataPoint.Y)
                {
                    j--;
                }
            }
            if (i < data.GetLength(0) && j < data.GetLength(1))
            {
                vd      = data[i, j];
                nearest = new Point(xArr[i], yArr[j]);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Finds the point nearest to a specified point on a screen.
        /// </summary>
        /// <param name="screenPoint">The point to search nearest for.</param>
        /// <param name="nearest">The out parameter to handle the founded point.</param>
        /// <param name="vd">The out parameter to handle data of founded point.</param>
        /// <returns>Boolen value indicating whether the nearest point was found or not.</returns>
        public bool GetNearestPointAndValue(Point screenPoint, out Point nearest, out double vd)
        {
            nearest = new Point(Double.NaN, Double.NaN);
            vd      = Double.NaN;
            if (DataContainer == null || XArray == null || YArray == null)
            {
                return(false);
            }
            Point dataPoint = new Point(XDataTransform.PlotToData(XFromLeft(screenPoint.X)), YDataTransform.PlotToData(YFromTop(screenPoint.Y)));
            int   i         = ArrayExtensions.GetNearestIndex(XArray, dataPoint.X);

            if (i < 0)
            {
                return(false);
            }
            int j = ArrayExtensions.GetNearestIndex(YArray, dataPoint.Y);

            if (j < 0)
            {
                return(false);
            }
            if (IsBitmap)
            {
                if (i > 0 && XArray[i - 1] > dataPoint.X)
                {
                    i--;
                }
                if (j > 0 && YArray[j - 1] > dataPoint.Y)
                {
                    j--;
                }
            }
            if (i < DataContainer.GetLength(0) && j < DataContainer.GetLength(1))
            {
                vd      = DataContainer[i, j];
                nearest = new Point(XArray[i], YArray[j]);
                return(true);
            }
            else
            {
                return(false);
            }
        }