Beispiel #1
0
        public void OnPointDragged(MovePointBehaviour.PointMoveEventArgs e)
        {
            var oldPoint = e.OldPoint;
            var newPoint = e.NewPoint;

            var index            = Curve.IndexOf(e.OldPoint);
            var prevPoint        = Curve.Points[index - 1];
            var biggestValueForY = double.MinValue;

            var newCurve = Curve.Points.GetRange(0, Curve.Points.Count);

            newCurve[index] = newPoint;
            var lastPoint = newCurve[newCurve.Count - 1];

            for (double x = 0; x < lastPoint.X; x++)
            {
                var y = CurveMath.SolveCubicSpline(newCurve, x);
                if (biggestValueForY > y)
                {
                    newPoint = oldPoint;
                    break;
                }

                if (y > biggestValueForY)
                {
                    biggestValueForY = y;
                }
            }

            e.NewPoint          = newPoint;
            Curve.Points[index] = e.NewPoint;

            Points = CalculateNewPoints();
        }
Beispiel #2
0
        public void OnPointDragged(MovePointBehaviour.PointMoveEventArgs e)
        {
            var oldPoint = e.OldPoint;
            var newPoint = e.NewPoint;

            var index = Curve.IndexOf(e.OldPoint);

            var newCurve = Curve.Points.GetRange(0, Curve.Points.Count);

            newCurve[index] = newPoint;

            var firstPoint = newCurve[0];
            var lastPoint  = newCurve[newCurve.Count - 1];

            var biggestValueForY = double.MinValue;

            if (ValidateCurve)
            {
                for (double x = firstPoint.X + 0.01; x < lastPoint.X - 0.01; x++)
                {
                    var y = CurveMath.SolveCubicSpline(newCurve, x);
                    if (y < biggestValueForY || newPoint.X >= lastPoint.X || newPoint.X <= firstPoint.X)
                    {
                        newPoint = oldPoint;
                        break;
                    }

                    if (y > biggestValueForY)
                    {
                        biggestValueForY = y;
                    }
                }
            }

            e.NewPoint          = newPoint;
            Curve.Points[index] = e.NewPoint;

            Points = CalculateNewPoints();
            UpdateSelectedPoint();
        }
Beispiel #3
0
 public double getY(double x)
 {
     return(CurveMath.SolveCubicSpline(curve.Points, x));
 }