Ignore:
Timestamp:
2016-08-22T21:16:36+02:00 (8 years ago)
Author:
Don-vip
Message:

fix #13413 - Clean ImproveWayAccuracyAction, add new class MapViewPath (patch by michael2402, modified) - gsoc-core

Location:
trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/NodeElement.java

    r10827 r10875  
    1616import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
    1717import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer;
     18import org.openstreetmap.josm.gui.draw.SymbolShape;
    1819import org.openstreetmap.josm.gui.mappaint.Cascade;
    1920import org.openstreetmap.josm.gui.mappaint.Environment;
     
    2425import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement.BoxProvider;
    2526import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement.SimpleBoxProvider;
    26 import org.openstreetmap.josm.gui.mappaint.styleelement.Symbol.SymbolShape;
    2727import org.openstreetmap.josm.gui.util.RotationAngle;
    2828import org.openstreetmap.josm.tools.CheckParameterUtil;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/Symbol.java

    r10840 r10875  
    55import java.awt.Shape;
    66import java.awt.Stroke;
    7 import java.awt.geom.Ellipse2D;
    8 import java.awt.geom.GeneralPath;
    9 import java.awt.geom.Rectangle2D;
    107import java.util.Objects;
    11 import java.util.Optional;
    12 import java.util.stream.Stream;
     8
     9import org.openstreetmap.josm.gui.draw.SymbolShape;
    1310
    1411/**
     
    8683     */
    8784    public Shape buildShapeAround(double x, double y) {
    88         int radius = size / 2;
    89         Shape shape;
    90         switch (symbolShape) {
    91         case SQUARE:
    92             // optimize for performance reasons
    93             shape = new Rectangle2D.Double(x - radius, y - radius, size, size);
    94             break;
    95         case CIRCLE:
    96             shape = new Ellipse2D.Double(x - radius, y - radius, size, size);
    97             break;
    98         default:
    99             shape = buildPolygon(x, y, radius);
    100             break;
    101         }
    102         return shape;
    103     }
    104 
    105     private Shape buildPolygon(double cx, double cy, int radius) {
    106         GeneralPath polygon = new GeneralPath();
    107         for (int i = 0; i < symbolShape.sides; i++) {
    108             double angle = ((2 * Math.PI / symbolShape.sides) * i) - symbolShape.rotation;
    109             double x = cx + radius * Math.cos(angle);
    110             double y = cy + radius * Math.sin(angle);
    111             if (i == 0) {
    112                 polygon.moveTo(x, y);
    113             } else {
    114                 polygon.lineTo(x, y);
    115             }
    116         }
    117         polygon.closePath();
    118         return polygon;
    119     }
    120 
    121     /**
    122      * A list of possible symbol shapes.
    123      */
    124     public enum SymbolShape {
    125         /**
    126          * A square
    127          */
    128         SQUARE("square", 4, Math.PI / 4),
    129         /**
    130          * A circle
    131          */
    132         CIRCLE("circle", 1, 0),
    133         /**
    134          * A triangle with sides of equal lengh
    135          */
    136         TRIANGLE("triangle", 3, Math.PI / 2),
    137         /**
    138          * A pentagon
    139          */
    140         PENTAGON("pentagon", 5, Math.PI / 2),
    141         /**
    142          * A hexagon
    143          */
    144         HEXAGON("hexagon", 6, 0),
    145         /**
    146          * A heptagon
    147          */
    148         HEPTAGON("heptagon", 7, Math.PI / 2),
    149         /**
    150          * An octagon
    151          */
    152         OCTAGON("octagon", 8, Math.PI / 8),
    153         /**
    154          * a nonagon
    155          */
    156         NONAGON("nonagon", 9, Math.PI / 2),
    157         /**
    158          * A decagon
    159          */
    160         DECAGON("decagon", 10, 0);
    161 
    162         private final String name;
    163         final int sides;
    164 
    165         final double rotation;
    166 
    167         SymbolShape(String name, int sides, double rotation) {
    168             this.name = name;
    169             this.sides = sides;
    170             this.rotation = rotation;
    171         }
    172 
    173         /**
    174          * Gets the number of normally straight sides this symbol has. Returns 1 for a circle.
    175          * @return The sides of the symbol
    176          */
    177         public int getSides() {
    178             return sides;
    179         }
    180 
    181         /**
    182          * Gets the rotateion of the first point of this symbol.
    183          * @return The roration
    184          */
    185         public double getRotation() {
    186             return rotation;
    187         }
    188 
    189         /**
    190          * Get the MapCSS name for this shape
    191          * @return The name
    192          */
    193         public String getName() {
    194             return name;
    195         }
    196 
    197         /**
    198          * Get the shape with the given name
    199          * @param val The name to search
    200          * @return The shape as optional
    201          */
    202         public static Optional<SymbolShape> forName(String val) {
    203             return Stream.of(values()).filter(shape -> val.equals(shape.name)).findAny();
    204         }
     85        return symbolShape.shapeAround(x, y, size);
    20586    }
    20687}
Note: See TracChangeset for help on using the changeset viewer.