First commit, added all projects
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package gui;
|
||||
|
||||
import java.awt.geom.Line2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A simple implementation of the DigitizerDocument interface that can be used to test the
|
||||
* DigitizerPanel.
|
||||
*/
|
||||
public class DisplayDigitizerDocument implements DigitizerDocument
|
||||
{
|
||||
protected DigitizerPanel panel;
|
||||
protected List<Line2D.Double> lines = new ArrayList<Line2D.Double>();
|
||||
|
||||
/**
|
||||
* @param panel
|
||||
*/
|
||||
public DisplayDigitizerDocument(final DigitizerPanel panel)
|
||||
{
|
||||
this.panel = panel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLine(final double[] start, final double[] stop)
|
||||
{
|
||||
Line2D.Double line = new Line2D.Double(start[0], start[1], stop[0], stop[1]);
|
||||
lines.add(line);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Line2D getClosest(final double[] point)
|
||||
{
|
||||
Line2D closest = null;
|
||||
double closestDistance = Double.MAX_VALUE;
|
||||
for (Line2D line : lines)
|
||||
{
|
||||
double distance = line.ptSegDist(point[0], point[1]);
|
||||
if (distance < closestDistance)
|
||||
{
|
||||
closest = line;
|
||||
closestDistance = distance;
|
||||
}
|
||||
}
|
||||
return closest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Line2D.Double> getLines()
|
||||
{
|
||||
return lines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLine(final Line2D line)
|
||||
{
|
||||
lines.remove(line);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user