]> git.gag.com Git - sw/motorsim/commitdiff
Added adjustable quality setting
authorBill Kuker <bkuker@billkuker.com>
Wed, 15 Apr 2009 13:48:07 +0000 (13:48 +0000)
committerBill Kuker <bkuker@billkuker.com>
Wed, 15 Apr 2009 13:48:07 +0000 (13:48 +0000)
src/com/billkuker/rocketry/motorsim/grain/RotatedShapeGrain.java

index 0c70fe046bd40632a65f39901958302174ba6dea..e9bd90969bb2015ab77b9d265ea33461776ed2b3 100644 (file)
@@ -20,6 +20,29 @@ import com.billkuker.rocketry.motorsim.visual.GrainPanel;
 \r
 public class RotatedShapeGrain implements Grain {\r
        \r
+       public enum Quality {\r
+               High()\r
+                       {{\r
+                                surfaceAreaStep = .001;\r
+                                squareFlatteningError = 0.001;\r
+                                squareSubdivide = .01;\r
+                                areaFlatteningError = .001;\r
+                       }},\r
+               Low()                   {{\r
+                        surfaceAreaStep = .001;\r
+                        squareFlatteningError = 0.01;\r
+                        squareSubdivide = .1;\r
+                        areaFlatteningError = .01;\r
+               }};\r
+               \r
+               double surfaceAreaStep = .001;\r
+               double squareFlatteningError = 0.001;\r
+               double squareSubdivide = .01;\r
+               double areaFlatteningError = .001;\r
+       }\r
+       \r
+       Quality quality = Quality.Low;\r
+       \r
        BurningShape shape = new BurningShape();\r
        \r
        Amount<Length> web = null;\r
@@ -29,6 +52,7 @@ public class RotatedShapeGrain implements Grain {
                shape.add( outside );\r
                shape.inhibit( outside );\r
                shape.subtract( new Rectangle2D.Double(0,50,5,70));\r
+               \r
                shape.subtract(new Rectangle2D.Double(0, 70, 15, 10));\r
        }\r
 \r
@@ -69,7 +93,7 @@ public class RotatedShapeGrain implements Grain {
                if (burn.isEmpty())\r
                        return zero;\r
                \r
-               burn.subtract(shape.getShape(regression.plus(Amount.valueOf(.001,\r
+               burn.subtract(shape.getShape(regression.plus(Amount.valueOf(quality.surfaceAreaStep,\r
                                SI.MILLIMETER))));\r
                \r
                System.out.println(regression);\r
@@ -109,7 +133,7 @@ public class RotatedShapeGrain implements Grain {
        }\r
        \r
        private Shape square(java.awt.geom.Area a) {\r
-               PathIterator i = a.getPathIterator(new AffineTransform(), 0.001);\r
+               PathIterator i = a.getPathIterator(new AffineTransform(), quality.squareFlatteningError);\r
                GeneralPath cur = new GeneralPath();\r
 \r
                double last[] = {0,0};\r
@@ -131,7 +155,7 @@ public class RotatedShapeGrain implements Grain {
                                double x = last[0];\r
                                double y = last[1];\r
                                double len = Math.sqrt(Math.pow(last[0]-coords[0], 2) + Math.pow(last[1]-coords[1], 2));\r
-                               int steps = (int)(len / .01) + 5;\r
+                               int steps = (int)(len / quality.squareSubdivide) + 5;\r
                                for (int s = 0; s < steps; s++) {\r
                                        x += (coords[0] - last[0]) / steps;\r
                                        y += (coords[1] - last[1]) / steps;\r
@@ -150,7 +174,7 @@ public class RotatedShapeGrain implements Grain {
        }\r
        \r
        private double yRotatedSurfaceArea(java.awt.geom.Area a) {\r
-               PathIterator i = a.getPathIterator(new AffineTransform(), .001);\r
+               PathIterator i = a.getPathIterator(new AffineTransform(), quality.areaFlatteningError);\r
                double x = 0, y = 0;\r
                double mx = 0, my = 0;\r
                double len = 0;\r