diff --git a/core/src/net/sf/openrocket/rocketcomponent/FreeformFinSet.java b/core/src/net/sf/openrocket/rocketcomponent/FreeformFinSet.java index 468cca53a..36dfc59ab 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FreeformFinSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FreeformFinSet.java @@ -1,5 +1,6 @@ package net.sf.openrocket.rocketcomponent; +import java.awt.geom.Point2D; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -128,16 +129,12 @@ public class FreeformFinSet extends FinSet { * The point is placed at the midpoint of the current segment. * * @param index the fin point before which to add the new point. + * @param point the target location to create the new point at */ - public void addPoint(int index) { - double x0, y0, x1, y1; - - x0 = points.get(index - 1).x; - y0 = points.get(index - 1).y; - x1 = points.get(index).x; - y1 = points.get(index).y; - - points.add(index, new Coordinate((x0 + x1) / 2, (y0 + y1) / 2)); + public void addPoint(int index, Point2D.Double location) { + // new method: add new point at closest point + points.add(index, new Coordinate(location.x, location.y)); + // adding a point within the segment affects neither mass nor aerodynamics fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE); } diff --git a/core/test/net/sf/openrocket/rocketcomponent/FreeformFinSetTest.java b/core/test/net/sf/openrocket/rocketcomponent/FreeformFinSetTest.java index 7df8e3039..803feb4f5 100644 --- a/core/test/net/sf/openrocket/rocketcomponent/FreeformFinSetTest.java +++ b/core/test/net/sf/openrocket/rocketcomponent/FreeformFinSetTest.java @@ -94,6 +94,33 @@ public class FreeformFinSetTest extends BaseTestCase { assertEquals(0.3889, coords.x, 0.001); assertEquals(0.4444, coords.y, 0.001); } + + @Test + public void testFreeformFinAddPoint() throws Exception { + FreeformFinSet fin = new FreeformFinSet(); + fin.setFinCount(1); + fin.setFinCount(1); + Coordinate[] points = new Coordinate[] { + new Coordinate(0, 0), + new Coordinate(0.5, 1.0), + new Coordinate(1.0, 1.0), + new Coordinate(1, 0) + }; + fin.setPoints(points); + assertEquals(4, fin.getPointCount()); + + // +--+ + // / |x + // / | + // +=====+ + Point2D.Double toAdd = new Point2D.Double(1.01, 0.8); + fin.addPoint(3, toAdd); + + assertEquals(5, fin.getPointCount()); + final Coordinate added = fin.getFinPoints()[3]; + assertEquals(1.1,added.x, 0.1); + assertEquals(0.8, added.y, 0.1); + } @Test public void testWildmanVindicatorShape() throws Exception { diff --git a/swing/src/net/sf/openrocket/gui/configdialog/FreeformFinSetConfig.java b/swing/src/net/sf/openrocket/gui/configdialog/FreeformFinSetConfig.java index 110c9d910..cd0fe53f5 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/FreeformFinSetConfig.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/FreeformFinSetConfig.java @@ -407,7 +407,7 @@ public class FreeformFinSetConfig extends FinSetConfig { final int segmentIndex = getSegment(event); if (segmentIndex >= 0) { Point2D.Double point = getCoordinates(event); - finset.addPoint(segmentIndex ); + finset.addPoint(segmentIndex, point); try { finset.setPoint(dragIndex, point.x, point.y);