[instancer-solver] port optimization and more tests from fonttools

This commit is contained in:
Qunxin Liu 2023-07-17 13:46:57 -07:00
parent 350423df8d
commit 73ce3015bb
2 changed files with 21 additions and 3 deletions

View file

@ -253,9 +253,8 @@ _solve (Triple tent, Triple axisLimit, bool negative = false)
* axisDef axisMax
*/
float newUpper = peak + (1 - gain) * (upper - peak);
// I feel like the first condition is always true because
// outGain >= gain.
if (axisMax <= newUpper && newUpper <= axisDef + (axisMax - axisDef) * 2)
assert (axisMax <= newUpper); // Because outGain >= gain
if (newUpper <= axisDef + (axisMax - axisDef) * 2)
{
upper = newUpper;
if (!negative && axisDef + (axisMax - axisDef) * MAX_F2DOT14 < upper)

View file

@ -392,5 +392,24 @@ main (int argc, char **argv)
assert (out[4].first == -1.f);
assert (out[4].second == Triple (-1.f, -1.f, -2/(float) (1 << 14)));
}
{
Triple tent (0.f, 1.f, 1.f);
Triple axis_range (-1.f, -0.5f, 1.f);
result_t out = rebase_tent (tent, axis_range, default_axis_distances);
assert (out.length == 1);
assert (out[0].first == 1.f);
assert (out[0].second == Triple (1.f/3, 1.f, 1.f));
}
{
Triple tent (0.f, 1.f, 1.f);
Triple axis_range (-1.f, -0.5f, 1.f);
TripleDistances axis_distances{2.f, 1.f};
result_t out = rebase_tent (tent, axis_range, axis_distances);
assert (out.length == 1);
assert (out[0].first == 1.f);
assert (out[0].second == Triple (0.5f, 1.f, 1.f));
}
}