[whitespace] harmonized mixed spaces + tabs => tabs
This commit is contained in:
parent
45fdb55dc4
commit
3d9938640f
@ -33,34 +33,34 @@ import net.sf.openrocket.util.StateChangeListener;
|
|||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class FinPointFigure extends AbstractScaleFigure {
|
public class FinPointFigure extends AbstractScaleFigure {
|
||||||
|
|
||||||
//private final static Logger log = LoggerFactory.getLogger(FinPointFigure.class);
|
//private final static Logger log = LoggerFactory.getLogger(FinPointFigure.class);
|
||||||
|
|
||||||
private static final Color GRID_MAJOR_LINE_COLOR = new Color( 64, 64, 128, 128);
|
private static final Color GRID_MAJOR_LINE_COLOR = new Color( 64, 64, 128, 128);
|
||||||
private static final Color GRID_MINOR_LINE_COLOR = new Color( 64, 64, 128, 32);
|
private static final Color GRID_MINOR_LINE_COLOR = new Color( 64, 64, 128, 32);
|
||||||
private static final int GRID_LINE_BASE_WIDTH_PIXELS = 1;
|
private static final int GRID_LINE_BASE_WIDTH_PIXELS = 1;
|
||||||
|
|
||||||
private static final int LINE_WIDTH_FIN_PIXELS = 1;
|
private static final int LINE_WIDTH_FIN_PIXELS = 1;
|
||||||
private static final int LINE_WIDTH_BODY_PIXELS = 2;
|
private static final int LINE_WIDTH_BODY_PIXELS = 2;
|
||||||
|
|
||||||
// the size of the boxes around each fin point vertex
|
// the size of the boxes around each fin point vertex
|
||||||
private static final int LINE_WIDTH_BOX_PIXELS = 1;
|
private static final int LINE_WIDTH_BOX_PIXELS = 1;
|
||||||
private static final float BOX_WIDTH_PIXELS = 12;
|
private static final float BOX_WIDTH_PIXELS = 12;
|
||||||
private static final float SELECTED_BOX_WIDTH_PIXELS = BOX_WIDTH_PIXELS + 4;
|
private static final float SELECTED_BOX_WIDTH_PIXELS = BOX_WIDTH_PIXELS + 4;
|
||||||
private static final Color POINT_COLOR = new Color(100, 100, 100);
|
private static final Color POINT_COLOR = new Color(100, 100, 100);
|
||||||
private static final Color SELECTED_POINT_COLOR = new Color(200, 0, 0);
|
private static final Color SELECTED_POINT_COLOR = new Color(200, 0, 0);
|
||||||
private static final double MINOR_TICKS = 0.01;
|
private static final double MINOR_TICKS = 0.01;
|
||||||
private static final double MAJOR_TICKS = 0.1;
|
private static final double MAJOR_TICKS = 0.1;
|
||||||
|
|
||||||
private final FreeformFinSet finset;
|
private final FreeformFinSet finset;
|
||||||
private int modID = -1;
|
private int modID = -1;
|
||||||
|
|
||||||
protected Rectangle2D finBounds_m = null;
|
protected Rectangle2D finBounds_m = null;
|
||||||
protected Rectangle2D mountBounds_m = null;
|
protected Rectangle2D mountBounds_m = null;
|
||||||
|
|
||||||
protected final List<StateChangeListener> listeners = new LinkedList<StateChangeListener>();
|
protected final List<StateChangeListener> listeners = new LinkedList<StateChangeListener>();
|
||||||
|
|
||||||
private Rectangle2D.Double[] finPointHandles = null;
|
private Rectangle2D.Double[] finPointHandles = null;
|
||||||
private int selectedIndex = -1;
|
private int selectedIndex = -1;
|
||||||
|
|
||||||
public FinPointFigure(FreeformFinSet finset) {
|
public FinPointFigure(FreeformFinSet finset) {
|
||||||
this.finset = finset;
|
this.finset = finset;
|
||||||
@ -75,13 +75,13 @@ public class FinPointFigure extends AbstractScaleFigure {
|
|||||||
@Override
|
@Override
|
||||||
public void paintComponent(Graphics g) {
|
public void paintComponent(Graphics g) {
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
Graphics2D g2 = (Graphics2D) g.create();
|
Graphics2D g2 = (Graphics2D) g.create();
|
||||||
|
|
||||||
if (modID != finset.getRocket().getAerodynamicModID()) {
|
if (modID != finset.getRocket().getAerodynamicModID()) {
|
||||||
modID = finset.getRocket().getAerodynamicModID();
|
modID = finset.getRocket().getAerodynamicModID();
|
||||||
updateTransform();
|
updateTransform();
|
||||||
}
|
}
|
||||||
|
|
||||||
g2.transform(projection);
|
g2.transform(projection);
|
||||||
|
|
||||||
// Set rendering hints appropriately
|
// Set rendering hints appropriately
|
||||||
@ -97,212 +97,212 @@ public class FinPointFigure extends AbstractScaleFigure {
|
|||||||
paintRocketBody(g2);
|
paintRocketBody(g2);
|
||||||
|
|
||||||
paintFinShape(g2);
|
paintFinShape(g2);
|
||||||
paintFinHandles(g2);
|
paintFinHandles(g2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paintBackgroundGrid( Graphics2D g2) {
|
public void paintBackgroundGrid( Graphics2D g2) {
|
||||||
Rectangle visible = g2.getClipBounds();
|
Rectangle visible = g2.getClipBounds();
|
||||||
final double x0 = visible.x - 3;
|
final double x0 = visible.x - 3;
|
||||||
final double x1 = visible.x + visible.width + 4;
|
final double x1 = visible.x + visible.width + 4;
|
||||||
final double y0 = visible.y - 3;
|
final double y0 = visible.y - 3;
|
||||||
final double y1 = visible.y + visible.height + 4;
|
final double y1 = visible.y + visible.height + 4;
|
||||||
|
|
||||||
final float grid_line_width = (float)(GRID_LINE_BASE_WIDTH_PIXELS/this.scale);
|
final float grid_line_width = (float)(GRID_LINE_BASE_WIDTH_PIXELS/this.scale);
|
||||||
g2.setStroke(new BasicStroke( grid_line_width,
|
g2.setStroke(new BasicStroke( grid_line_width,
|
||||||
BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
|
BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
|
||||||
|
|
||||||
Unit unit;
|
Unit unit;
|
||||||
if (this.getParent() != null && this.getParent().getParent() instanceof ScaleScrollPane) {
|
if (this.getParent() != null && this.getParent().getParent() instanceof ScaleScrollPane) {
|
||||||
unit = ((ScaleScrollPane) this.getParent().getParent()).getCurrentUnit();
|
unit = ((ScaleScrollPane) this.getParent().getParent()).getCurrentUnit();
|
||||||
} else {
|
} else {
|
||||||
unit = UnitGroup.UNITS_LENGTH.getDefaultUnit();
|
unit = UnitGroup.UNITS_LENGTH.getDefaultUnit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// vertical
|
// vertical
|
||||||
Tick[] verticalTicks = unit.getTicks(x0, x1, MINOR_TICKS, MAJOR_TICKS);
|
Tick[] verticalTicks = unit.getTicks(x0, x1, MINOR_TICKS, MAJOR_TICKS);
|
||||||
Line2D.Double line = new Line2D.Double();
|
Line2D.Double line = new Line2D.Double();
|
||||||
for (Tick t : verticalTicks) {
|
for (Tick t : verticalTicks) {
|
||||||
if (t.major) {
|
if (t.major) {
|
||||||
g2.setColor(FinPointFigure.GRID_MAJOR_LINE_COLOR);
|
g2.setColor(FinPointFigure.GRID_MAJOR_LINE_COLOR);
|
||||||
line.setLine( t.value, y0, t.value, y1);
|
line.setLine( t.value, y0, t.value, y1);
|
||||||
g2.draw(line);
|
g2.draw(line);
|
||||||
}else{
|
}else{
|
||||||
g2.setColor(FinPointFigure.GRID_MINOR_LINE_COLOR);
|
g2.setColor(FinPointFigure.GRID_MINOR_LINE_COLOR);
|
||||||
line.setLine( t.value, y0, t.value, y1);
|
line.setLine( t.value, y0, t.value, y1);
|
||||||
g2.draw(line);
|
g2.draw(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// horizontal
|
// horizontal
|
||||||
Tick[] horizontalTicks = unit.getTicks(y0, y1, MINOR_TICKS, MAJOR_TICKS);
|
Tick[] horizontalTicks = unit.getTicks(y0, y1, MINOR_TICKS, MAJOR_TICKS);
|
||||||
for (Tick t : horizontalTicks) {
|
for (Tick t : horizontalTicks) {
|
||||||
if (t.major) {
|
if (t.major) {
|
||||||
g2.setColor(FinPointFigure.GRID_MAJOR_LINE_COLOR);
|
g2.setColor(FinPointFigure.GRID_MAJOR_LINE_COLOR);
|
||||||
line.setLine( x0, t.value, x1, t.value);
|
line.setLine( x0, t.value, x1, t.value);
|
||||||
g2.draw(line);
|
g2.draw(line);
|
||||||
}else{
|
}else{
|
||||||
g2.setColor(FinPointFigure.GRID_MINOR_LINE_COLOR);
|
g2.setColor(FinPointFigure.GRID_MINOR_LINE_COLOR);
|
||||||
line.setLine( x0, t.value, x1, t.value);
|
line.setLine( x0, t.value, x1, t.value);
|
||||||
g2.draw(line);
|
g2.draw(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void paintRocketBody( Graphics2D g2){
|
private void paintRocketBody( Graphics2D g2){
|
||||||
RocketComponent comp = finset.getParent();
|
RocketComponent comp = finset.getParent();
|
||||||
if( comp instanceof Transition ){
|
if( comp instanceof Transition ){
|
||||||
paintBodyTransition(g2);
|
paintBodyTransition(g2);
|
||||||
}else{
|
}else{
|
||||||
paintBodyTube(g2);
|
paintBodyTube(g2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: This function drawns relative to the reference point of the BODY component
|
// NOTE: This function drawns relative to the reference point of the BODY component
|
||||||
// In other words: 0,0 == the front, foreRadius of the body component
|
// In other words: 0,0 == the front, foreRadius of the body component
|
||||||
private void paintBodyTransition( Graphics2D g2){
|
private void paintBodyTransition( Graphics2D g2){
|
||||||
|
|
||||||
// setup lines
|
|
||||||
final float bodyLineWidth = (float) ( LINE_WIDTH_BODY_PIXELS / scale );
|
|
||||||
g2.setStroke(new BasicStroke( bodyLineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
|
|
||||||
g2.setColor(Color.BLACK);
|
|
||||||
|
|
||||||
Transition body = (Transition) finset.getParent();
|
// setup lines
|
||||||
final float xResolution_m = 0.01f; // distance between draw points, in meters
|
final float bodyLineWidth = (float) ( LINE_WIDTH_BODY_PIXELS / scale );
|
||||||
|
g2.setStroke(new BasicStroke( bodyLineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
|
||||||
|
g2.setColor(Color.BLACK);
|
||||||
|
|
||||||
final double xFinStart = finset.getAxialOffset(AxialMethod.TOP); //<< in body frame
|
Transition body = (Transition) finset.getParent();
|
||||||
|
final float xResolution_m = 0.01f; // distance between draw points, in meters
|
||||||
|
|
||||||
// vv in fin-frame == draw-frame vv
|
final double xFinStart = finset.getAxialOffset(AxialMethod.TOP); //<< in body frame
|
||||||
final double xOffset = -xFinStart;
|
|
||||||
final double yOffset = -body.getRadius(xFinStart);
|
|
||||||
|
|
||||||
Path2D.Double bodyShape = new Path2D.Double();
|
// vv in fin-frame == draw-frame vv
|
||||||
// draw front-cap:
|
final double xOffset = -xFinStart;
|
||||||
bodyShape.moveTo( xOffset, yOffset);
|
final double yOffset = -body.getRadius(xFinStart);
|
||||||
bodyShape.lineTo( xOffset, yOffset + body.getForeRadius());
|
|
||||||
|
|
||||||
final float length_m = (float)( body.getLength());
|
Path2D.Double bodyShape = new Path2D.Double();
|
||||||
Point2D.Double cur = new Point2D.Double ();
|
// draw front-cap:
|
||||||
for( double xBody = xResolution_m ; xBody < length_m; xBody += xResolution_m ){
|
bodyShape.moveTo( xOffset, yOffset);
|
||||||
// xBody is distance from front of parent body
|
bodyShape.lineTo( xOffset, yOffset + body.getForeRadius());
|
||||||
cur.x = xOffset + xBody; // offset from origin (front of fin)
|
|
||||||
cur.y = yOffset + body.getRadius( xBody); // offset from origin ( fin-front-point )
|
|
||||||
|
|
||||||
bodyShape.lineTo( cur.x, cur.y);
|
final float length_m = (float)( body.getLength());
|
||||||
}
|
Point2D.Double cur = new Point2D.Double ();
|
||||||
|
for( double xBody = xResolution_m ; xBody < length_m; xBody += xResolution_m ){
|
||||||
|
// xBody is distance from front of parent body
|
||||||
|
cur.x = xOffset + xBody; // offset from origin (front of fin)
|
||||||
|
cur.y = yOffset + body.getRadius( xBody); // offset from origin ( fin-front-point )
|
||||||
|
|
||||||
// draw end-cap
|
bodyShape.lineTo( cur.x, cur.y);
|
||||||
bodyShape.lineTo( xOffset + length_m, yOffset + body.getAftRadius());
|
}
|
||||||
bodyShape.lineTo( xOffset + length_m, yOffset);
|
|
||||||
|
|
||||||
g2.draw(bodyShape);
|
// draw end-cap
|
||||||
}
|
bodyShape.lineTo( xOffset + length_m, yOffset + body.getAftRadius());
|
||||||
|
bodyShape.lineTo( xOffset + length_m, yOffset);
|
||||||
|
|
||||||
private void paintBodyTube( Graphics2D g2){
|
g2.draw(bodyShape);
|
||||||
// in-figure left extent
|
}
|
||||||
final double xFore = mountBounds_m.getMinX();
|
|
||||||
// in-figure right extent
|
private void paintBodyTube( Graphics2D g2){
|
||||||
final double xAft = mountBounds_m.getMaxX();
|
// in-figure left extent
|
||||||
// in-figure right extent
|
final double xFore = mountBounds_m.getMinX();
|
||||||
final double yCenter = mountBounds_m.getMinY();
|
// in-figure right extent
|
||||||
|
final double xAft = mountBounds_m.getMaxX();
|
||||||
Path2D.Double shape = new Path2D.Double();
|
// in-figure right extent
|
||||||
shape.moveTo( xFore, yCenter );
|
final double yCenter = mountBounds_m.getMinY();
|
||||||
shape.lineTo( xFore, 0); // body tube fore edge
|
|
||||||
shape.lineTo( xAft, 0); // body tube side
|
Path2D.Double shape = new Path2D.Double();
|
||||||
shape.lineTo( xAft, yCenter); // body tube aft edge
|
shape.moveTo( xFore, yCenter );
|
||||||
|
shape.lineTo( xFore, 0); // body tube fore edge
|
||||||
final float bodyLineWidth = (float) ( LINE_WIDTH_BODY_PIXELS / scale );
|
shape.lineTo( xAft, 0); // body tube side
|
||||||
g2.setStroke(new BasicStroke( bodyLineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
|
shape.lineTo( xAft, yCenter); // body tube aft edge
|
||||||
g2.setColor(Color.BLACK);
|
|
||||||
g2.draw(shape);
|
final float bodyLineWidth = (float) ( LINE_WIDTH_BODY_PIXELS / scale );
|
||||||
}
|
g2.setStroke(new BasicStroke( bodyLineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
|
||||||
|
g2.setColor(Color.BLACK);
|
||||||
|
g2.draw(shape);
|
||||||
|
}
|
||||||
|
|
||||||
private void paintFinShape(final Graphics2D g2){
|
private void paintFinShape(final Graphics2D g2){
|
||||||
// excludes fin tab points
|
// excludes fin tab points
|
||||||
final Coordinate[] drawPoints = finset.getFinPoints();
|
final Coordinate[] drawPoints = finset.getFinPoints();
|
||||||
|
|
||||||
Path2D.Double shape = new Path2D.Double();
|
Path2D.Double shape = new Path2D.Double();
|
||||||
Coordinate startPoint= drawPoints[0];
|
Coordinate startPoint= drawPoints[0];
|
||||||
shape.moveTo( startPoint.x, startPoint.y);
|
shape.moveTo( startPoint.x, startPoint.y);
|
||||||
for (int i = 1; i < drawPoints.length; i++) {
|
for (int i = 1; i < drawPoints.length; i++) {
|
||||||
shape.lineTo( drawPoints[i].x, drawPoints[i].y);
|
shape.lineTo( drawPoints[i].x, drawPoints[i].y);
|
||||||
}
|
}
|
||||||
|
|
||||||
final float finEdgeWidth_m = (float) (LINE_WIDTH_FIN_PIXELS / scale );
|
final float finEdgeWidth_m = (float) (LINE_WIDTH_FIN_PIXELS / scale );
|
||||||
g2.setStroke(new BasicStroke( finEdgeWidth_m, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
|
g2.setStroke(new BasicStroke( finEdgeWidth_m, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
|
||||||
g2.setColor(Color.BLACK);
|
g2.setColor(Color.BLACK);
|
||||||
g2.draw(shape);
|
g2.draw(shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void paintFinHandles(final Graphics2D g2) {
|
private void paintFinHandles(final Graphics2D g2) {
|
||||||
// excludes fin tab points
|
// excludes fin tab points
|
||||||
final Coordinate[] drawPoints = finset.getFinPoints();
|
final Coordinate[] drawPoints = finset.getFinPoints();
|
||||||
|
|
||||||
// Fin point boxes
|
|
||||||
final float boxWidth = (float) (BOX_WIDTH_PIXELS / scale );
|
|
||||||
final float boxHalfWidth = boxWidth/2;
|
|
||||||
|
|
||||||
final float boxEdgeWidth_m = (float) ( LINE_WIDTH_BOX_PIXELS / scale );
|
|
||||||
g2.setStroke(new BasicStroke( boxEdgeWidth_m, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
|
|
||||||
g2.setColor(POINT_COLOR);
|
|
||||||
|
|
||||||
finPointHandles = new Rectangle2D.Double[ drawPoints.length];
|
|
||||||
for (int currentIndex = 0; currentIndex < drawPoints.length; currentIndex++) {
|
|
||||||
Coordinate c = drawPoints[currentIndex];
|
|
||||||
|
|
||||||
if( currentIndex == selectedIndex ) {
|
|
||||||
final float selBoxWidth = (float) (SELECTED_BOX_WIDTH_PIXELS / scale );
|
|
||||||
final float selBoxHalfWidth = selBoxWidth/2;
|
|
||||||
|
|
||||||
final Rectangle2D.Double selectedPointHighlight = new Rectangle2D.Double(c.x - selBoxHalfWidth, c.y - selBoxHalfWidth, selBoxWidth, selBoxWidth);
|
// Fin point boxes
|
||||||
|
final float boxWidth = (float) (BOX_WIDTH_PIXELS / scale );
|
||||||
|
final float boxHalfWidth = boxWidth/2;
|
||||||
|
|
||||||
// switch to the highlight color
|
final float boxEdgeWidth_m = (float) ( LINE_WIDTH_BOX_PIXELS / scale );
|
||||||
g2.setColor(SELECTED_POINT_COLOR);
|
g2.setStroke(new BasicStroke( boxEdgeWidth_m, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
|
||||||
g2.draw(selectedPointHighlight);
|
g2.setColor(POINT_COLOR);
|
||||||
|
|
||||||
// reset to the normal color
|
|
||||||
g2.setColor(POINT_COLOR);
|
|
||||||
}
|
|
||||||
|
|
||||||
// normal boxes
|
finPointHandles = new Rectangle2D.Double[ drawPoints.length];
|
||||||
finPointHandles[currentIndex] = new Rectangle2D.Double(c.x - boxHalfWidth, c.y - boxHalfWidth, boxWidth, boxWidth);
|
for (int currentIndex = 0; currentIndex < drawPoints.length; currentIndex++) {
|
||||||
|
Coordinate c = drawPoints[currentIndex];
|
||||||
g2.draw(finPointHandles[currentIndex]);
|
|
||||||
}
|
if( currentIndex == selectedIndex ) {
|
||||||
}
|
final float selBoxWidth = (float) (SELECTED_BOX_WIDTH_PIXELS / scale );
|
||||||
|
final float selBoxHalfWidth = selBoxWidth/2;
|
||||||
|
|
||||||
|
final Rectangle2D.Double selectedPointHighlight = new Rectangle2D.Double(c.x - selBoxHalfWidth, c.y - selBoxHalfWidth, selBoxWidth, selBoxWidth);
|
||||||
|
|
||||||
|
// switch to the highlight color
|
||||||
|
g2.setColor(SELECTED_POINT_COLOR);
|
||||||
|
g2.draw(selectedPointHighlight);
|
||||||
|
|
||||||
|
// reset to the normal color
|
||||||
|
g2.setColor(POINT_COLOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
// normal boxes
|
||||||
|
finPointHandles[currentIndex] = new Rectangle2D.Double(c.x - boxHalfWidth, c.y - boxHalfWidth, boxWidth, boxWidth);
|
||||||
|
|
||||||
|
g2.draw(finPointHandles[currentIndex]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Point2D.Double getPoint( final int x, final int y){
|
private Point2D.Double getPoint( final int x, final int y){
|
||||||
if (finPointHandles == null)
|
if (finPointHandles == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// Calculate point in shapes' coordinates
|
// Calculate point in shapes' coordinates
|
||||||
Point2D.Double p = new Point2D.Double(x, y);
|
Point2D.Double p = new Point2D.Double(x, y);
|
||||||
try {
|
try {
|
||||||
projection.inverseTransform(p, p);
|
projection.inverseTransform(p, p);
|
||||||
return p;
|
return p;
|
||||||
} catch (NoninvertibleTransformException e) {
|
} catch (NoninvertibleTransformException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getIndexByPoint(final int x, final int y) {
|
public int getIndexByPoint(final int x, final int y) {
|
||||||
final Point2D.Double p = getPoint(x,y);
|
final Point2D.Double p = getPoint(x,y);
|
||||||
if (p == null)
|
if (p == null)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (int i = 0; i < finPointHandles.length; i++) {
|
for (int i = 0; i < finPointHandles.length; i++) {
|
||||||
if (finPointHandles[i].contains(p)) {
|
if (finPointHandles[i].contains(p)) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSegmentByPoint(final int x, final int y) {
|
public int getSegmentByPoint(final int x, final int y) {
|
||||||
final Point2D.Double p = getPoint(x,y);
|
final Point2D.Double p = getPoint(x,y);
|
||||||
if (p == null)
|
if (p == null)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
final double threshold = BOX_WIDTH_PIXELS / scale;
|
final double threshold = BOX_WIDTH_PIXELS / scale;
|
||||||
|
|
||||||
@ -318,15 +318,15 @@ public class FinPointFigure extends AbstractScaleFigure {
|
|||||||
// Distance to an infinite line, defined by two points:
|
// Distance to an infinite line, defined by two points:
|
||||||
// (For a more in-depth explanation, see wikipedia: https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line )
|
// (For a more in-depth explanation, see wikipedia: https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line )
|
||||||
double x0 = p.x;
|
double x0 = p.x;
|
||||||
double y0 = p.y;
|
double y0 = p.y;
|
||||||
final double distanceToLine = Math.abs((y2 - y1)*x0 - (x2-x1)*y0 + x2*y1 - y2*x1)/segmentLength;
|
final double distanceToLine = Math.abs((y2 - y1)*x0 - (x2-x1)*y0 + x2*y1 - y2*x1)/segmentLength;
|
||||||
|
|
||||||
final double distanceToStart = MathUtil.hypot(x1-x0, y1-y0);
|
final double distanceToStart = MathUtil.hypot(x1-x0, y1-y0);
|
||||||
final double distanceToEnd = MathUtil.hypot(x2-x0, y2-y0);
|
final double distanceToEnd = MathUtil.hypot(x2-x0, y2-y0);
|
||||||
final boolean withinSegment = (distanceToStart < segmentLength && distanceToEnd < segmentLength);
|
final boolean withinSegment = (distanceToStart < segmentLength && distanceToEnd < segmentLength);
|
||||||
|
|
||||||
if ( distanceToLine < threshold && withinSegment){
|
if ( distanceToLine < threshold && withinSegment){
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -352,52 +352,52 @@ public class FinPointFigure extends AbstractScaleFigure {
|
|||||||
modID = finset.getRocket().getAerodynamicModID();
|
modID = finset.getRocket().getAerodynamicModID();
|
||||||
updateTransform();
|
updateTransform();
|
||||||
}
|
}
|
||||||
return new Dimension(originLocation_px.width, originLocation_px.height);
|
return new Dimension(originLocation_px.width, originLocation_px.height);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void updateSubjectDimensions(){
|
|
||||||
|
|
||||||
// update subject (i.e. Fin) bounds
|
|
||||||
finBounds_m = new BoundingBox().update(finset.getFinPoints()).toRectangle();
|
|
||||||
|
|
||||||
// update to bound the parent body:
|
|
||||||
SymmetricComponent parent = (SymmetricComponent)this.finset.getParent();
|
|
||||||
final double xFinFront = finset.getAxialOffset(AxialMethod.TOP);
|
|
||||||
final double xParent = -xFinFront;
|
|
||||||
final double yParent = -parent.getRadius(xParent); // from parent centerline to fin front.
|
|
||||||
final double rParent = Math.max(parent.getForeRadius(), parent.getAftRadius());
|
|
||||||
mountBounds_m = new Rectangle2D.Double( xParent, yParent, parent.getLength(), rParent);
|
|
||||||
|
|
||||||
final double xMinBounds = Math.min(xParent, finBounds_m.getMinX());
|
|
||||||
final double yMinBounds = Math.min(xParent, finBounds_m.getMinY());
|
|
||||||
final double subjectWidth = Math.max( xFinFront + finBounds_m.getWidth(), parent.getLength());
|
|
||||||
final double subjectHeight = Math.max( 2*rParent, rParent + finBounds_m.getHeight());
|
|
||||||
subjectBounds_m = new Rectangle2D.Double( xMinBounds, yMinBounds, subjectWidth, subjectHeight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateCanvasOrigin() {
|
protected void updateSubjectDimensions(){
|
||||||
final int finHeight = (int)(finBounds_m.getHeight()*scale);
|
|
||||||
final int mountHeight = (int)(mountBounds_m.getHeight()*scale);
|
|
||||||
final int finFrontX = (int)(subjectBounds_m.getX()*scale);
|
|
||||||
final int subjectHeight = (int)(subjectBounds_m.getHeight()*scale);
|
|
||||||
|
|
||||||
originLocation_px.width = borderThickness_px.width - finFrontX;
|
|
||||||
|
|
||||||
if( visibleBounds_px.height > (subjectHeight+ 2*borderThickness_px.height)) {
|
|
||||||
originLocation_px.height = getHeight() - mountHeight - borderThickness_px.height;
|
|
||||||
}else {
|
|
||||||
originLocation_px.height = borderThickness_px.height + finHeight;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void resetSelectedIndex() {
|
// update subject (i.e. Fin) bounds
|
||||||
this.selectedIndex = -1;
|
finBounds_m = new BoundingBox().update(finset.getFinPoints()).toRectangle();
|
||||||
}
|
|
||||||
|
|
||||||
public void setSelectedIndex(final int newIndex) {
|
// update to bound the parent body:
|
||||||
this.selectedIndex = newIndex;
|
SymmetricComponent parent = (SymmetricComponent)this.finset.getParent();
|
||||||
}
|
final double xFinFront = finset.getAxialOffset(AxialMethod.TOP);
|
||||||
|
final double xParent = -xFinFront;
|
||||||
|
final double yParent = -parent.getRadius(xParent); // from parent centerline to fin front.
|
||||||
|
final double rParent = Math.max(parent.getForeRadius(), parent.getAftRadius());
|
||||||
|
mountBounds_m = new Rectangle2D.Double( xParent, yParent, parent.getLength(), rParent);
|
||||||
|
|
||||||
|
final double xMinBounds = Math.min(xParent, finBounds_m.getMinX());
|
||||||
|
final double yMinBounds = Math.min(xParent, finBounds_m.getMinY());
|
||||||
|
final double subjectWidth = Math.max( xFinFront + finBounds_m.getWidth(), parent.getLength());
|
||||||
|
final double subjectHeight = Math.max( 2*rParent, rParent + finBounds_m.getHeight());
|
||||||
|
subjectBounds_m = new Rectangle2D.Double( xMinBounds, yMinBounds, subjectWidth, subjectHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateCanvasOrigin() {
|
||||||
|
final int finHeight = (int)(finBounds_m.getHeight()*scale);
|
||||||
|
final int mountHeight = (int)(mountBounds_m.getHeight()*scale);
|
||||||
|
final int finFrontX = (int)(subjectBounds_m.getX()*scale);
|
||||||
|
final int subjectHeight = (int)(subjectBounds_m.getHeight()*scale);
|
||||||
|
|
||||||
|
originLocation_px.width = borderThickness_px.width - finFrontX;
|
||||||
|
|
||||||
|
if( visibleBounds_px.height > (subjectHeight+ 2*borderThickness_px.height)) {
|
||||||
|
originLocation_px.height = getHeight() - mountHeight - borderThickness_px.height;
|
||||||
|
}else {
|
||||||
|
originLocation_px.height = borderThickness_px.height + finHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetSelectedIndex() {
|
||||||
|
this.selectedIndex = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelectedIndex(final int newIndex) {
|
||||||
|
this.selectedIndex = newIndex;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user