[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,27 +414,27 @@ 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();
|
||||||
|
|
||||||
BoundingBox bounds = new BoundingBox();
|
|
||||||
|
|
||||||
for (RocketComponent component : this.getActiveComponents()) {
|
|
||||||
BoundingBox componentBounds = new BoundingBox().update(component.getComponentBounds());
|
|
||||||
|
|
||||||
bounds.update( componentBounds );
|
|
||||||
}
|
|
||||||
|
|
||||||
cachedLength = bounds.span().x;
|
|
||||||
|
|
||||||
cachedBounds.update( bounds );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cachedBounds;
|
return cachedBounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void calculateBounds(){
|
||||||
|
BoundingBox bounds = new BoundingBox();
|
||||||
|
|
||||||
|
for (RocketComponent component : this.getActiveComponents()) {
|
||||||
|
BoundingBox componentBounds = new BoundingBox().update(component.getComponentBounds());
|
||||||
|
bounds.update( componentBounds );
|
||||||
|
}
|
||||||
|
|
||||||
|
boundsModID = rocket.getModID();
|
||||||
|
cachedLength = bounds.span().x;
|
||||||
|
cachedBounds.update( bounds );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the length of the rocket configuration, from the foremost bound X-coordinate
|
* Returns the length of the rocket configuration, from the foremost bound X-coordinate
|
||||||
@ -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