Component scaling support
[debian/openrocket] / src / net / sf / openrocket / rocketcomponent / RingComponent.java
index 0450b4155addb667d212f6b8feee57851b33a510..9e2c16bc11a8dc8465decd2a70d26a9f11c3c484 100644 (file)
@@ -1,47 +1,50 @@
 package net.sf.openrocket.rocketcomponent;
 
-import net.sf.openrocket.util.Coordinate;
-import net.sf.openrocket.util.MathUtil;
-
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
+import net.sf.openrocket.util.Coordinate;
+import net.sf.openrocket.util.MathUtil;
+
 
 /**
  * An inner component that consists of a hollow cylindrical component.  This can be
  * an inner tube, tube coupler, centering ring, bulkhead etc.
- * 
+ *
  * The properties include the inner and outer radii, length and radial position.
- * 
+ *
  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
  */
 public abstract class RingComponent extends StructuralComponent implements Coaxial {
-
+       
        protected boolean outerRadiusAutomatic = false;
        protected boolean innerRadiusAutomatic = false;
        
-       
+
        private double radialDirection = 0;
        private double radialPosition = 0;
        
        private double shiftY = 0;
        private double shiftZ = 0;
        
-
        
-    @Override
+
+       @Override
        public abstract double getOuterRadius();
-    @Override
+       
+       @Override
        public abstract void setOuterRadius(double r);
        
-    @Override
-       public abstract double getInnerRadius();        
-    @Override
+       @Override
+       public abstract double getInnerRadius();
+       
+       @Override
        public abstract void setInnerRadius(double r);
        
-    @Override
+       @Override
        public abstract double getThickness();
+       
        public abstract void setThickness(double thickness);
        
        
@@ -49,6 +52,7 @@ public abstract class RingComponent extends StructuralComponent implements Coaxi
                return outerRadiusAutomatic;
        }
        
+       // Setter is protected, subclasses may make it public
        protected void setOuterRadiusAutomatic(boolean auto) {
                if (auto == outerRadiusAutomatic)
                        return;
@@ -61,6 +65,7 @@ public abstract class RingComponent extends StructuralComponent implements Coaxi
                return innerRadiusAutomatic;
        }
        
+       // Setter is protected, subclasses may make it public
        protected void setInnerRadiusAutomatic(boolean auto) {
                if (auto == innerRadiusAutomatic)
                        return;
@@ -69,22 +74,22 @@ public abstract class RingComponent extends StructuralComponent implements Coaxi
        }
        
        
-       
-       
+
+
        public final void setLength(double length) {
-               double l = Math.max(length,0);
+               double l = Math.max(length, 0);
                if (this.length == l)
                        return;
                
                this.length = l;
                fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
        }
-
+       
        
        /**
         * Return the radial direction of displacement of the component.  Direction 0
         * is equivalent to the Y-direction.
-        * 
+        *
         * @return  the radial direction.
         */
        public double getRadialDirection() {
@@ -94,7 +99,7 @@ public abstract class RingComponent extends StructuralComponent implements Coaxi
        /**
         * Set the radial direction of displacement of the component.  Direction 0
         * is equivalent to the Y-direction.
-        * 
+        *
         * @param dir  the radial direction.
         */
        public void setRadialDirection(double dir) {
@@ -106,14 +111,14 @@ public abstract class RingComponent extends StructuralComponent implements Coaxi
                shiftZ = radialPosition * Math.sin(radialDirection);
                fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
        }
-
-       
        
        
+
+
        /**
         * Return the radial position of the component.  The position is the distance
         * of the center of the component from the center of the parent component.
-        * 
+        *
         * @return  the radial position.
         */
        public double getRadialPosition() {
@@ -123,7 +128,7 @@ public abstract class RingComponent extends StructuralComponent implements Coaxi
        /**
         * Set the radial position of the component.  The position is the distance
         * of the center of the component from the center of the parent component.
-        * 
+        *
         * @param pos  the radial position.
         */
        public void setRadialPosition(double pos) {
@@ -135,7 +140,7 @@ public abstract class RingComponent extends StructuralComponent implements Coaxi
                shiftZ = radialPosition * Math.sin(radialDirection);
                fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
        }
-
+       
        
        public double getRadialShiftY() {
                return shiftY;
@@ -149,22 +154,22 @@ public abstract class RingComponent extends StructuralComponent implements Coaxi
                radialPosition = Math.hypot(y, z);
                radialDirection = Math.atan2(z, y);
                
-               // Re-calculate to ensure consistency 
+               // Re-calculate to ensure consistency
                shiftY = radialPosition * Math.cos(radialDirection);
                shiftZ = radialPosition * Math.sin(radialDirection);
-               assert(MathUtil.equals(y, shiftY));
-               assert(MathUtil.equals(z, shiftZ));
+               assert (MathUtil.equals(y, shiftY));
+               assert (MathUtil.equals(z, shiftZ));
                
                fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
        }
-
-
+       
+       
        /**
         * Return the number of times the component is multiplied.
         */
        public int getClusterCount() {
                if (this instanceof Clusterable)
-                       return ((Clusterable)this).getClusterConfiguration().getClusterCount();
+                       return ((Clusterable) this).getClusterConfiguration().getClusterCount();
                return 1;
        }
        
@@ -174,7 +179,7 @@ public abstract class RingComponent extends StructuralComponent implements Coaxi
         */
        @Override
        public Coordinate[] shiftCoordinates(Coordinate[] array) {
-               for (int i=0; i < array.length; i++) {
+               for (int i = 0; i < array.length; i++) {
                        array[i] = array[i].add(0, shiftY, shiftZ);
                }
                return array;
@@ -184,43 +189,33 @@ public abstract class RingComponent extends StructuralComponent implements Coaxi
        @Override
        public Collection<Coordinate> getComponentBounds() {
                List<Coordinate> bounds = new ArrayList<Coordinate>();
-               addBound(bounds,0,getOuterRadius());
-               addBound(bounds,length,getOuterRadius());
+               addBound(bounds, 0, getOuterRadius());
+               addBound(bounds, length, getOuterRadius());
                return bounds;
        }
        
-
        
+
        @Override
        public Coordinate getComponentCG() {
-               return new Coordinate(length/2, 0, 0, getComponentMass());
+               return new Coordinate(length / 2, 0, 0, getComponentMass());
        }
-
+       
        @Override
        public double getComponentMass() {
                return ringMass(getOuterRadius(), getInnerRadius(), getLength(),
                                getMaterial().getDensity()) * getClusterCount();
        }
        
-
+       
        @Override
-       public double getLongitudalUnitInertia() {
-               return ringLongitudalUnitInertia(getOuterRadius(), getInnerRadius(), getLength());
+       public double getLongitudinalUnitInertia() {
+               return ringLongitudinalUnitInertia(getOuterRadius(), getInnerRadius(), getLength());
        }
-
+       
        @Override
        public double getRotationalUnitInertia() {
                return ringRotationalUnitInertia(getOuterRadius(), getInnerRadius());
        }
-
-    /**
-     * Accept a visitor to this RingComponent in the component hierarchy.
-     * 
-     * @param theVisitor  the visitor that will be called back with a reference to this RingComponent
-     */    
-    @Override 
-    public void accept (final ComponentVisitor theVisitor) {
-        theVisitor.visit(this);
-    }
-
+       
 }