1640 {
1642 return;
1643
1644
1645 double x = expr_x.as_d();
1646 bool evaluated = false;
1647 for (
size_t i = 1; i <
table.table.size(); ++i) {
1648 double x0 =
table.table[i - 1].x;
1649 double x1 =
table.table[i].x;
1650 if (x0 > x1)
1651 boost::throw_exception(qi::expectation_failure(
1652 table.table[i - 1].it_range_x.begin(),
table.table[i].it_range_x.end(), spirit::info(
"X coordinates of the table must be increasing")));
1653 if (! evaluated && x >= x0 && x <= x1) {
1654 double y0 =
table.table[i - 1].y;
1655 double y1 =
table.table[i].y;
1656 if (x == x0)
1657 out.set_d(y0);
1658 else if (x == x1)
1659 out.set_d(y1);
1661 out.set_d(0.5 * (y0 + y1));
1662 else
1664 evaluated = true;
1665 }
1666 }
1667 if (! evaluated) {
1668
1669 if (
double x0 =
table.table.front().x;
x > x0 -
EPSILON &&
x < x0)
1670 out.set_d(
table.table.front().y);
1671 else if (
double x1 =
table.table.back().x;
x > x1 &&
x < x1 +
EPSILON)
1672 out.set_d(
table.table.back().y);
1673 else
1674
1675 expr_x.throw_exception("Interpolation value is outside the table range");
1676 }
1677 }
static constexpr double EPSILON
Definition libslic3r.h:51
ColorRGB lerp(const ColorRGB &a, const ColorRGB &b, float t)
Definition Color.cpp:228
constexpr bool is_approx(Number value, Number test_value, Number precision=EPSILON)
Definition libslic3r.h:271