diff --git a/src/hb-subset-instancer-solver.cc b/src/hb-subset-instancer-solver.cc index 4cb3f8a48..4876bc437 100644 --- a/src/hb-subset-instancer-solver.cc +++ b/src/hb-subset-instancer-solver.cc @@ -168,12 +168,14 @@ _solve (Triple tent, Triple axisLimit, bool negative = false) * | * crossing */ - if (gain > outGain) + if (gain >= outGain) { + // Note that this is the branch taken if both gain and outGain are 0. + // Crossing point on the axis. float crossing = peak + (1 - gain) * (upper - peak); - Triple loc{axisDef, peak, crossing}; + Triple loc{hb_max (lower, axisDef), peak, crossing}; float scalar = 1.f; // The part before the crossing point. @@ -253,7 +255,7 @@ _solve (Triple tent, Triple axisLimit, bool negative = false) * axisDef axisMax */ float newUpper = peak + (1 - gain) * (upper - peak); - assert (axisMax <= newUpper); // Because outGain >= gain + assert (axisMax <= newUpper); // Because outGain > gain if (newUpper <= axisDef + (axisMax - axisDef) * 2) { upper = newUpper; diff --git a/src/test-subset-instancer-solver.cc b/src/test-subset-instancer-solver.cc index e8294cfa8..f68a7deb4 100644 --- a/src/test-subset-instancer-solver.cc +++ b/src/test-subset-instancer-solver.cc @@ -411,5 +411,15 @@ main (int argc, char **argv) assert (out[0].first == 1.f); assert (out[0].second == Triple (0.5f, 1.f, 1.f)); } + + { + Triple tent (0.6f, 0.7f, 0.8f); + Triple axis_range (-1.f, 0.2f, 1.f); + TripleDistances axis_distances{1.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, 0.625f, 0.75f)); + } }