[refactor] BodyTube now implements the BoxBounded interface
This commit is contained in:
		
							parent
							
								
									7b81f763c7
								
							
						
					
					
						commit
						22160dbe5d
					
				| @ -10,6 +10,7 @@ import net.sf.openrocket.motor.MotorConfiguration; | ||||
| import net.sf.openrocket.motor.MotorConfigurationSet; | ||||
| import net.sf.openrocket.preset.ComponentPreset; | ||||
| import net.sf.openrocket.startup.Application; | ||||
| import net.sf.openrocket.util.BoundingBox; | ||||
| import net.sf.openrocket.util.BugException; | ||||
| import net.sf.openrocket.util.Coordinate; | ||||
| import net.sf.openrocket.util.MathUtil; | ||||
| @ -21,7 +22,7 @@ import net.sf.openrocket.util.MathUtil; | ||||
|  * @author Sampo Niskanen <sampo.niskanen@iki.fi> | ||||
|  */ | ||||
| 
 | ||||
| public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial { | ||||
| public class BodyTube extends SymmetricComponent implements BoxBounded, MotorMount, Coaxial { | ||||
| 	private static final Translator trans = Application.getTranslator(); | ||||
| 	 | ||||
| 	private double outerRadius = 0; | ||||
| @ -296,52 +297,19 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial | ||||
| 	private static double getFilledVolume(double r, double l) { | ||||
| 		return Math.PI * r * r * l; | ||||
| 	} | ||||
| 	 | ||||
| 	 | ||||
| 	/** | ||||
| 	 * 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() { | ||||
| 		Collection<Coordinate> bounds = new ArrayList<Coordinate>(8); | ||||
| 		double x_min_shape = 0; | ||||
| 		double x_max_shape = this.length; | ||||
| 		double r_max_shape = getOuterRadius(); | ||||
| 		 | ||||
| 		Coordinate[] locs = this.getLocations(); | ||||
| 		// 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; | ||||
| 
 | ||||
| 	public BoundingBox getInstanceBoundingBox(){ | ||||
| 		BoundingBox instanceBounds = new BoundingBox(); | ||||
| 
 | ||||
| 		instanceBounds.update(new Coordinate(this.getLength(), 0,0)); | ||||
| 
 | ||||
| 		final double r = getOuterRadius(); | ||||
| 		instanceBounds.update(new Coordinate(0,r,r)); | ||||
| 		instanceBounds.update(new Coordinate(0,-r,-r)); | ||||
| 
 | ||||
| 		return instanceBounds; | ||||
| 	} | ||||
| 	 | ||||
| 	 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Check whether the given type can be added to this component.  BodyTubes allow any | ||||
| 	 * InternalComponents or ExternalComponents, excluding BodyComponents, to be added. | ||||
|  | ||||
| @ -581,17 +581,8 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo | ||||
| 					} | ||||
| 					componentBounds = instanceBounds.transform(context.transform); | ||||
| 				} | ||||
| 			}else if (component instanceof BodyTube) { | ||||
| 				// Legacy Case #1: | ||||
| 				// These components do not need the transform performed in | ||||
| 				// order to provide the proper coordinates for length calculation. | ||||
| 				// The transformation will cause the values to be calculated | ||||
| 				// incorrectly. This should be fixed in the appropriate places | ||||
| 				// not handled as one-offs in here. | ||||
| 				componentBounds.update(component.getComponentBounds()); | ||||
| 			} else { | ||||
| 				// Legacy Case #2: | ||||
| 				// These components do not implement | ||||
| 				// Legacy Case: These components do not implement the BoxBounded Interface. | ||||
| 				Collection<Coordinate> instanceCoordinates = component.getComponentBounds(); | ||||
| 				for (InstanceContext context : contexts) { | ||||
| 					/* | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user