]> git.gag.com Git - sw/motorsim/commitdiff
Allwo area calc on non-singular areas
authorBill Kuker <bkuker@billkuker.com>
Wed, 15 Apr 2009 18:46:25 +0000 (18:46 +0000)
committerBill Kuker <bkuker@billkuker.com>
Wed, 15 Apr 2009 18:46:25 +0000 (18:46 +0000)
src/com/billkuker/rocketry/motorsim/grain/ShapeUtil.java

index 23e8e2df2b06da6bf2454367c393e1881c4aae91..7b2aba37881003bdf558d1581394f22bc733736b 100644 (file)
@@ -19,10 +19,12 @@ public class ShapeUtil {
         * http://valis.cs.uiuc.edu/~sariel/research/CG/compgeom/msg00831.html\r
         * http://stackoverflow.com/questions/451426/how-do-i-calculate-the-surface-area-of-a-2d-polygon\r
         * http://www.wikihow.com/Calculate-the-Area-of-a-Polygon\r
+        * According to http://www.geog.ubc.ca/courses/klink/gis.notes/ncgia/u33.html\r
+        * this algorithm works OK with holes, and it seems to (see test)\r
         */\r
        public static Amount<Area> area(java.awt.geom.Area a) {\r
-               if ( !a.isSingular() )\r
-                       throw new IllegalArgumentException("Can not calculate area of non-singular shape!");\r
+               //if ( !a.isSingular() )\r
+                       //throw new IllegalArgumentException("Can not calculate area of non-singular shape!");\r
                PathIterator i = a.getPathIterator(new AffineTransform(), .001);\r
                \r
                \r
@@ -64,8 +66,9 @@ public class ShapeUtil {
                \r
                area = area / 2.0; // Result so far is double the signed area\r
                \r
-               if ( area < 0 ) //Depending on winding it could be negative\r
+               if ( area < 0 ){ //Depending on winding it could be negative\r
                        area = area * -1.0;\r
+               }\r
                \r
                \r
                return Amount.valueOf(area, SI.MILLIMETER.pow(2)).to(Area.UNIT);\r