Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::client::InterpolateTableContext Struct Reference
+ Collaboration diagram for Slic3r::client::InterpolateTableContext:

Classes

struct  Item
 

Static Public Member Functions

static void init (const expr &x)
 
static void add_pair (const expr &x, const expr &y, InterpolateTableContext &table)
 
static void evaluate (const expr &expr_x, const InterpolateTableContext &table, expr &out)
 

Public Attributes

std::vector< Itemtable
 

Detailed Description


Class Documentation

◆ Slic3r::client::InterpolateTableContext::Item

struct Slic3r::client::InterpolateTableContext::Item
Class Members
IteratorRange it_range_x
double x
double y

Member Function Documentation

◆ add_pair()

static void Slic3r::client::InterpolateTableContext::add_pair ( const expr x,
const expr y,
InterpolateTableContext table 
)
inlinestatic
1631 {
1632 if (x.type() != expr::TYPE_EMPTY) {
1633 if (! x.numeric_type())
1634 x.throw_exception("X value of a table point must be a number.");
1635 if (! y.numeric_type())
1636 y.throw_exception("Y value of a table point must be a number.");
1637 table.table.push_back({ x.as_d(), x.it_range, y.as_d() });
1638 }
1639 }
const Scalar & y
Definition MathFunctions.h:552
TCoord< P > x(const P &p)
Definition geometry_traits.hpp:297
std::vector< Item > table
Definition PlaceholderParser.cpp:1623
@ TYPE_EMPTY
Definition PlaceholderParser.cpp:249

References table, and Slic3r::client::expr::TYPE_EMPTY.

Referenced by Slic3r::client::macro_processor::macro_processor().

+ Here is the caller graph for this function:

◆ evaluate()

static void Slic3r::client::InterpolateTableContext::evaluate ( const expr expr_x,
const InterpolateTableContext table,
expr out 
)
inlinestatic
1640 {
1641 if (expr_x.type() == expr::TYPE_EMPTY)
1642 return;
1643
1644 // Check whether the table X values are sorted.
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);
1660 else if (is_approx(x0, x1))
1661 out.set_d(0.5 * (y0 + y1));
1662 else
1663 out.set_d(Slic3r::lerp(y0, y1, (x - x0) / (x1 - x0)));
1664 evaluated = true;
1665 }
1666 }
1667 if (! evaluated) {
1668 // Clamp x into the table range with EPSILON.
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 // The value is really outside the table range.
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

References Slic3r::client::expr::as_d(), EPSILON, Slic3r::is_approx(), Slic3r::lerp(), Slic3r::client::expr::set_d(), table, Slic3r::client::expr::throw_exception(), Slic3r::client::expr::type(), and Slic3r::client::expr::TYPE_EMPTY.

Referenced by Slic3r::client::macro_processor::macro_processor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init()

static void Slic3r::client::InterpolateTableContext::init ( const expr x)
inlinestatic
1625 {
1626 if (x.type() != expr::TYPE_EMPTY) {
1627 if (!x.numeric_type())
1628 x.throw_exception("Interpolation value must be a number.");
1629 }
1630 }

References Slic3r::client::expr::TYPE_EMPTY.

Referenced by Slic3r::client::macro_processor::macro_processor().

+ Here is the caller graph for this function:

Member Data Documentation

◆ table

std::vector<Item> Slic3r::client::InterpolateTableContext::table

The documentation for this struct was generated from the following file: