Skip to content

Make Merge/splinefit/ApproximateSplineFromPoints* more accurate #4552

@linusromer

Description

@linusromer

This is a improvement request. When using "Merge" in FontForge, the resulting merged curve is quite inaccurate in many cases.
The following image shall illustrate this inaccurateness:
merge0
If several segments are to be merged, FontForge's algorithm (right) is even worse in comparison with my algorithm (left): (only the upper right segments have been merged)
merge2

I think splinefit.c and the ApproximateSplineFromPoint* methods are responsible for "Merge".

The main problem of FontForge's algorithm IMHO is the assumption that the point at time t of the approximation contour is near the point at time t of the original contour. But because FontForge's contour are not parameterized by arc length, this assumption is bad.

If you want you may use my algorithm: I have varied the handle lengths until the error of the approximation contour has become minimal. The error is calculated as follows:

  • calculate few (9) points inbetween the start and the end point of the original contour
  • calculate more (99) points inbetween the start and the end point of the approximation contour
  • for each of the original 9 points find the smallest squared distance to the 99 points; the sum of the squared distances is the error

I have made a quick Python plugin to test the algorithm. It seems to work okay (only the User Interface function is bad).

Example font and Python plugin in mergebezier.zip
(I have updated the plugin because I had implemented a small part which made the error calculation faster but worse in some situations. Now it really should follow the description that is already given here.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions