OrcaSlicer latest
OrcaSlicer
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< Item > table

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()

void Slic3r::client::InterpolateTableContext::add_pair ( const expr & x,
const expr & y,
InterpolateTableContext & table )
inlinestatic
1956 {
1957 if (x.type() != expr::TYPE_EMPTY) {
1958 if (! x.numeric_type())
1959 x.throw_exception(L("X value of a table point must be a number."));
1960 if (! y.numeric_type())
1961 y.throw_exception(L("Y value of a table point must be a number."));
1962 table.table.push_back({ x.as_d(), x.it_range, y.as_d() });
1963 }
1964 }
#define L(s)
Definition ExtrusionEntity.cpp:25
std::vector< Item > table
Definition PlaceholderParser.cpp:1948
@ TYPE_EMPTY
Definition PlaceholderParser.cpp:306

References Slic3r::client::expr::as_d(), Slic3r::client::expr::it_range, L, Slic3r::client::expr::numeric_type(), 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:

◆ evaluate()

void Slic3r::client::InterpolateTableContext::evaluate ( const expr & expr_x,
const InterpolateTableContext & table,
expr & out )
inlinestatic
1965 {
1966 if (expr_x.type() == expr::TYPE_EMPTY)
1967 return;
1968
1969 // Check whether the table X values are sorted.
1970 double x = expr_x.as_d();
1971 assert(! std::isnan(x));
1972 bool evaluated = false;
1973 for (size_t i = 1; i < table.table.size(); ++i) {
1974 double x0 = table.table[i - 1].x;
1975 double x1 = table.table[i].x;
1976 if (x0 > x1)
1977 boost::throw_exception(qi::expectation_failure(
1978 table.table[i - 1].it_range_x.begin(), table.table[i].it_range_x.end(), spirit::info(std::string("*") + L("X coordinates of the table must be increasing"))));
1979 if (! evaluated && x >= x0 && x <= x1) {
1980 double y0 = table.table[i - 1].y;
1981 double y1 = table.table[i].y;
1982 if (x == x0)
1983 out.set_d(y0);
1984 else if (x == x1)
1985 out.set_d(y1);
1986 else if (is_approx(x0, x1))
1987 out.set_d(0.5 * (y0 + y1));
1988 else
1989 out.set_d(Slic3r::lerp(y0, y1, (x - x0) / (x1 - x0)));
1990 evaluated = true;
1991 }
1992 }
1993 if (! evaluated) {
1994 // Clamp x into the table range with EPSILON.
1995 if (double x0 = table.table.front().x; x > x0 - EPSILON && x < x0)
1996 out.set_d(table.table.front().y);
1997 else if (double x1 = table.table.back().x; x > x1 && x < x1 + EPSILON)
1998 out.set_d(table.table.back().y);
1999 else
2000 // The value is really outside the table range.
2001 expr_x.throw_exception(L("Interpolation value is outside the table range"));
2002 }
2003 }
#define EPSILON
Definition ColorUtils.cpp:64
ColorRGB lerp(const ColorRGB &a, const ColorRGB &b, float t)
Definition Color.cpp:244
constexpr bool is_approx(Number value, Number test_value, Number precision=EPSILON)
Definition libslic3r.h:320

References Slic3r::client::expr::as_d(), EPSILON, Slic3r::is_approx(), L, 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()

void Slic3r::client::InterpolateTableContext::init ( const expr & x)
inlinestatic
1950 {
1951 if (x.type() != expr::TYPE_EMPTY) {
1952 if (!x.numeric_type())
1953 x.throw_exception(L("Interpolation value must be a number."));
1954 }
1955 }

References L, Slic3r::client::expr::numeric_type(), 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:

Member Data Documentation

◆ table

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

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