First commit, added all projects
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
package geography;
|
||||
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Path2D;
|
||||
|
||||
/**
|
||||
* A class representing a piecewise linear curve.
|
||||
*/
|
||||
public class PiecewiseLinearCurve extends AbstractGeographicShape
|
||||
{
|
||||
protected Path2D.Double shape;
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* The id of the curve
|
||||
*/
|
||||
public PiecewiseLinearCurve(final String id)
|
||||
{
|
||||
super(id);
|
||||
shape = new Path2D.Double();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* The id of the curve
|
||||
* @param path
|
||||
* The path of the curve
|
||||
*/
|
||||
public PiecewiseLinearCurve(final String id, final Path2D.Double path)
|
||||
{
|
||||
super(id);
|
||||
this.shape = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Shape getShape()
|
||||
{
|
||||
return shape;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param point
|
||||
* The point to add to the curve
|
||||
*/
|
||||
public void add(final double[] point)
|
||||
{
|
||||
if (shape.getCurrentPoint() == null)
|
||||
{
|
||||
shape.moveTo(point[0], point[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
shape.lineTo(point[0], point[1]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param addition
|
||||
* The shape to add to the curve
|
||||
* @param connect
|
||||
* Whether to connect the current curve to the addition with a line segment (if true, the
|
||||
* addition will be connected to the current curve with a line segment; if false, the
|
||||
* addition will be added as a separate shape)
|
||||
*/
|
||||
public void append(final Shape addition, final boolean connect)
|
||||
{
|
||||
if (connect && shape.getCurrentPoint() != null)
|
||||
{
|
||||
shape.lineTo(addition.getBounds2D().getX(), addition.getBounds2D().getY());
|
||||
}
|
||||
shape.append(addition, false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user