fixed some visual display bugs improper auto-zoom.

This commit is contained in:
Daniel_M_Williams 2015-08-19 20:44:12 -04:00
parent 719db29a31
commit 29ec764b61
4 changed files with 64 additions and 14 deletions

View File

@ -311,14 +311,39 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
@Override
public Collection<Coordinate> getComponentBounds() {
Collection<Coordinate> bounds = new ArrayList<Coordinate>(8);
// not exact, but should *usually* give the right bounds
Coordinate ref = this.getLocation()[0];
double r = getOuterRadius();
addBound(bounds, ref.x, r);
addBound(bounds, ref.x + length, r);
return bounds;
double x_min_shape = 0;
double x_max_shape = this.length;
double r_max_shape = getOuterRadius();
Coordinate[] locs = this.getLocation();
// not strictly accurate, but this should provide an acceptable estimate for total vehicle size
double x_min_inst = Double.MAX_VALUE;
double x_max_inst = Double.MIN_VALUE;
double r_max_inst = 0.0;
// refactor: get component inherent bounds
for (Coordinate cur : locs) {
double x_cur = cur.x;
double r_cur = MathUtil.hypot(cur.y, cur.z);
if (x_min_inst > x_cur) {
x_min_inst = x_cur;
}
if (x_max_inst < x_cur) {
x_max_inst = x_cur;
}
if (r_cur > r_max_inst) {
r_max_inst = r_cur;
}
}
// combine the position bounds with the inherent shape bounds
double x_min = x_min_shape + x_min_inst;
double x_max = x_max_shape + x_max_inst;
double r_max = r_max_shape + r_max_inst;
addBoundingBox(bounds, x_min, x_max, r_max);
return bounds;
}
/**

View File

@ -615,23 +615,41 @@ public abstract class FinSet extends ExternalComponent {
}
/**
* Adds the fin set's bounds to the collection.
* Adds bounding coordinates to the given set. The body tube will fit within the
* convex hull of the points.
*
* Currently the points are simply a rectangular box around the body tube.
*/
@Override
public Collection<Coordinate> getComponentBounds() {
List<Coordinate> bounds = new ArrayList<Coordinate>();
double refx = this.getLocation()[0].x;
double r = getBodyRadius();
Collection<Coordinate> bounds = new ArrayList<Coordinate>(8);
// should simply return this component's bounds in this component's body frame.
double x_min = Double.MAX_VALUE;
double x_max = Double.MIN_VALUE;
double r_max = 0.0;
for (Coordinate point : getFinPoints()) {
addFinBound(bounds, refx + point.x, point.y + r);
double hypot = MathUtil.hypot(point.y, point.z);
double x_cur = point.x;
if (x_min > x_cur) {
x_min = x_cur;
}
if (x_max < x_cur) {
x_max = x_cur;
}
if (r_max < hypot) {
r_max = hypot;
}
}
addBoundingBox(bounds, x_min, x_max, r_max);
return bounds;
}
/**
* Adds the 2d-coordinate bound (x,y) to the collection for both z-components and for
* all fin rotations.

View File

@ -1831,6 +1831,13 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
/**
* Helper method to add eight bounds in a box around the rocket centerline. This box will be (x_max - x_min) long, and 2*r wide/high.
*/
protected static final void addBoundingBox(Collection<Coordinate> bounds, double x_min, double x_max, double r) {
addBound(bounds, x_min, r);
addBound(bounds, x_max, r);
}
/**
* Helper method to add four bounds rotated around the given x coordinate at radius 'r', and 90deg between each.

View File

@ -13,13 +13,13 @@ public class LaunchLugShapes extends RocketComponentShape {
public static RocketComponentShape[] getShapesSide(
net.sf.openrocket.rocketcomponent.RocketComponent component,
Transformation transformation,
Coordinate instanceOffset) {
Coordinate componentAbsoluteLocation) {
net.sf.openrocket.rocketcomponent.LaunchLug lug = (net.sf.openrocket.rocketcomponent.LaunchLug)component;
double length = lug.getLength();
double radius = lug.getOuterRadius();
Coordinate[] start = transformation.transform(lug.toAbsolute(instanceOffset));
Coordinate[] start = transformation.transform( lug.getLocation());
Shape[] s = new Shape[start.length];
for (int i=0; i < start.length; i++) {