tour updates
[debian/openrocket] / src / net / sf / openrocket / rocketcomponent / TrapezoidFinSet.java
index fb276a7c03349248e532b3a71357e1b94b6676d4..fc118881dc042fa97cd1ee635c5021c6d3c37a6c 100644 (file)
@@ -1,26 +1,30 @@
 package net.sf.openrocket.rocketcomponent;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import net.sf.openrocket.l10n.Translator;
 import net.sf.openrocket.startup.Application;
 import net.sf.openrocket.util.Coordinate;
+import net.sf.openrocket.util.MathUtil;
 
 /**
  * A set of trapezoidal fins.  The root and tip chords are perpendicular to the rocket
  * base line, while the leading and aft edges may be slanted.
- * 
+ *
  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
  */
 
 public class TrapezoidFinSet extends FinSet {
        private static final Translator trans = Application.getTranslator();
-
-       public static final double MAX_SWEEP_ANGLE=(89*Math.PI/180.0);
-
+       
+       public static final double MAX_SWEEP_ANGLE = (89 * Math.PI / 180.0);
+       
        /*
         *           sweep   tipChord
         *           |    |___________
         *           |   /            |
-        *           |  /             | 
+        *           |  /             |
         *           | /              |  height
         *            /               |
         * __________/________________|_____________
@@ -35,11 +39,11 @@ public class TrapezoidFinSet extends FinSet {
        
        
        public TrapezoidFinSet() {
-               this (3, 0.05, 0.05, 0.025, 0.05);
+               this(3, 0.05, 0.05, 0.025, 0.03);
        }
        
        // TODO: HIGH:  height=0 -> CP = NaN
-       public TrapezoidFinSet(int fins, double rootChord, double tipChord, double sweep, 
+       public TrapezoidFinSet(int fins, double rootChord, double tipChord, double sweep,
                        double height) {
                super();
                
@@ -53,43 +57,46 @@ public class TrapezoidFinSet extends FinSet {
        
        public void setFinShape(double rootChord, double tipChord, double sweep, double height,
                        double thickness) {
-               if (this.length==rootChord && this.tipChord==tipChord && this.sweep==sweep &&
-                               this.height==height && this.thickness==thickness)
+               if (this.length == rootChord && this.tipChord == tipChord && this.sweep == sweep &&
+                               this.height == height && this.thickness == thickness)
                        return;
-               this.length=rootChord;
-               this.tipChord=tipChord;
-               this.sweep=sweep;
-               this.height=height;
-               this.thickness=thickness;
+               this.length = rootChord;
+               this.tipChord = tipChord;
+               this.sweep = sweep;
+               this.height = height;
+               this.thickness = thickness;
                fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
        }
-
+       
        public double getRootChord() {
                return length;
        }
+       
        public void setRootChord(double r) {
                if (length == r)
                        return;
-               length = Math.max(r,0);
+               length = Math.max(r, 0);
                fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
        }
        
        public double getTipChord() {
                return tipChord;
        }
+       
        public void setTipChord(double r) {
                if (tipChord == r)
                        return;
-               tipChord = Math.max(r,0);
+               tipChord = Math.max(r, 0);
                fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
        }
-
+       
        /**
         * Get the sweep length.
         */
        public double getSweep() {
                return sweep;
        }
+       
        /**
         * Set the sweep length.
         */
@@ -107,13 +114,14 @@ public class TrapezoidFinSet extends FinSet {
        public double getSweepAngle() {
                if (height == 0) {
                        if (sweep > 0)
-                               return Math.PI/2;
+                               return Math.PI / 2;
                        if (sweep < 0)
-                               return -Math.PI/2;
+                               return -Math.PI / 2;
                        return 0;
                }
-               return Math.atan(sweep/height);
+               return Math.atan(sweep / height);
        }
+       
        /**
         * Sets the sweep by the sweep angle.  The sweep is calculated and set by this method,
         * and the angle itself is not stored.
@@ -128,32 +136,35 @@ public class TrapezoidFinSet extends FinSet {
                        return;
                setSweep(sweep);
        }
-
+       
        public double getHeight() {
                return height;
        }
+       
        public void setHeight(double r) {
                if (height == r)
                        return;
-               height = Math.max(r,0);
+               height = Math.max(r, 0);
                fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
        }
-
        
-
+       
+       
        /**
         * Returns the geometry of a trapezoidal fin.
         */
        @Override
        public Coordinate[] getFinPoints() {
-               Coordinate[] c = new Coordinate[4];
+               List<Coordinate> list = new ArrayList<Coordinate>(4);
                
-               c[0] = Coordinate.NUL;
-               c[1] = new Coordinate(sweep,height);
-               c[2] = new Coordinate(sweep+tipChord,height);
-               c[3] = new Coordinate(length,0);
+               list.add(Coordinate.NUL);
+               list.add(new Coordinate(sweep, height));
+               if (tipChord > 0.0001) {
+                       list.add(new Coordinate(sweep + tipChord, height));
+               }
+               list.add(new Coordinate(MathUtil.max(length, 0.0001), 0));
                
-               return c;
+               return list.toArray(new Coordinate[list.size()]);
        }
        
        /**
@@ -164,20 +175,11 @@ public class TrapezoidFinSet extends FinSet {
                return height;
        }
        
-
+       
        @Override
        public String getComponentName() {
                //// Trapezoidal fin set
                return trans.get("TrapezoidFinSet.TrapezoidFinSet");
        }
-
-    /**
-     * Accept a visitor to this TrapezoidFinSet in the component hierarchy.
-     * 
-     * @param theVisitor  the visitor that will be called back with a reference to this TrapezoidFinSet
-     */    
-    @Override
-    public void accept(ComponentVisitor theVisitor) {
-        theVisitor.visit(this);
-    }
+       
 }