[instancer_solver] port solver fix: where axisDef < lower and upper < axisMax

Port from f1e56cd757
This commit is contained in:
Qunxin Liu 2023-11-06 09:00:33 -08:00 committed by Behdad Esfahbod
parent 64305568d7
commit 80cb6b580f
2 changed files with 15 additions and 3 deletions

View file

@ -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;

View file

@ -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));
}
}