view 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 source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
 * Software engineering by Intevation GmbH
 *
 * This file is Free Software under the GNU AGPL (>=v3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */

package org.dive4elements.river.java2d;

import java.awt.Shape;
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 {

    public static enum ShapeType {
        measured, digitized, interpolated, outlier
    }

    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(-size, size);
        p.lineTo(size, -size);
        p.closePath();

        return p;
    }

    private static Shape createBox(float size) {
        return new Rectangle2D.Double(-size, -size, size * 2, size * 2);
    }

    private static Shape createCircle(float size) {
        return new Ellipse2D.Float(-size, -size, size * 2, size * 2);
    }

    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);
        }
    }
}

http://dive4elements.wald.intevation.org