Clip Piecewise-Linear (PWL) Functions

Defines

DEBUG_CLIP

Functions

template <int step, bool need_check = false, typename float_ = double>
float_ clip(Event *elem, Range &pq, float_ slope, float_ offset)

Cut all knots until the PWL is at least zero.

Hereby, start with initial slope and offset. To achieve a value of t, subtract it from offset.

If step is positive, go from pq.start till pq.stop (inclusive); otherwise go the other direction, i.e. from pq.stop down to pq.start (inclusive).

If need_check is set, ensure that in the end std::abs(slope) > EPS; if slope is too close to zero (i.e. EPS) the division by slope might result in strange behavior. That is why a new Event is only added if std::abs(slope) > EPS.

template <int step, bool need_check = false, typename float_ = double>
float_ clip(std::vector<Event> &elem, Range &pq, float_ slope, float_ offset)
double clip_front(Event *elements, Range &pq, double slope, double offset)
double clip_back(Event *elements, Range &pq, double slope, double offset, const double t)
double clip_fronw(Event *elements, Range &pq, double slope, double offset, const double t, const double)
double clip_backw(Event *elements, Range &pq, double slope, double offset, const double t, const double)

Variables

const double EPS = 1e-10

Minimal slope after which the PWL is treated as having zero slope.

const bool DEBUG = false

Printout debugging information?

Functions

std::ostream &operator<<(std::ostream &o, const Event &e)
struct Event
#include <event.hpp>

Record the changes of a piecewise-linear function.

The offset is calculated implicitly as we assume that for any Event e the postion e.x of the event e is the root of the linear function, i.e.

 e.x * e.slope + e.offset() == 0

Public Functions

Event()

Zero event: does not change anything.

Event(double x, double slope)

Default constructor.

Event(double x, double slope, double)

For compatibility: ignore third argument.

double offset() const
bool operator==(const Event &o) const
bool operator<(const Event &other) const

Public Members

double x
double slope

Public Static Attributes

const int _p = 5

Printing precision.

const int _w = 6

Printing width.