Merge pull request #1862 from SiboVG/issue-1655
[#1655] Use minimum mount bounds for fin set editor origin updating
This commit is contained in:
commit
f66c8305a3
@ -5,8 +5,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
public class BoundingBox {
|
public class BoundingBox {
|
||||||
public Coordinate min;
|
public Coordinate min; // Top-left coordinate of the bounding box
|
||||||
public Coordinate max;
|
public Coordinate max; // Bottom-right coordinate of the bounding box
|
||||||
|
|
||||||
public BoundingBox() {
|
public BoundingBox() {
|
||||||
clear();
|
clear();
|
||||||
@ -158,7 +158,7 @@ public class BoundingBox {
|
|||||||
public Rectangle2D toRectangle() {
|
public Rectangle2D toRectangle() {
|
||||||
return new Rectangle2D.Double(min.x, min.y, (max.x-min.x), (max.y - min.y));
|
return new Rectangle2D.Double(min.x, min.y, (max.x-min.x), (max.y - min.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("[( %g, %g, %g) < ( %g, %g, %g)]",
|
return String.format("[( %g, %g, %g) < ( %g, %g, %g)]",
|
||||||
|
@ -37,7 +37,7 @@ public abstract class AbstractScaleFigure extends JPanel {
|
|||||||
protected double userScale = 1.0;
|
protected double userScale = 1.0;
|
||||||
protected double scale = -1;
|
protected double scale = -1;
|
||||||
|
|
||||||
// pixel offset from the the subject's origin to the canvas's upper-left-corner.
|
// pixel offset from the subject's origin to the canvas's upper-left-corner.
|
||||||
protected Point originLocation_px = new Point(0,0);
|
protected Point originLocation_px = new Point(0,0);
|
||||||
|
|
||||||
// size of the visible region
|
// size of the visible region
|
||||||
|
@ -54,7 +54,9 @@ public class FinPointFigure extends AbstractScaleFigure {
|
|||||||
private int modID = -1;
|
private int modID = -1;
|
||||||
|
|
||||||
protected BoundingBox finBounds_m = null;
|
protected BoundingBox finBounds_m = null;
|
||||||
protected BoundingBox mountBounds_m = null;
|
// Fin parent bounds
|
||||||
|
protected BoundingBox mountBoundsMax_m = null; // Bounds using the maximum parent radius
|
||||||
|
protected BoundingBox mountBoundsMin_m = null; // Bound using the minimum parent radius
|
||||||
|
|
||||||
protected final List<StateChangeListener> listeners = new LinkedList<>();
|
protected final List<StateChangeListener> listeners = new LinkedList<>();
|
||||||
|
|
||||||
@ -204,11 +206,11 @@ public class FinPointFigure extends AbstractScaleFigure {
|
|||||||
|
|
||||||
private void paintBodyTube( Graphics2D g2){
|
private void paintBodyTube( Graphics2D g2){
|
||||||
// in-figure left extent
|
// in-figure left extent
|
||||||
final double xFore = mountBounds_m.min.x;
|
final double xFore = mountBoundsMax_m.min.x;
|
||||||
// in-figure right extent
|
// in-figure right extent
|
||||||
final double xAft = mountBounds_m.max.x;
|
final double xAft = mountBoundsMax_m.max.x;
|
||||||
// in-figure right extent
|
// in-figure right extent
|
||||||
final double yCenter = mountBounds_m.min.y;
|
final double yCenter = mountBoundsMax_m.min.y;
|
||||||
|
|
||||||
Path2D.Double shape = new Path2D.Double();
|
Path2D.Double shape = new Path2D.Double();
|
||||||
shape.moveTo( xFore, yCenter );
|
shape.moveTo( xFore, yCenter );
|
||||||
@ -373,33 +375,37 @@ public class FinPointFigure extends AbstractScaleFigure {
|
|||||||
final double xFinFront = finset.getAxialOffset(AxialMethod.TOP);
|
final double xFinFront = finset.getAxialOffset(AxialMethod.TOP);
|
||||||
final double xParent = -xFinFront;
|
final double xParent = -xFinFront;
|
||||||
final double yParent = -parent.getRadius(xParent); // from fin-front to parent centerline
|
final double yParent = -parent.getRadius(xParent); // from fin-front to parent centerline
|
||||||
final double rParent = Math.max(parent.getForeRadius(), parent.getAftRadius());
|
final double rParentMax = Math.max(parent.getForeRadius(), parent.getAftRadius());
|
||||||
|
final double rParentMin = Math.min(parent.getForeRadius(), parent.getAftRadius());
|
||||||
|
|
||||||
mountBounds_m = new BoundingBox()
|
mountBoundsMax_m = new BoundingBox()
|
||||||
.update(new Coordinate(xParent, yParent, 0))
|
.update(new Coordinate(xParent, yParent, 0))
|
||||||
.update(new Coordinate(xParent + parent.getLength(), yParent + rParent));
|
.update(new Coordinate(xParent + parent.getLength(), yParent + rParentMax));
|
||||||
|
mountBoundsMin_m = new BoundingBox()
|
||||||
|
.update(new Coordinate(xParent, yParent, 0))
|
||||||
|
.update(new Coordinate(xParent + parent.getLength(), yParent + rParentMin));
|
||||||
|
|
||||||
final BoundingBox combinedBounds = new BoundingBox().update(finBounds_m).update(mountBounds_m);
|
final BoundingBox combinedBounds = new BoundingBox().update(finBounds_m).update(mountBoundsMax_m);
|
||||||
|
|
||||||
contentBounds_m = combinedBounds.toRectangle();
|
contentBounds_m = combinedBounds.toRectangle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateCanvasOrigin() {
|
protected void updateCanvasOrigin() {
|
||||||
final int finHeightPx = (int)(finBounds_m.max.y*scale);
|
final int finBottomPy = (int)(finBounds_m.max.y*scale);
|
||||||
final int mountHeightPx = (int)(mountBounds_m.span().y*scale);
|
final int mountHeight = (int)(mountBoundsMin_m.span().y*scale);
|
||||||
// this is non-intuitive: it's an offset _from_ the origin(0,0) _to_ the lower-left of the content --
|
// this is non-intuitive: it's an offset _from_ the origin(0,0) _to_ the lower-left of the content --
|
||||||
// because the canvas is drawn from that lower-left corner of the content, and the fin-front
|
// because the canvas is drawn from that lower-left corner of the content, and the fin-front
|
||||||
// is fixed-- by definition-- to the origin.
|
// is fixed-- by definition-- to the origin.
|
||||||
final int finFrontPx = -(int)(contentBounds_m.getX()*scale); // pixels from left-border to fin-front
|
final int finFrontPx = -(int)(contentBounds_m.getX()*scale); // pixels from left-border to fin-front
|
||||||
final int contentHeightPx = (int)(contentBounds_m.getHeight()*scale);
|
final int contentHeight = (int)(contentBounds_m.getHeight()*scale);
|
||||||
|
|
||||||
originLocation_px.x = borderThickness_px.width + finFrontPx;
|
originLocation_px.x = borderThickness_px.width + finFrontPx;
|
||||||
|
|
||||||
if( visibleBounds_px.height > (contentHeightPx + 2*borderThickness_px.height)){
|
if( visibleBounds_px.height > (contentHeight + 2*borderThickness_px.height)){
|
||||||
originLocation_px.y = getHeight() - mountHeightPx - borderThickness_px.height;
|
originLocation_px.y = getHeight() - mountHeight - borderThickness_px.height;
|
||||||
}else {
|
}else {
|
||||||
originLocation_px.y = borderThickness_px.height + finHeightPx;
|
originLocation_px.y = borderThickness_px.height + finBottomPy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user