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