Crate piecewise_linear

source ·
Expand description

This crate provides utilities to manipulate continuous piecewise linear functions.

They are internally represented as a list of (x, y) pairs, each representing a point of inflection (or equivalently a limit between two linear pieces). The represented function is assumed to be linear between each of these points.


The domain of a function is the range over which it is defined, that is, the range between the smallest x coordinate and the greatest one in the function’s definition points.

Most methods will refuse to operate on two (or more) functions that do not have the same domain. You can use expand_domain() and shrink_domain() to adapt domains.

Domains over all real numbers should be possible by using ±inf x values, but this has not been extensively tested.

Numeric types

This crate should support functions using any CoordFloat (more or less a rust-num Num), however it has not been tested with types other than f32 and f64.



  • Controls how the domain of a function is expanded using expand_domain() on PiecewiseLinearFunction.


  • For algorithms which can only use floating point Points/Coords, like area or length calculations


  • Returns an iterator over pairs (x, values), where x is the union of all points of inflection of self and other, and values is a vector of the values of all passed functions, in the same order, at the corresponding x.
  • Sums the functions together. Returns None in case of domain error.