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`

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 final int`
`CIRCUMSCRIBED`
Summation method type.
`static final int`
`CURRENT_METHOD`
For use in getValueObject(), to indicate whatever summation method is currently set for drawing.
`static final int`
`INSCRIBED`
Summation method type.
`static final int`
`LEFTENDPOINT`
Summation method type.
`static final int`
`MIDPOINT`
Summation method type.
`static final int`
`RIGHTENDPOINT`
Summation method type.
`static final int`
`TRAPEZOID`
Summation method type.

### Fields inherited from class edu.hws.jcm.draw.Drawable

`canvas, coords`

## 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

Modifier and Type
Method
Description
`void`
`compute()`
This is generally called by a Controller.
`void`
`draw(Graphics g, boolean coordsChanged)`
Draw the Rieman sum rects.
`Color`
`getColor()`
Get the current color used to draw the rectangles
`Function`
`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 sums
`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(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(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`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### 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

## 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

public RiemannSumRects(Function f, Value i)
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

public Color getColor()
Get the current color used to draw the rectangles

### setColor

public void setColor(Color c)
Set the color used to draw the rectangles. The default color is a light yellow.

### setOutlineColor

public void setOutlineColor(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 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 interface `Computable`

### 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(Graphics g, boolean coordsChanged)
Draw the Rieman sum rects. This is generally called by an object of class CoordinateRect

Specified by:
  `draw` in class `Drawable`
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