Пример #1
0
        /// <summary>
        /// Returns True if connecting two provided data point based on cross side is possible otherwise False
        /// </summary>
        /// <param name="dataSeries"></param>
        /// <param name="startIndex">The first point index in data series</param>
        /// <param name="endIndex">The second point index in data series</param>
        /// <param name="direction">The line direction, is it on up direction or low direction?</param>
        /// <returns>bool</returns>
        public static bool IsConnectionPossible(this DataSeries dataSeries, int startIndex, int endIndex, Direction direction)
        {
            if (startIndex >= endIndex)
            {
                throw new ArgumentException("The 'startIndex' must be less than 'secondPointIndex'");
            }

            var slope = dataSeries.GetSlope(startIndex, endIndex);

            var counter = 0;

            for (var i = startIndex + 1; i <= endIndex; i++)
            {
                counter++;

                if (direction == Direction.Up && dataSeries[i] < dataSeries[startIndex] + slope * counter)
                {
                    return(false);
                }
                else if (direction == Direction.Down && dataSeries[i] > dataSeries[startIndex] + slope * counter)
                {
                    return(false);
                }
            }

            return(true);
        }