[fix] limits a FreeformFinSet maximum size to 2.5m x 2.5m. This prevents a stack-overflow while editing
This commit is contained in:
parent
b960d37a4a
commit
748a871e57
@ -25,6 +25,9 @@ public class FreeformFinSet extends FinSet {
|
|||||||
private static final double SNAP_SMALLER_THAN = 5e-3;
|
private static final double SNAP_SMALLER_THAN = 5e-3;
|
||||||
private static final double IGNORE_SMALLER_THAN = 1e-12;
|
private static final double IGNORE_SMALLER_THAN = 1e-12;
|
||||||
|
|
||||||
|
// attempts to set a fin value any larger than this will be snapped to this max value
|
||||||
|
public static final double SNAP_LARGER_THAN = 2.5; // in meters
|
||||||
|
|
||||||
public FreeformFinSet() {
|
public FreeformFinSet() {
|
||||||
points.add(Coordinate.ZERO);
|
points.add(Coordinate.ZERO);
|
||||||
points.add(new Coordinate(0.025, 0.05));
|
points.add(new Coordinate(0.025, 0.05));
|
||||||
@ -164,6 +167,16 @@ public class FreeformFinSet extends FinSet {
|
|||||||
newPoints = translatePoints( newPoints, delta);
|
newPoints = translatePoints( newPoints, delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for ( int i =0; i < newPoints.size(); ++i ) {
|
||||||
|
final Coordinate p = newPoints.get(i);
|
||||||
|
if( p.x > SNAP_LARGER_THAN){
|
||||||
|
newPoints.set(i, p.setX(SNAP_LARGER_THAN));
|
||||||
|
}
|
||||||
|
if( p.y > SNAP_LARGER_THAN){
|
||||||
|
newPoints.set(i, p.setY(SNAP_LARGER_THAN));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// copy the old points, in case validation fails
|
// copy the old points, in case validation fails
|
||||||
final ArrayList<Coordinate> pointsCopy = new ArrayList<>(this.points);
|
final ArrayList<Coordinate> pointsCopy = new ArrayList<>(this.points);
|
||||||
final double lengthCopy = this.length;
|
final double lengthCopy = this.length;
|
||||||
@ -203,14 +216,39 @@ public class FreeformFinSet extends FinSet {
|
|||||||
* @param yRequest the y-coordinate.
|
* @param yRequest the y-coordinate.
|
||||||
*/
|
*/
|
||||||
public void setPoint(final int index, final double xRequest, final double yRequest) {
|
public void setPoint(final int index, final double xRequest, final double yRequest) {
|
||||||
final Coordinate revertPoint = points.get(index);
|
if(null == this.getParent()) {
|
||||||
if(null != this.getParent()) {
|
return;
|
||||||
final Coordinate prior = points.get(index);
|
}
|
||||||
points.set(index, new Coordinate(xRequest, yRequest));
|
|
||||||
|
|
||||||
if((points.size() - 1) == index){
|
// if the new x,y would cause a fin larger than our max-size, limit the new request:
|
||||||
clampLastPoint(xRequest-prior.x);
|
double xAccept = xRequest;
|
||||||
|
double yAccept = yRequest;
|
||||||
|
if(0 == index) {
|
||||||
|
final Coordinate cl = points.get(points.size() - 1);
|
||||||
|
double newLength = cl.x - xRequest;
|
||||||
|
if (newLength > SNAP_LARGER_THAN) {
|
||||||
|
xAccept = SNAP_LARGER_THAN - cl.x;
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
if (xAccept > SNAP_LARGER_THAN) {
|
||||||
|
xAccept = SNAP_LARGER_THAN;
|
||||||
|
}
|
||||||
|
if (yAccept > SNAP_LARGER_THAN) {
|
||||||
|
yAccept = SNAP_LARGER_THAN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final Coordinate revertPoint = points.get(index);
|
||||||
|
|
||||||
|
points.set(index, new Coordinate(xAccept, yAccept));
|
||||||
|
|
||||||
|
if( IGNORE_SMALLER_THAN > Math.abs(revertPoint.x - xAccept) && IGNORE_SMALLER_THAN > Math.abs(revertPoint.y - yAccept) ){
|
||||||
|
// no-op. ignore
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((points.size() - 1) == index) {
|
||||||
|
clampLastPoint(xAccept - revertPoint.x);
|
||||||
}
|
}
|
||||||
|
|
||||||
update();
|
update();
|
||||||
|
@ -347,7 +347,9 @@ public class FinPointFigure extends AbstractScaleFigure {
|
|||||||
return new Point2D.Double(0, 0);
|
return new Point2D.Double(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
p.setLocation(p.x, p.y);
|
p.x = MathUtil.clamp(p.x, -FreeformFinSet.SNAP_LARGER_THAN, FreeformFinSet.SNAP_LARGER_THAN);
|
||||||
|
p.y = MathUtil.clamp(p.y, -FreeformFinSet.SNAP_LARGER_THAN, FreeformFinSet.SNAP_LARGER_THAN);
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user