From fc43b19db0bb4b6b18845018d2542fdb6171bfc9 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Sun, 8 Jul 2018 18:40:49 -0400 Subject: [PATCH] [fix] clicking away from points now longer causes an exception --- .../openrocket/rocketcomponent/FreeformFinSet.java | 3 ++- .../gui/configdialog/FreeformFinSetConfig.java | 8 ++++++-- .../openrocket/gui/scalefigure/FinPointFigure.java | 12 +++++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/FreeformFinSet.java b/core/src/net/sf/openrocket/rocketcomponent/FreeformFinSet.java index 8924eb3ba..468cca53a 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FreeformFinSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FreeformFinSet.java @@ -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 diff --git a/swing/src/net/sf/openrocket/gui/configdialog/FreeformFinSetConfig.java b/swing/src/net/sf/openrocket/gui/configdialog/FreeformFinSetConfig.java index 2cc516af2..d288935e9 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/FreeformFinSetConfig.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/FreeformFinSetConfig.java @@ -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; diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/FinPointFigure.java b/swing/src/net/sf/openrocket/gui/scalefigure/FinPointFigure.java index db03dd446..1eebd5b67 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/FinPointFigure.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/FinPointFigure.java @@ -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; }