Class FreehandFunction
java.lang.Object
|
+--FreehandFunction
- class FreehandFunction
- extends java.lang.Object
- implements Function
Allows the user tp "draw" a function. Internally, a finite number
of values will be stored, for regularly spaced x-coordinates. If the
function is evaluated at any other x-coordinate, linear interpolation
will be applied to derive a value.
|
Field Summary |
protected int |
lastX
The last x coordinate the mouse pointer was seen at |
protected double |
maxX
|
protected double |
minX
|
protected double[] |
vals
An array of values, for evenly spaced x coordinate between
minX and maxX. |
|
Constructor Summary |
FreehandFunction(double minX,
double maxX,
int steps)
Creates a new freehand function, for which a number (steps)
of values between minX and maxX may be set. |
|
Method Summary |
double |
evaluate(double x)
Uses linear interpolation to determine the value of the function at x |
void |
update(double x,
double y,
boolean mouseDown)
Called to add a point to the function. |
int |
xToIndex(double x)
Helper method to convert an x coordinate from
graph space to an array index. |
| Methods inherited from class java.lang.Object |
,
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
registerNatives,
toString,
wait,
wait,
wait |
lastX
protected int lastX
- The last x coordinate the mouse pointer was seen at
minX
protected double minX
maxX
protected double maxX
vals
protected double[] vals
- An array of values, for evenly spaced x coordinate between
minX and maxX.
FreehandFunction
public FreehandFunction(double minX,
double maxX,
int steps)
- Creates a new freehand function, for which a number (
steps)
of values between minX and maxX may be set.
evaluate
public double evaluate(double x)
- Uses linear interpolation to determine the value of the function at x
- Specified by:
- evaluate in interface Function
update
public void update(double x,
double y,
boolean mouseDown)
- Called to add a point to the function.
- Parameters:
x - The x coordinate (in screen space)y - The y coordinate (in screen space)mouseDown - true if this is the first point to be
added in this mouse gesture (ie. the first position reported since
the mouse button was depressed)
xToIndex
public int xToIndex(double x)
- Helper method to convert an x coordinate from
graph space to an array index.