[refactor] FlightConfiguration now optionally caches its calculated bounds.
This commit is contained in:
		
							parent
							
								
									5e3d230724
								
							
						
					
					
						commit
						7d813b4e55
					
				@ -404,7 +404,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
 | 
				
			|||||||
	 * 
 | 
						 * 
 | 
				
			||||||
	 * @return	a <code>Collection</code> containing coordinates bounding the rocket.
 | 
						 * @return	a <code>Collection</code> containing coordinates bounding the rocket.
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
	 * @deprecated Migrate to FlightConfiguration#BoundingBox, when practical.
 | 
						 * @deprecated Migrate to <FlightConfiguration>.getBoundingBox(), when practical.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	@Deprecated 
 | 
						@Deprecated 
 | 
				
			||||||
	public Collection<Coordinate> getBounds() {
 | 
						public Collection<Coordinate> getBounds() {
 | 
				
			||||||
@ -414,26 +414,26 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
 | 
				
			|||||||
	/** 
 | 
						/** 
 | 
				
			||||||
	 * Return the bounding box of the current configuration.  
 | 
						 * Return the bounding box of the current configuration.  
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
	 * @return
 | 
						 * @return the rocket's bounding box (under the selected configuration)
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public BoundingBox getBoundingBox() {
 | 
						public BoundingBox getBoundingBox() {
 | 
				
			||||||
		if (rocket.getModID() != boundsModID) {
 | 
							if (rocket.getModID() != boundsModID) {
 | 
				
			||||||
			boundsModID = rocket.getModID();
 | 
								calculateBounds();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return cachedBounds;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			BoundingBox bounds = new BoundingBox();
 | 
						private void calculateBounds(){
 | 
				
			||||||
 | 
							BoundingBox bounds = new BoundingBox();
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			for (RocketComponent component : this.getActiveComponents()) {
 | 
							for (RocketComponent component : this.getActiveComponents()) {
 | 
				
			||||||
				BoundingBox componentBounds = new BoundingBox().update(component.getComponentBounds());				
 | 
								BoundingBox componentBounds = new BoundingBox().update(component.getComponentBounds());
 | 
				
			||||||
				
 | 
								bounds.update( componentBounds );
 | 
				
			||||||
				bounds.update( componentBounds );
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			cachedLength = bounds.span().x;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			cachedBounds.update( bounds );
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return cachedBounds;
 | 
							boundsModID = rocket.getModID();
 | 
				
			||||||
 | 
							cachedLength = bounds.span().x;
 | 
				
			||||||
 | 
							cachedBounds.update( bounds );
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
@ -443,9 +443,9 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
 | 
				
			|||||||
	 * @return	the length of the rocket in the X-direction.
 | 
						 * @return	the length of the rocket in the X-direction.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public double getLength() {
 | 
						public double getLength() {
 | 
				
			||||||
		if (rocket.getModID() != boundsModID)
 | 
							if (rocket.getModID() != boundsModID) {
 | 
				
			||||||
			getBounds(); // Calculates the length
 | 
								calculateBounds();
 | 
				
			||||||
			
 | 
							}
 | 
				
			||||||
		return cachedLength;
 | 
							return cachedLength;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user