Skip to content
Snippets Groups Projects
Commit 9210d516 authored by stepan's avatar stepan
Browse files

FastR Grid: distinguish filled polygon and polylines

parent 7b9503d6
No related branches found
No related tags found
No related merge requests found
......@@ -121,7 +121,7 @@ public abstract class GridLinesNode extends Node {
void drawPolylines(GridDevice dev, DrawingContext drawingCtx, double[] yy, double[] xx, int start, int length) {
xx[start + length] = xx[start];
yy[start + length] = yy[start];
dev.drawPolyLines(drawingCtx, xx, yy, start, length + 1);
dev.drawPolygon(drawingCtx, xx, yy, start, length + 1);
}
}
}
......@@ -101,6 +101,14 @@ public class BufferedJFrameDevice implements GridDevice {
}
}
@Override
public void drawPolygon(DrawingContext ctx, double[] x, double[] y, int startIndex, int length) {
inner.drawPolygon(ctx, x, y, startIndex, length);
if (buffer != null) {
drawActions.add(() -> inner.drawPolygon(ctx, x, y, startIndex, length));
}
}
@Override
public void drawCircle(DrawingContext ctx, double centerX, double centerY, double radius) {
inner.drawCircle(ctx, centerX, centerY, radius);
......
......@@ -54,6 +54,15 @@ public interface GridDevice {
*/
void drawPolyLines(DrawingContext ctx, double[] x, double[] y, int startIndex, int length);
/**
* Version of {@link #drawPolyLines(DrawingContext, double[], double[], int, int)}, which should
* fill in the area bounded by the lines. Note that it is responsibility of the caller to
* connect the first and the last point if the caller wishes to draw actual polygon.
*
* @see DrawingContext#getFillColor()
*/
void drawPolygon(DrawingContext ctx, double[] x, double[] y, int startIndex, int length);
void drawCircle(DrawingContext ctx, double centerX, double centerY, double radius);
/**
......
......@@ -23,6 +23,7 @@
package com.oracle.truffle.r.library.fastrGrid.device;
import static com.oracle.truffle.r.library.fastrGrid.device.DrawingContext.INCH_TO_POINTS_FACTOR;
import static java.awt.geom.Path2D.WIND_EVEN_ODD;
import java.awt.BasicStroke;
import java.awt.BorderLayout;
......@@ -89,17 +90,18 @@ public class JFrameDevice implements GridDevice {
@Override
public void drawPolyLines(DrawingContext ctx, double[] x, double[] y, int startIndex, int length) {
assert startIndex >= 0 && startIndex < x.length && startIndex < y.length : "startIndex out of bounds";
assert length > 0 && (startIndex + length) <= Math.min(x.length, y.length) : "length out of bounds";
Path2D.Double path = getPath2D(x, y, startIndex, length);
setContext(ctx);
Path2D.Double path = new Path2D.Double();
path.moveTo(x[startIndex], y[startIndex]);
for (int i = startIndex + 1; i < length; i++) {
path.lineTo(x[i], y[i]);
}
graphics.draw(path);
}
@Override
public void drawPolygon(DrawingContext ctx, double[] x, double[] y, int startIndex, int length) {
Path2D.Double path = getPath2D(x, y, startIndex, length);
setContext(ctx);
drawShape(ctx, path);
}
@Override
public void drawCircle(DrawingContext ctx, double centerX, double centerY, double radius) {
setContext(ctx);
......@@ -166,6 +168,17 @@ public class JFrameDevice implements GridDevice {
graphics.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
}
private Path2D.Double getPath2D(double[] x, double[] y, int startIndex, int length) {
assert startIndex >= 0 && startIndex < x.length && startIndex < y.length : "startIndex out of bounds";
assert length > 0 && (startIndex + length) <= Math.min(x.length, y.length) : "length out of bounds";
Path2D.Double path = new Path2D.Double(WIND_EVEN_ODD, x.length);
path.moveTo(x[startIndex], y[startIndex]);
for (int i = startIndex + 1; i < length; i++) {
path.lineTo(x[i], y[i]);
}
return path;
}
private void drawShape(DrawingContext drawingCtx, Shape shape) {
Paint paint = graphics.getPaint();
graphics.setPaint(fromGridColor(drawingCtx.getFillColor()));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment