Builds a piecewise linear envelope around the data using convex hulls and intersection logic similar to the original C++ code.
build_pwl_envelope(data, smallconst = 1e-06)A list with element 'PWL': a numeric matrix of segments (slope, intercept, lower x-bound, upper x-bound). Returns NULL if envelope construction fails due to invalid input.
A numeric matrix with two columns: x and f(x) values. Must have at least two rows.
Small constant for numerical tolerance (default 1e-6).