MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / FunctionDrawer

Class FunctionDrawer

src/org/opensourcephysics/display/FunctionDrawer.java:26–257  ·  view source on GitHub ↗

FunctionDrawer draws a function from xmin to xmax. The function will be evaluated at every screen pixel unless the domain is set using the initialize method. @author Wolfgang Christian @author Joshua Gould @version 1.0

Source from the content-addressed store, hash-verified

24 * @version 1.0
25 */
26public class FunctionDrawer implements Drawable, Measurable, Function {
27 protected double[] xrange = new double[2];
28 protected double[] yrange = new double[2];
29 protected int numpts = 0;
30 protected GeneralPath generalPath = new GeneralPath();
31 protected Function function;
32 protected boolean filled = false;
33 protected boolean measured = false; // set to true if function has been initialized.
34 public Color color = Color.black;
35 public boolean functionChanged = false;
36 protected boolean enabled = true;
37
38 public void setEnabled(boolean b) {
39 enabled = b;
40 }
41 /**
42 * Constructs a FunctionDrawer with optimum resolution.
43 *
44 * @param f the function that will be drawn.
45 */
46 public FunctionDrawer(Function f) {
47 function = f;
48 }
49
50 /**
51 * Creates the function drawer and initialzies the domain with the given values.
52 * @param f Function
53 * @param xmin double
54 * @param xmax double
55 * @param numpts int
56 * @param filled boolean fills the area under the curve with the drawing color when true
57 */
58 public FunctionDrawer(Function f, double xmin, double xmax, int numpts, boolean filled) {
59 this(f);
60 initialize(xmin, xmax, numpts, filled);
61 }
62
63 /**
64 * Evaluates the function.
65 * @param x
66 * @return value of the function
67 */
68 @Override
69 public double evaluate(double x) {
70 return function.evaluate(x);
71 }
72
73 /**
74 * Initialize the function range and the number of display points.
75 * @param xmin the beginning value of the range.
76 * @param xmax the ending value for the range
77 * @param numpts the number of points to display
78 * @param filled fills the area under the curve with the drawing color when true
79 */
80 public void initialize(double xmin, double xmax, int numpts, boolean filled) {
81 if(numpts<1) {
82 return;
83 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected