[fix] clicking away from points now longer causes an exception

This commit is contained in:
Daniel_M_Williams 2018-07-08 18:40:49 -04:00
parent 80c0fa8568
commit fc43b19db0
3 changed files with 15 additions and 8 deletions

View File

@ -215,7 +215,8 @@ public class FreeformFinSet extends FinSet {
y0 = Double.NaN;
x1 = points.get(1).x;
y1 = points.get(1).y;
// } else if ( (0 > index) || (points.size() <= index) ){
// throw new IllegalFinPointException("Point Index not available!");
} else if (index == points.size() - 1) {
// Restrict point

View File

@ -381,13 +381,15 @@ public class FreeformFinSetConfig extends FinSetConfig {
return;
}
int pointIndex = getPoint(event);
final int pointIndex = getPoint(event);
if ( pointIndex >= 0) {
dragIndex = pointIndex;
return;
}
int segmentIndex = getSegment(event);
final int segmentIndex = getSegment(event);
System.err.println(String.format(".... finpoint//segmentIndex: %d", segmentIndex));
if (segmentIndex >= 0) {
Point2D.Double point = getCoordinates(event);
finset.addPoint(segmentIndex );
@ -396,6 +398,8 @@ public class FreeformFinSetConfig extends FinSetConfig {
finset.setPoint(dragIndex, point.x, point.y);
} catch (IllegalFinPointException ignore) {
// no-op
} catch (ArrayIndexOutOfBoundsException ex) {
log.error("bad index while editing fin points!!", ex);
}
dragIndex = segmentIndex;

View File

@ -274,10 +274,10 @@ public class FinPointFigure extends AbstractScaleFigure {
double x0 = p.x;
double y0 = p.y;
double delta = BOX_WIDTH_PIXELS /*/ scale*/;
double delta = BOX_WIDTH_PIXELS / scale;
//System.out.println("Point: " + x0 + "," + y0);
//System.out.println("delta: " + (BOX_SIZE / scale));
//System.err.println(String.format("__Point: x=%.4f, y=%.4f", x0, y0));
//System.err.println(String.format("__delta: %.4f", BOX_WIDTH_PIXELS / scale));
Coordinate[] points = finset.getFinPoints();
for (int i = 1; i < points.length; i++) {
@ -286,11 +286,13 @@ public class FinPointFigure extends AbstractScaleFigure {
double x2 = points[i].x;
double y2 = points[i].y;
// System.out.println("point1:"+x1+","+y1+" point2:"+x2+","+y2);
//System.out.println("point1:"+x1+","+y1+" point2:"+x2+","+y2);
double u = Math.abs((x2 - x1) * (y1 - y0) - (x1 - x0) * (y2 - y1)) /
MathUtil.hypot(x2 - x1, y2 - y1);
//System.out.println("Distance of segment " + i + " is " + u);
//System.err.println("Distance of segment " + i + " is " + u);
if (u < delta)
return i;
}