xamarin / SignaturePad

MIT License
246 stars 150 forks source link

Curves seem a bit jagged #85

Open robertmiles3 opened 7 years ago

robertmiles3 commented 7 years ago

Just finding this and checking it out (great work by the way!!). I love that it's a component and could easily be what I'm looking for.

I'm comparing a few Xamarin samples of drawing like SpeedSketch and TouchCanvas. I've noticed that the curves as you write on SignaturePad are slightly jagged and not as smooth as some of these samples. Is there anything I can help with to get it a bit smoother? So far, SpeedSketch is by far the smoothest lines and curves I've seen among the samples. After reviewing the code, I'm finding it incredibly hard to follow, but I'd be willing to dig if pointed in the right direction.

Here's a side-by-side example of me writing an "R" with my Apple Pencil on both SignaturePad and SpeedSketch (iPad Pro 2017 10.5"):

screen shot 2017-07-26 at 7 36 48 pm
robertmiles3 commented 7 years ago

I think I've made a little progress with just a few lines of code. Instead of using the SmoothedPathWithGranularity function, I made some tweaks to the iOS InkPresenter and came up with this.

screen shot 2017-07-28 at 10 32 50 am

Besides looking better, the stats reported from the sample app show the old at 200-250 points while my new shows 50-60 points.

mattleibow commented 7 years ago

Hi @robertmiles3, that looks good. What did you do?

robertmiles3 commented 7 years ago

You can check it at...

https://github.com/robertmiles3/SignaturePad/tree/smoother-paths

For now, it's working great. I've only edited the iOS portion so far, so if it's liked then we can figure out the other platforms as well.

mattleibow commented 7 years ago

@robertmiles3 This looks really good. I tested it out and it works pretty well.

The only thing that I noticed is that the last point is sometimes "lost". You are waiting for 4 points, but the user may stop before.

For Android, this extension method may help:

public static void AddCurveToPoint (this Path path, System.Drawing.PointF endPoint, System.Drawing.PointF controlPoint1, System.Drawing.PointF controlPoint2)
{
    path.CubicTo (controlPoint1.X, controlPoint1.Y, controlPoint2.X, controlPoint2.Y, endPoint.X, endPoint.Y);
}

Other than that one issue with the last point, I think this is something that I would like to merge it as soon as you are finished.

mattleibow commented 6 years ago

Just linking this: #92