Search in sources :

Example 61 with Path2D

use of java.awt.geom.Path2D in project sis by apache.

the class ShapeUtilitiesTest method testToPrimitive.

/**
 * Tests {@link ShapeUtilities#toPrimitive(Shape)}.
 */
@Test
public void testToPrimitive() {
    final Path2D path = new Path2D.Double();
    path.moveTo(4, 5);
    path.lineTo(7, 9);
    Shape p = ShapeUtilities.toPrimitive(path);
    assertInstanceOf("toPrimitive", Line2D.class, p);
    assertEquals("P1", new Point2D.Double(4, 5), ((Line2D) p).getP1());
    assertEquals("P2", new Point2D.Double(7, 9), ((Line2D) p).getP2());
    path.reset();
    path.moveTo(4, 5);
    path.quadTo(6, 7, 8, 5);
    p = ShapeUtilities.toPrimitive(path);
    assertInstanceOf("toPrimitive", QuadCurve2D.class, p);
    assertEquals("P1", new Point2D.Double(4, 5), ((QuadCurve2D) p).getP1());
    assertEquals("CtrlPt", new Point2D.Double(6, 7), ((QuadCurve2D) p).getCtrlPt());
    assertEquals("P2", new Point2D.Double(8, 5), ((QuadCurve2D) p).getP2());
    path.reset();
    path.moveTo(4, 5);
    path.curveTo(6, 7, 8, 6, 9, 4);
    p = ShapeUtilities.toPrimitive(path);
    assertInstanceOf("toPrimitive", CubicCurve2D.class, p);
    assertEquals("P1", new Point2D.Double(4, 5), ((CubicCurve2D) p).getP1());
    assertEquals("CtrlP1", new Point2D.Double(6, 7), ((CubicCurve2D) p).getCtrlP1());
    assertEquals("CtrlP2", new Point2D.Double(8, 6), ((CubicCurve2D) p).getCtrlP2());
    assertEquals("P2", new Point2D.Double(9, 4), ((CubicCurve2D) p).getP2());
}
Also used : Shape(java.awt.Shape) Point2D(java.awt.geom.Point2D) Path2D(java.awt.geom.Path2D) Test(org.junit.Test)

Example 62 with Path2D

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

the class HeapSamples method paintComponent.

@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    if (heapState == null) {
        return;
    }
    final int height = getHeight() - 1;
    final int width = getWidth();
    final long now = System.currentTimeMillis();
    final long maxDataSize = Math.round(heapState.getCapacity() / (double) TEN_MB) * TEN_MB + TEN_MB;
    final Graphics2D graphics2D = (Graphics2D) g;
    graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    graphics2D.setColor(getForegroundColor());
    graphics2D.setStroke(GRAPH_STROKE);
    Path2D path = null;
    for (HeapSample sample : heapState.getSamples()) {
        final double x = width - (((double) (now - sample.getSampleTime())) / ((double) heapState.getMaxSampleSizeMs()) * width);
        final double y = (double) height * sample.getBytes() / maxDataSize;
        if (path == null) {
            path = new Path2D.Double();
            path.moveTo(x, height - y + 1);
        } else {
            path.lineTo(x, height - y + 1);
        }
    }
    graphics2D.draw(path);
}
Also used : Path2D(java.awt.geom.Path2D) HeapSample(io.flutter.vmService.HeapMonitor.HeapSample)

Example 63 with Path2D

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

the class StackLayout method paintComponent.

@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    final Rectangle bounds = getBounds();
    final int height = bounds.height;
    if (height <= 20) {
        return;
    }
    final Graphics2D g2 = (Graphics2D) g;
    final float msPerPixel = (2.0f * 1000000.0f / 60.0f) / height;
    final float y = displayRefreshRateManager.getTargetMicrosPerFrame() / msPerPixel;
    final Stroke oldStroke = g2.getStroke();
    try {
        g2.setStroke(STROKE);
        final Path2D path = new Path2D.Float();
        // Slight left indent to allow space for [targetFrameTimeLabel].
        path.moveTo(34, height - y);
        path.lineTo(bounds.width, height - y);
        g2.draw(path);
    } finally {
        g2.setStroke(oldStroke);
    }
}
Also used : Path2D(java.awt.geom.Path2D)

Example 64 with Path2D

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

the class LineChart method postAnimate.

@Override
public void postAnimate() {
    long duration = System.nanoTime();
    int p = 0;
    // Store the Y coordinates of the last stacked series to use them to increment the Y values
    // of the current stacked series.
    TDoubleArrayList lastStackedSeriesY = null;
    Deque<Path2D> orderedPaths = new ArrayDeque<>(myLinesConfig.size());
    Deque<LineConfig> orderedConfigs = new ArrayDeque<>(myLinesConfig.size());
    for (Map.Entry<RangedContinuousSeries, LineConfig> lineConfig : myLinesConfig.entrySet()) {
        final RangedContinuousSeries ranged = lineConfig.getKey();
        final LineConfig config = lineConfig.getValue();
        // Stores the y coordinates of the current series in case it's used as a stacked series
        final TDoubleArrayList currentSeriesY = new TDoubleArrayList();
        Path2D path = new Path2D.Float();
        double xMin = ranged.getXRange().getMin();
        double xMax = ranged.getXRange().getMax();
        double yMin = ranged.getYRange().getMin();
        double yMax = ranged.getYRange().getMax();
        // X coordinate of the first point
        double firstXd = 0f;
        List<SeriesData<Long>> seriesList = ranged.getSeries();
        for (int i = 0; i < seriesList.size(); i++) {
            // TODO: refactor to allow different types (e.g. double)
            SeriesData<Long> seriesData = seriesList.get(i);
            long currX = seriesData.x;
            long currY = seriesData.value;
            double xd = (currX - xMin) / (xMax - xMin);
            double yd = (currY - yMin) / (yMax - yMin);
            // prior iteration). In this case, yd of the current series shouldn't change.
            if (config.isStacked() && lastStackedSeriesY != null && i < lastStackedSeriesY.size()) {
                yd += lastStackedSeriesY.get(i);
            }
            currentSeriesY.add(yd);
            // Swing's (0, 0) coordinate is in top-left. As we use bottom-left (0, 0), we need to adjust the y coordinate.
            float adjustedYd = 1 - (float) yd;
            if (i == 0) {
                path.moveTo(xd, adjustedYd);
                firstXd = xd;
            } else {
                // drawing a line to the destination point itself (e.g. (x1, y1)).
                if (config.isStepped()) {
                    float y = (float) path.getCurrentPoint().getY();
                    path.lineTo(xd, y);
                }
                path.lineTo(xd, adjustedYd);
            }
        }
        if (config.isFilled() && path.getCurrentPoint() != null) {
            // If the chart is filled, but not stacked, draw a line from the last point to X
            // axis and another one from this new point to the first destination point.
            path.lineTo(path.getCurrentPoint().getX(), 1f);
            path.lineTo(firstXd, 1f);
        }
        if (config.isStacked()) {
            lastStackedSeriesY = currentSeriesY;
        }
        if (config.isFilled()) {
            // Draw the filled lines first, otherwise other lines won't be visible.
            // Also, to draw stacked and filled lines correctly, they need to be drawn in reverse order to their adding order.
            orderedPaths.addFirst(path);
            orderedConfigs.addFirst(config);
        } else {
            orderedPaths.addLast(path);
            orderedConfigs.addLast(config);
        }
        addDebugInfo("Range[%d] Max: %.2f", p, xMax);
        p++;
    }
    myLinePaths.clear();
    myLinePaths.addAll(orderedPaths);
    myLinePathConfigs.clear();
    myLinePathConfigs.addAll(orderedConfigs);
    addDebugInfo("postAnimate time: %d ms", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - duration));
}
Also used : Path2D(java.awt.geom.Path2D) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries) SeriesData(com.android.tools.adtui.model.SeriesData) TDoubleArrayList(gnu.trove.TDoubleArrayList)

Example 65 with Path2D

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

the class TimelineComponent method fillTriangle.

private void fillTriangle(Point p1, Point p2, Point p3, Color color, Graphics2D g2d) {
    g2d.setColor(color);
    Path2D path = new Path2D.Float();
    path.moveTo(p1.getX(), p1.getY());
    path.lineTo(p2.getX(), p2.getY());
    path.lineTo(p3.getX(), p3.getY());
    path.lineTo(p1.getX(), p1.getY());
    g2d.fill(path);
}
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