Class Dobjects::Function
In: split/Dvector/dvector.c
split/Function/lib/Function_extras.rb
Parent: Object

Function is a class that embeds two Dvectors, one for X data and one for Y data. It provides

And getting bigger everyday…

Methods

Public Class methods

Sorts x, while ensuring that the corresponding y values keep matching. Should be pretty fast, as it is derived from glibc‘s quicksort.

 a = Dvector[3,2,1]
 b = a * 2                 -> [6,4,2]
 Function.joint_sort(a,b)  -> [[1,2,3], [2,4,6]]

Creates a Function object with given x and y values.

Public Instance methods

Returns [xmin, ymin, xmax, ymax]

Interpolates the value of the function at the points given. Returns a brand new Dvector. The X values must be sorted !

Computes spline data and caches it inside the object. Both X and Y vectors are cleared (see Dvector#clear) to make sure the cache is kept up-to-date. If the function is not sorted, sorts it.

Computes the derivative of the Function and returns it as a new Function. The newly created function shares the X vector with the previous one.

Returns the distance of the function to the given point. Optionnal xscale and yscale says by how much we should divide the x and y coordinates before computing the distance. Use it if the distance is not homogeneous.

Iterates over all the points in the Function, yielding X and Y for each point.

: Returns the value of the integral of the function between the two indexes given, or over the whole function if no indexes are specified.

Computes interpolated values of the data contained in f and returns a Function object holding both x_values and the computed Y values. x_values will be sorted if necessary.

With the second form, specify only the number of points, and the function will construct the appropriate vector with equally spaced points within the function range.

is_sorted()

Alias for sorted?

length()

Alias for size

Returns an interpolant that can be fed to Special_Paths#append_interpolant_to_path to make nice splines.

Can be used this way:

 f = Function.new(x,y)
 t.append_interpolant_to_path(f.make_interpolant)
 t.stroke

Returns the point where Y is the maximum

Returns the point where Y is the minimum

Returns a Dvector with two elements: the X and Y values of the point at the given index.

Computes the primitive of the Function (whose value for the first point is 0) and returns it as a new Function. The newly created function shares the X vector with the previous one.

Returns the number of points inside the function.

Sorts the X values while keeping the matching Y values.

Checks if the X values of the Function are sorted.

Splits the function into strictly monotonic sub-functions. Returns the array of the subfunctions. The returned values are necessarily new values.

Strips all the points containing NaN values from the function, and returns the number of points stripped.

The X vector.

The Y vector.

[Validate]