LittleFunny
LittleFunny

Reputation: 8375

CurveTo and ContinueCurveTo not drawing properly

I am using NGraphics and I want to generate a smooth curve.

Android devices are showing a different result, compared to iPhone when using the code below.

The line with surrounded by asterisks (*), if used on Android (tested on Samsung Galaxy S4) the curve looks as expected. However, on iPhone it doesn't look correct.

private bool DrawingMove(TouchData touchData)
{
    if (touchData == null)
    {
        Invalidate();
        return true;
    }

    foreach (var stroke in _localStroke)
    {
        if (stroke.Pointer == touchData.PointerId)
        {
            var newPoint = ConvertLocalToGlobal(touchData.Point);
            var point = new PointModel();
            point.X = newPoint.X;
            point.Y = newPoint.Y;

            stroke.Points.Add(point);

            var length = stroke.Points.Count - 1;

            if (stroke.Points.Count >= 3)
            {
                var p1 = ConvertGlobalToLocal(
                    new Point(stroke.Points[length - 2].X,
                              stroke.Points[length - 2].Y));
                var p2 = ConvertGlobalToLocal(
                    new Point(stroke.Points[length - 1].X, 
                              stroke.Points[length - 1].Y));
                var p3 = ConvertGlobalToLocal(
                    new Point(stroke.Points[length].X, 
                              stroke.Points[length].Y));

                if (stroke.Points.Count == 3)
                {
                    stroke.Path.MoveTo(p1);
                    stroke.Path.CurveTo(p1, p2, p3);
                }
                else if (stroke.Points.Count > 3)
                {
                    **stroke.Path.LineTo(p2);**
                    stroke.Path.ContinueCurveTo(p2, p3);

                    Console.WriteLine("Path.ContinueCurveTo(new Point(" + p2.X + "," + p2.Y + "),new Point(" + p3.X + "," + p3.Y + "));");
                }
            }

            break;
        }
    }
    return base.TouchesMoved(touchData);
}

The code above generates the following results:

iPhone iPhone Screenshot

Android Android Screenshot

I've also tried to reproduce this in small samples without all the touch drawing code above, simply by passing in coordinates to CurveTo and ContinueCurveTo, which yield the same results.

Upvotes: 0

Views: 87

Answers (1)

LittleFunny
LittleFunny

Reputation: 8375

Found the answer... Just realised I have to pass in the current point plus the previous point and get the middle point.

Upvotes: 0

Related Questions