diff artifacts/src/main/java/org/dive4elements/river/java2d/ShapeUtils.java @ 9360:ddcd52d239cd

Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle). Removed old outliers theme. Also consider showpoints property. Also consider pointsize property.
author gernotbelger
date Wed, 01 Aug 2018 17:13:52 +0200
parents af13ceeba52a
children d8e753d0fdb9
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/java2d/ShapeUtils.java	Wed Aug 01 13:21:34 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/java2d/ShapeUtils.java	Wed Aug 01 17:13:52 2018 +0200
@@ -9,83 +9,81 @@
 package org.dive4elements.river.java2d;
 
 import java.awt.Shape;
-
-import java.awt.geom.AffineTransform;
+import java.awt.geom.Area;
 import java.awt.geom.Ellipse2D;
 import java.awt.geom.GeneralPath;
 import java.awt.geom.Rectangle2D;
-
 import java.util.HashMap;
 import java.util.Map;
 
-public class ShapeUtils
-{
-    // TODO: Use enum
-    public static final int MEASURED     = 0;
-    public static final int DIGITIZED    = 1;
-    public static final int INTERPOLATED = 2;
-
-    public static final boolean DIGITIZED_FILL    = false;
-    public static final boolean MEASURED_FILL     = true;
-    public static final boolean INTERPOLATED_FILL = false;
-
-   public static final Shape DIGITIZED_SHAPE =
-        createCross(4f);
+public class ShapeUtils {
 
-    public static final Shape MEASURED_SHAPE =
-        new Rectangle2D.Double(-2, -2, 4, 4);
-
-    public static final Shape INTERPOLATED_SHAPE =
-        new Ellipse2D.Double(-2, -2, 4, 4);
-
-    protected static Map<Long, Shape> scaledShapesCache =
-        new HashMap<Long, Shape>();
+    public static enum ShapeType {
+        measured, digitized, interpolated, outlier
+    }
 
-    public static final Shape createCross(float size) {
-        float half = size * 0.5f;
-        GeneralPath p = new GeneralPath();
-        p.moveTo(-half, -half);
-        p.lineTo(half, half);
+    private static Map<Long, Shape> scaledShapesCache = new HashMap<>();
+
+    private static final Shape createCross(float size) {
+
+        final GeneralPath p = new GeneralPath();
+
+        p.moveTo(-size, -size);
+        p.lineTo(size, size);
         p.closePath();
-        p.moveTo(-half, half);
-        p.lineTo(half, -half);
+        p.moveTo(-size, size);
+        p.lineTo(size, -size);
         p.closePath();
+
         return p;
     }
 
-    public static Shape scale(Shape shape, float factor) {
-        if (factor == 1f) {
-            return shape;
-        }
-        AffineTransform xform =
-            AffineTransform.getScaleInstance(factor, factor);
-
-        GeneralPath gp = new GeneralPath(shape);
-        return gp.createTransformedShape(xform);
+    private static Shape createBox(float size) {
+        return new Rectangle2D.Double(-size, -size, size * 2, size * 2);
     }
 
-    public static synchronized Shape getScaledShape(int type, float size) {
-
-        Long hash = Long.valueOf(
-            (((long)type) << 32) | Float.floatToIntBits(size));
-
-        Shape shape = scaledShapesCache.get(hash);
+    private static Shape createCircle(float size) {
+        return new Ellipse2D.Float(-size, -size, size * 2, size * 2);
+    }
 
-        if (shape == null) {
-            switch (type) {
-                case MEASURED:
-                    shape = MEASURED_SHAPE;
-                    break;
-                case DIGITIZED:
-                    shape = DIGITIZED_SHAPE;
-                    break;
-                default:
-                    shape = INTERPOLATED_SHAPE;
-            }
-            scaledShapesCache.put(hash, shape = scale(shape, size));
+    private static final Shape createTriangle(float size) {
+        final GeneralPath p = new GeneralPath();
+
+        p.moveTo(-size, size);
+        p.lineTo(size, size);
+        p.lineTo(0, -size);
+        p.closePath();
+
+        return new Area(p);
+    }
+
+    public static synchronized Shape getScaledShape(final ShapeType type, float size) {
+
+        final Long hash = Long.valueOf((((long) type.ordinal()) << 32) | Float.floatToIntBits(size));
+
+        final Shape shape = scaledShapesCache.get(hash);
+        if (shape != null)
+            return shape;
+
+        final Shape newShape = createScaledShape(type, size);
+        scaledShapesCache.put(hash, newShape);
+        return newShape;
+    }
+
+    private static Shape createScaledShape(ShapeType type, float size) {
+        switch (type) {
+        case measured:
+            return createBox(size);
+
+        case digitized:
+            return createCross(size);
+
+        case outlier:
+            return createTriangle(size);
+
+        case interpolated:
+        default:
+            return createCircle(size);
         }
-
-        return shape;
     }
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
+}
\ No newline at end of file

http://dive4elements.wald.intevation.org