>> How many times do you have to solve this for each glyph?
>
> A considerable amount of time. If you want the exact number it is
> `width * rows * number_of_conic_curves', without any optimization.
Ouch.
>> How many different solutions (aka curve points) do you have to find
>> for each curved segment? I figure there are a lot of grid-curve
>> pairs to enumerate with most of the curve segment sampled fairly
>> frequently...
>
> This can be as many as 65536, this is tied to the width and rows of
> the bitmap being generated. The more the resolution the more curve
> points have to be checked.
>
> And yes there are various grid points which correspond to the same
> curve point. If the grid point lies on the same perpendicular from
> the curve then their curve point might be the same.
>
>> Do you see where I am going?
>
> I'm not sure. Are you telling me to use the results of the previous
> iteration?
I think he means that the code must be optimized as much as possible
to get fast rendering. In particular, it is important to find and
eliminate hotspots.
> I have fixed the overflow, it was just my stupid calculation
> mistake. [...]
Excellent. Will check the code soon.
> I have updated the repositories and perhaps I can now start
> integrating it into freetype?
Certainly. Please create a branch for your stuff and try to add your
code in small (if possible), concise commits. This doesn't hold for
new files, which should be simply added as-is.
Some comments to your code.
* What does line 38 do?
https://github.com/preversewharf45/freetype2-sdf/blob/dcedba69423fc169a9ca95b6391902e1cf27e0b6/src/sdfgen.c#L38
It seems that `pup` and `roots` aren't used at all.
* Function `get_min_conour` should probably be called
`get_min_contour`. Otherwise please explain in a comment what
'conour' means.
* Our coding style is to use
if ( foo )
bar;
for single-line statements instead of
if ( foo )
{
bar;
}
* Have you thought about iterative solutions to get the cubic roots
necessary for the quadratic case? Maybe this would be faster.
* Maybe there is a mathematical approximation to solving the
fifth-grade polynomial. I don't mean a better root-finding
algorithm but a simpler representation of the curves so that we can
avoid a fifth-grade polynomial altogether. The same holds for the
third-grade equation, of course.
* Typo: s/simliar/similar/
* If you end a comment with a full stop, please start it with an
uppercase letter so that it becomes a normal English sentence.
Werner
PS: Did you have a look at Behdad's `GLyphy` implementation?