[fixes #419] Adding new points to FreeformFins are now placed at the mouse cursor
This commit is contained in:
parent
f3dbceba37
commit
e4b6b25a8b
@ -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);
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user