private void DragHSpline(MouseEventArgs e)
        {
            // yCursorPosition = e.GetPosition(LayoutRoot).Y - _point.Y;
            // _lastClickedPositionX = e.GetPosition(LayoutRoot).X - _point.X;
            var cursorPosition      = CursorPosition(e);
            var xCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaX(cursorPosition.X + W_DIV_2, _plotArea, _worldArea);
            var yCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaY(cursorPosition.Y + H_DIV_2, _plotArea, _worldArea);

            if (HermiteRegularCheckBox.IsChecked.Value)
            {
                if (cursorPosition.X <= _leftEllipseX + DEFAULT_REDRAWING_PRECISION)
                {
                    cursorPosition.X = _leftEllipseX + DEFAULT_REDRAWING_PRECISION;
                    // CanvasMyUtils.RemoveCPFromHermiteSpline(_redrawedHermiteSpline,_changedCPPos,canvas1,_engine);
                    return;
                }
                else if (cursorPosition.X >= _rightEllipseX - DEFAULT_REDRAWING_PRECISION && _rightEllipseX != -1)
                {
                    cursorPosition.X = _rightEllipseX - DEFAULT_REDRAWING_PRECISION;
                    //CanvasMyUtils.RemoveCPFromHermiteSpline(_redrawedHermiteSpline, _changedCPPos, canvas1, _engine);
                    return;
                }
            }
            _selectedEllipse.SetValue(Canvas.TopProperty, cursorPosition.Y);
            _selectedEllipse.SetValue(Canvas.LeftProperty, cursorPosition.X);

            // try
            //{

            _selectedHermiteSpline.ControlPoints[_changedPointIndex] = yCursorPositionInWA;

            _selectedHermiteSpline.Knots[_changedPointIndex] = xCursorPositionInWA;

            //}
            //catch (Exception) { }
            // _selectedEllipse.SetValue(Canvas.TopProperty, e.GetPosition(LayoutRoot).controlPoints - _point.controlPoints);
            _dragInfoLabel.WriteAndSetCoordinates(_changedPointIndex, xCursorPositionInWA, yCursorPositionInWA, cursorPosition.X + AVOID_CURSOR_X, cursorPosition.Y + H_DIV_2);
            _dragInfoLabel.Visibility = Visibility.Visible;
            _canvasUtilities.RefreshHermiteSplineInCanvas(_selectedHermiteSpline, canvas1, _engine);
            //_canvasUtilities.TotalRefreshHermiteSplineInCanvas(_selectedHermiteSpline, canvas1, _engine);
            // }
        }
        public new Tuple <double, double, double, double> Range_MinX_MaxX_MinY_MaxY(PlotArea plotArea, WorldArea worldArea)
        {
            double minX = double.MaxValue;
            double maxX = double.MinValue;
            double minY = double.MaxValue;
            double maxY = double.MinValue;

            for (int i = 0; i < LinesOfSpline.Count; i++)
            {
                var X1 = TransformCoordinates.PlotAreaToWorldAreaX(LinesOfSpline[i].X1, plotArea, worldArea);
                var X2 = TransformCoordinates.PlotAreaToWorldAreaX(LinesOfSpline[i].X2, plotArea, worldArea);
                var Y1 = TransformCoordinates.PlotAreaToWorldAreaY(LinesOfSpline[i].Y1, plotArea, worldArea);
                var Y2 = TransformCoordinates.PlotAreaToWorldAreaY(LinesOfSpline[i].Y2, plotArea, worldArea);
                if (X1 < minX)
                {
                    minX = X1;
                }
                if (X2 > maxX)
                {
                    maxX = X2;
                }
                if (Y1 < minY)
                {
                    minY = Y1;
                }
                if (Y2 > maxY)
                {
                    maxY = Y2;
                }
            }

            //for (int i = 0; i < DragEllipses.Count; i++)
            //{
            //    var X = TransformCoordinates.PlotAreaToWorldAreaX(DragEllipses[i]., plotArea, worldArea);
            //    var Y = TransformCoordinates.PlotAreaToWorldAreaY(DragEllipses[i].X2, plotArea, worldArea);
            //}

            return(Tuple.Create(minX, maxX, minY, maxY));
        }
        private void DragBSpline(MouseEventArgs e)
        {
            if (!UniformBSpline_CheckBox.IsChecked.Value)
            {
                // _lastClickedPositionX = e.GetPosition(LayoutRoot).X - _point.X;
                // yCursorPosition = e.GetPosition(LayoutRoot).Y - _point.Y;

                var cursorPosition      = CursorPosition(e);
                var xCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaX(cursorPosition.X + W_DIV_2, _plotArea, _worldArea);
                var yCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaY(cursorPosition.Y + H_DIV_2, _plotArea, _worldArea);

                if (cursorPosition.X <= _leftEllipseX + DEFAULT_REDRAWING_PRECISION)
                {
                    cursorPosition.X = _leftEllipseX + DEFAULT_REDRAWING_PRECISION;
                    // CanvasMyUtils.RemoveCPFromHermiteSpline(_redrawedHermiteSpline,_changedCPPos,canvas1,_engine);
                    return;
                }
                // else if (cursorPosition.X >= _rightEllipseX - DEFAULT_REDRAWING_PRECISION && _rightEllipseX != -1)
                else if (cursorPosition.X >= _rightEllipseX - DEFAULT_REDRAWING_PRECISION)// && _stupidFastHackToResolveBugWithBSplineWhenLastEllipseIsDragged)
                {
                    cursorPosition.X = _rightEllipseX - DEFAULT_REDRAWING_PRECISION;
                    //CanvasMyUtils.RemoveCPFromHermiteSpline(_redrawedHermiteSpline, _changedCPPos, canvas1, _engine);
                    return;
                }

                _selectedEllipse.SetValue(Canvas.LeftProperty, cursorPosition.X);
                _selectedEllipse.SetValue(Canvas.TopProperty, cursorPosition.Y);


                //try
                //{


                _selectedBSpline.Knots[_changedKnotPos] = xCursorPositionInWA;

                _selectedBSpline.ControlPoints[_changedPointIndex] = yCursorPositionInWA;
                //if (_selectedBSpline.Knots[_changedKnotPos] >= _selectedBSpline.Knots[_changedKnotPos + 1])
                //{
                //    var swap = _selectedBSpline.Knots[_changedKnotPos + 1];
                //    _selectedBSpline.Knots[_changedKnotPos + 1] = _selectedBSpline.Knots[_changedKnotPos];
                //    _selectedBSpline.Knots[_changedKnotPos] = swap;
                //    var idx= _selectedBSpline.DragEllipses.IndexOf(_selectedEllipse as Ellipse);
                //    var swapEl = _selectedBSpline.DragEllipses[idx + 1];
                //    _selectedBSpline.DragEllipses[idx + 1] = _selectedBSpline.DragEllipses[idx];
                //    _selectedBSpline.DragEllipses[idx] = swapEl;
                //}

                //}
                //catch (Exception) { }

                _dragInfoLabel.WriteAndSetCoordinates(_changedPointIndex, xCursorPositionInWA, yCursorPositionInWA, cursorPosition.X + AVOID_CURSOR_X, cursorPosition.Y + H_DIV_2);
                _dragInfoLabel.Visibility = Visibility.Visible;
                //CanvasMyUtils.OptimizedRefreshBSplineInCanvas(_selectedBSpline, _changedCPPos, canvas1, _engine, false);
                _canvasUtilities.RefreshBSplineInCanvas(_selectedBSpline, canvas1, _engine);
            }
            else
            {
                // yCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaY(yCursorPosition + H_DIV_2, _plotArea, _worldArea);

                //yCursorPosition = e.GetPosition(LayoutRoot).Y - _point.Y;
                var yCursorPosition = CursorPositionY(e);
                _selectedEllipse.SetValue(Canvas.TopProperty, yCursorPosition);
                //try
                //{
                var yCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaY(yCursorPosition + H_DIV_2, _plotArea, _worldArea);
                _selectedBSpline.ControlPoints[_changedPointIndex] = yCursorPositionInWA;


                //}
                //catch (Exception) { }
                var selectedKnotPositionInPA = TransformCoordinates.WorldAreaToPlotAreaX(_selectedBSpline.Knots[_changedKnotPos], _plotArea, _worldArea);
                _dragInfoLabel.WriteAndSetCoordinates(_changedPointIndex, _selectedBSpline.Knots[_changedKnotPos], yCursorPositionInWA, selectedKnotPositionInPA + AVOID_CURSOR_X, yCursorPosition + H_DIV_2);
                _dragInfoLabel.Visibility = Visibility.Visible;
                _canvasUtilities.RefreshBSplineInCanvas(_selectedBSpline, canvas1, _engine);
            }
        }