com.meltingice.caman.util
Class Bezier

java.lang.Object
  extended by com.meltingice.caman.util.Bezier

public class Bezier
extends java.lang.Object

Class for generating a Bezier curve that can be queried by X coordinate to return a Y coordinate. For CamanJ, the X coordinate is the input color, and the Y coordinate is the output color. It helps to think of Photoshop's curves functionality when thinking about Bezier curves. While that uses a different curves equation, the idea is very similar. It generates the curve by running a certain number of iterations from the start coordinate to the end coordinate. For edge cases where certain X coordinates aren't defined, it uses linear interpolation to approximate what the value should be. Usually this approximation is very accurate.

Version:
1.0
Author:
Ryan LeFevre

Constructor Summary
Bezier(int[] start, int[] ctrl1, int[] ctrl2, int[] end)
          Create a new Bezier curve with the given points.
Bezier(int[] start, int[] ctrl1, int[] ctrl2, int[] end, int lowBound, int highBound)
          Create a new Bezier curve with the given points and bounds.
 
Method Summary
 void fillEnds(int s, int e)
          Fills the edges of the bezier curve out to a certain start and end point.
 int query(int x)
          Lets you query the Bezier curve to convert an X input into a Y output value.
 void setIterations(int iter)
          Sets the number of iterations to run between the start and end coordinates.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Bezier

public Bezier(int[] start,
              int[] ctrl1,
              int[] ctrl2,
              int[] end,
              int lowBound,
              int highBound)
Create a new Bezier curve with the given points and bounds.

Parameters:
start - The start x,y coords
ctrl1 - The control point 1 x,y coords
ctrl2 - The control point 2 x,y coords
end - The end x,y coords
lowBound - The low bound of the Y values in the Bezier curve
highBound - The high bound of the Y values in the Bezier curve

Bezier

public Bezier(int[] start,
              int[] ctrl1,
              int[] ctrl2,
              int[] end)
Create a new Bezier curve with the given points. This sets the low and high bound to 0 and 255, respectively.

Parameters:
start - The start x,y coords
ctrl1 - The control point 1 x,y coords
ctrl2 - The control point 2 x,y coords
end - The end x,y coords
Method Detail

setIterations

public void setIterations(int iter)
Sets the number of iterations to run between the start and end coordinates. The default is normally ok, but if you have a very extreme bezier curve, you may need to increase the number of iterations for more accurate results.

Parameters:
iter - The number of iterations

fillEnds

public void fillEnds(int s,
                     int e)
Fills the edges of the bezier curve out to a certain start and end point. This is used to ensure that all values between the start and end values are accounted for.

Parameters:
s -
e -

query

public int query(int x)
Lets you query the Bezier curve to convert an X input into a Y output value.

Parameters:
x - The input color
Returns:
The output color based on the curve.