Package edu.hws.jcm.draw
Class RiemannSumRects
java.lang.Object
edu.hws.jcm.draw.Drawable
edu.hws.jcm.draw.RiemannSumRects
- All Implemented Interfaces:
Computable
,Serializable
A RiemannSumRects calculates a Riemann sum for a function. It implements
Computable and InputObject. You can specify and change the number of
intervals in the sum, as well as the method used to calculate the sum.
Functions exist to return Value objects for the sum using different
computations. This class was written by Gabriel Weinstock, with some
modifications by David Eck
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Summation method type.static final int
For use in getValueObject(), to indicate whatever summation method is currently set for drawing.static final int
Summation method type.static final int
Summation method type.static final int
Summation method type.static final int
Summation method type.static final int
Summation method type. -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a RiemannSumRects object that initially has nothing to draw and that is set up to use the default number of intervals, 5.RiemannSumRects
(Function f, Value i) Construct a new RiemannSumRects object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
compute()
This is generally called by a Controller.void
Draw the Rieman sum rects.getColor()
Get the current color used to draw the rectanglesReturns the function whose Riemann sums are computed.Get the number of intervals used.int
Return the current method used to find the rectangle sumsGet the color that is used to draw outlines around the rects.getValueObject
(int which) Gets a Value object that gives the value of the Riemann sum for the specified method.void
Set the color used to draw the rectangles.void
setFunction
(Function func) Set the function whose Riemann sums are to be computed.void
Set the interval count (the RiemannSumRects will be redrawn after this function is called).void
setMethod
(int m) Set the method used to calculate the rectangles.void
Set the color that will be used to draw outlines around the rects.Methods inherited from class edu.hws.jcm.draw.Drawable
getVisible, needsRedraw, setOwnerData, setVisible
-
Field Details
-
LEFTENDPOINT
public static final int LEFTENDPOINTSummation method type.- See Also:
-
RIGHTENDPOINT
public static final int RIGHTENDPOINTSummation method type.- See Also:
-
MIDPOINT
public static final int MIDPOINTSummation method type.- See Also:
-
CIRCUMSCRIBED
public static final int CIRCUMSCRIBEDSummation method type.- See Also:
-
INSCRIBED
public static final int INSCRIBEDSummation method type.- See Also:
-
TRAPEZOID
public static final int TRAPEZOIDSummation method type.- See Also:
-
CURRENT_METHOD
public static final int CURRENT_METHODFor use in getValueObject(), to indicate whatever summation method is currently set for drawing.- See Also:
-
-
Constructor Details
-
RiemannSumRects
public RiemannSumRects()Construct a RiemannSumRects object that initially has nothing to draw and that is set up to use the default number of intervals, 5. -
RiemannSumRects
Construct a new RiemannSumRects object.- Parameters:
f
- a Function object used to derive the Riemann sum. If null, nothing is drawn.i
- a Value object representing the number of intervals. If null, five intervals are used.
-
-
Method Details
-
getColor
Get the current color used to draw the rectangles -
setColor
Set the color used to draw the rectangles. The default color is a light yellow. -
setOutlineColor
Set the color that will be used to draw outlines around the rects. If this is null, then no outlines are drawn. The default is a medium-dark red that looks brownish next to the default yellow fill color. -
getOutlineColor
Get the color that is used to draw outlines around the rects. If this is null, then no outlines are drawn. -
setFunction
Set the function whose Riemann sums are to be computed. If null, nothing is drawn. The function, if non-null, must have arity 1, or an IllegalArgumentException is thrown. -
getFuction
Returns the function whose Riemann sums are computed. Can be null. -
setMethod
public void setMethod(int m) Set the method used to calculate the rectangles.- Parameters:
m
- can be: LEFTENDPOINT, RIGHTENDPOINT, MIDPOINT, CIRCUMSCRIBED, INSCRIBED or TRAPEZOID (these are integers ranging from 0 to 5, respectively)
-
getMethod
public int getMethod()Return the current method used to find the rectangle sums -
compute
public void compute()This is generally called by a Controller. Indicates that all data should be recomputed because input values that the data depends on might have changed.- Specified by:
compute
in interfaceComputable
-
getIntervalCount
Get the number of intervals used.- Returns:
- a Value object representing the number of intervals
-
setIntervalCount
Set the interval count (the RiemannSumRects will be redrawn after this function is called). The value will be clamped to be a value between 1 and 5000. If the value is null, the default number of intervals, five, is used.- Parameters:
c
- a Value object representing the interval count
-
draw
Draw the Rieman sum rects. This is generally called by an object of class CoordinateRect- Specified by:
draw
in classDrawable
- Parameters:
g
- The graphics context in which the Drawble is to be drawn. (The drawing can change the color in g, but should not permanently change font, painting mode, etc. Thus, every drawable is responsible for setting the color it wants to use.)coordsChanged
- Indicates whether the CoordinateRect has changed.
-
getValueObject
Gets a Value object that gives the value of the Riemann sum for the specified method.- Parameters:
which
- integer stating the method used to derive the sum; one of the constants LEFTENDPOINT, RIGHTENDPOINT, MIDPOINT, CIRCUMSCRIBED, INSCRIBED, TRAPEZOID, or CURRENT_METHOD.- Returns:
- a Value object representing the sum for the given method
-