Search in sources :

Example 66 with Path2D

use of java.awt.geom.Path2D in project android by JetBrains.

the class LineChart method drawLines.

public static void drawLines(Graphics2D g2d, List<Path2D> transformedPaths, List<LineConfig> configs, boolean grayScale) {
    assert transformedPaths.size() == configs.size();
    for (int i = 0; i < transformedPaths.size(); ++i) {
        Path2D path = transformedPaths.get(i);
        LineConfig config = configs.get(i);
        Color lineColor = config.getColor();
        if (grayScale) {
            int gray = (lineColor.getBlue() + lineColor.getRed() + lineColor.getGreen()) / 3;
            g2d.setColor(new Color(gray, gray, gray));
        } else {
            g2d.setColor(lineColor);
        }
        g2d.setStroke(config.getStroke());
        if (config.isFilled()) {
            g2d.fill(path);
        } else {
            g2d.draw(path);
        }
    }
}
Also used : Path2D(java.awt.geom.Path2D)

Example 67 with Path2D

use of java.awt.geom.Path2D in project android by JetBrains.

the class LineChartReducer method reduce.

@Override
public Path2D reduce(@NotNull Path2D path, @NotNull LineConfig config) {
    if (path.getCurrentPoint() == null) {
        return path;
    }
    Path2D resultPath = new Path2D.Float();
    float[] coords = new float[PATH_ITERATOR_COORDS_COUNT];
    float pixel = -1;
    float minX = -1, minY = -1;
    float maxX = -1, maxY = -1;
    float curX = -1, curY = -1;
    int minIndex = -1, maxIndex = -1;
    int curIndex = 0;
    PathIterator iterator = path.getPathIterator(null);
    while (!iterator.isDone()) {
        int segType = iterator.currentSegment(coords);
        assert segType == PathIterator.SEG_MOVETO || segType == PathIterator.SEG_LINETO;
        float lastX = curX;
        float lastY = curY;
        curX = coords[0];
        curY = coords[1];
        if (curIndex > 0 && curX < lastX) {
            // The second last point must be with maximum Y
            assert equals(maxX, lastX) && equals(maxY, lastY);
            break;
        }
        if (curIndex == 0 || curX >= pixel) {
            if (curIndex > 0) {
                // Add min and max points from the previous pixel
                addMinMaxPoints(resultPath, config, minIndex, minX, minY, maxIndex, maxX, maxY);
                // Add the last point from the previous pixel
                addToResultPath(resultPath, config, lastX, lastY);
            }
            pixel = (float) Math.floor(curX) + 1;
            minX = maxX = curX;
            minY = maxY = curY;
            minIndex = maxIndex = curIndex;
            // Add the first point from the current pixel
            addToResultPath(resultPath, config, curX, curY);
        } else {
            if (minY > curY) {
                minIndex = curIndex;
                minX = curX;
                minY = curY;
            }
            if (maxY <= curY) {
                maxIndex = curIndex;
                maxX = curX;
                maxY = curY;
            }
        }
        iterator.next();
        curIndex++;
    }
    addMinMaxPoints(resultPath, config, minIndex, minX, minY, maxIndex, maxX, maxY);
    addToResultPath(resultPath, config, curX, curY);
    if (config.isStepped()) {
        // The last point won't be added if Y value is the same with previous point, so let's add it
        if (resultPath.getCurrentPoint() == null || equals((float) resultPath.getCurrentPoint().getY(), curY)) {
            addToPath(resultPath, curX, curY);
        }
    }
    return resultPath;
}
Also used : PathIterator(java.awt.geom.PathIterator) Path2D(java.awt.geom.Path2D)

Example 68 with Path2D

use of java.awt.geom.Path2D in project intellij-community by JetBrains.

the class DividerPolygon method paint.

private void paint(Graphics2D g, int width) {
    GraphicsUtil.setupAntialiasing(g);
    if (!myApplied) {
        Shape upperCurve = makeCurve(width, myStart1, myStart2, true);
        Shape lowerCurve = makeCurve(width, myEnd1, myEnd2, false);
        Path2D path = new Path2D.Double();
        path.append(upperCurve, true);
        path.append(lowerCurve, true);
        g.setColor(myColor);
        g.fill(path);
        g.setColor(DiffUtil.getFramingColor(myColor));
        g.draw(upperCurve);
        g.draw(lowerCurve);
    } else {
        g.setColor(myColor);
        g.draw(makeCurve(width, myStart1 + 1, myStart2 + 1, true));
        g.draw(makeCurve(width, myStart1 + 2, myStart2 + 2, true));
        g.draw(makeCurve(width, myEnd1 + 1, myEnd2 + 1, false));
        g.draw(makeCurve(width, myEnd1 + 2, myEnd2 + 2, false));
    }
}
Also used : Path2D(java.awt.geom.Path2D)

Example 69 with Path2D

use of java.awt.geom.Path2D in project intellij-community by JetBrains.

the class DiffDrawUtil method drawCurveTrapezium.

public static void drawCurveTrapezium(@NotNull Graphics2D g, int x1, int x2, int start1, int end1, int start2, int end2, @Nullable Color fillColor, @Nullable Color borderColor) {
    Shape upperCurve = makeCurve(x1, x2, start1, start2, true);
    Shape lowerCurve = makeCurve(x1, x2, end1 + 1, end2 + 1, false);
    Shape lowerCurveBorder = makeCurve(x1, x2, end1, end2, false);
    if (fillColor != null) {
        Path2D path = new Path2D.Double();
        path.append(upperCurve, true);
        path.append(lowerCurve, true);
        g.setColor(fillColor);
        g.fill(path);
    }
    if (borderColor != null) {
        g.setColor(borderColor);
        g.draw(upperCurve);
        g.draw(lowerCurveBorder);
    }
}
Also used : Path2D(java.awt.geom.Path2D)

Example 70 with Path2D

use of java.awt.geom.Path2D in project jdk8u_jdk by JetBrains.

the class EmptyCapacity method main.

public static void main(final String[] args) {
    final Path2D path1 = new Path2D.Double(Path2D.WIND_EVEN_ODD, 0);
    path1.moveTo(10, 10);
    path1.lineTo(20, 20);
    final Path2D path2 = new Path2D.Float(Path2D.WIND_EVEN_ODD, 0);
    path2.moveTo(10, 10);
    path2.lineTo(20, 20);
}
Also used : Path2D(java.awt.geom.Path2D)

Aggregations

Path2D (java.awt.geom.Path2D)126 Point2D (java.awt.geom.Point2D)20 Area (java.awt.geom.Area)16 Rectangle2D (java.awt.geom.Rectangle2D)13 Shape (java.awt.Shape)9 Point (java.awt.Point)8 Line2D (java.awt.geom.Line2D)8 PathIterator (java.awt.geom.PathIterator)8 ArrayList (java.util.ArrayList)8 AffineTransform (java.awt.geom.AffineTransform)7 GeneralPath (java.awt.geom.GeneralPath)7 Color (java.awt.Color)6 Graphics2D (java.awt.Graphics2D)6 Paint (java.awt.Paint)6 ShapeRoi (ij.gui.ShapeRoi)5 BasicStroke (java.awt.BasicStroke)4 RadialGradientPaint (java.awt.RadialGradientPaint)4 Point2D_F64 (georegression.struct.point.Point2D_F64)3 RoundRectangle2D (java.awt.geom.RoundRectangle2D)3 Vector2D (de.gurkenlabs.litiengine.util.geom.Vector2D)2