Package edu.hws.jcm.draw
Class RiemannSumRects
- java.lang.Object
-
- edu.hws.jcm.draw.Drawable
-
- edu.hws.jcm.draw.RiemannSumRects
-
- All Implemented Interfaces:
Computable
,java.io.Serializable
public class RiemannSumRects extends Drawable implements Computable
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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static int
CIRCUMSCRIBED
Summation method type.static int
CURRENT_METHOD
For use in getValueObject(), to indicate whatever summation method is currently set for drawing.static int
INSCRIBED
Summation method type.static int
LEFTENDPOINT
Summation method type.static int
MIDPOINT
Summation method type.static int
RIGHTENDPOINT
Summation method type.static int
TRAPEZOID
Summation method type.
-
Constructor Summary
Constructors Constructor Description 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(Function f, Value i)
Construct a new RiemannSumRects object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
compute()
This is generally called by a Controller.void
draw(java.awt.Graphics g, boolean coordsChanged)
Draw the Rieman sum rects.java.awt.Color
getColor()
Get the current color used to draw the rectanglesFunction
getFuction()
Returns the function whose Riemann sums are computed.Value
getIntervalCount()
Get the number of intervals used.int
getMethod()
Return the current method used to find the rectangle sumsjava.awt.Color
getOutlineColor()
Get the color that is used to draw outlines around the rects.Value
getValueObject(int which)
Gets a Value object that gives the value of the Riemann sum for the specified method.void
setColor(java.awt.Color c)
Set the color used to draw the rectangles.void
setFunction(Function func)
Set the function whose Riemann sums are to be computed.void
setIntervalCount(Value c)
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
setOutlineColor(java.awt.Color c)
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 Detail
-
LEFTENDPOINT
public static final int LEFTENDPOINT
Summation method type.- See Also:
- Constant Field Values
-
RIGHTENDPOINT
public static final int RIGHTENDPOINT
Summation method type.- See Also:
- Constant Field Values
-
MIDPOINT
public static final int MIDPOINT
Summation method type.- See Also:
- Constant Field Values
-
CIRCUMSCRIBED
public static final int CIRCUMSCRIBED
Summation method type.- See Also:
- Constant Field Values
-
INSCRIBED
public static final int INSCRIBED
Summation method type.- See Also:
- Constant Field Values
-
TRAPEZOID
public static final int TRAPEZOID
Summation method type.- See Also:
- Constant Field Values
-
CURRENT_METHOD
public static final int CURRENT_METHOD
For use in getValueObject(), to indicate whatever summation method is currently set for drawing.- See Also:
- Constant Field Values
-
-
Method Detail
-
getColor
public java.awt.Color getColor()
Get the current color used to draw the rectangles
-
setColor
public void setColor(java.awt.Color c)
Set the color used to draw the rectangles. The default color is a light yellow.
-
setOutlineColor
public void setOutlineColor(java.awt.Color c)
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
public java.awt.Color getOutlineColor()
Get the color that is used to draw outlines around the rects. If this is null, then no outlines are drawn.
-
setFunction
public void setFunction(Function func)
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
public Function 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
public Value getIntervalCount()
Get the number of intervals used.- Returns:
- a Value object representing the number of intervals
-
setIntervalCount
public void setIntervalCount(Value c)
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
public void draw(java.awt.Graphics g, boolean coordsChanged)
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
public Value getValueObject(int which)
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
-
-