Skip to content

Commit

Permalink
Fixed "absolute positioning" support for arcs and sectors
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAMan committed Nov 14, 2016
1 parent 72d94b2 commit 649fb95
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Currently known commands are:
* `fill_rect x1 y1 x2 y2 <color>` - draw a filled rect with corners at (x1, y1) to (x2, y2) with color `color`
* `line x1 y1 x2 y2 <color>` - draw a line from (x1, y1) to (x2, y2) with color `color`
* `text x0 y0 msg <color>` - show `msg` at coordinates (x0, y0) with color `color`
* `arc x y r startAngle arcAngle <color>` - draw a arc with center at (x, y) with radius r, begins at startAngle and extends for arcAngle. All angles in radians
* `arc x y r startAngle arcAngle <color>` - draw an arc with center at (x, y) with radius r, begins at startAngle and extends for arcAngle. All angles are in radians
* `fill_arc x y r startAngle arcAngle <color>` - draw a sector with center at (x, y) with radius r, begins at startAngle and extends for arcAngle. All angles are in radians

Color `<color>` is actually an `r g b` triple of floats where `0.0 0.0 0.0` will be black and `1.0 1.0 1.0` will be white.

Expand Down
18 changes: 8 additions & 10 deletions local-runner/plugins/LocalTestRendererListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ public void draw(Graphics graphics, LocalTestRendererListener listner, boolean u
if (type.equals(CIRCLE)) listner.drawCircle(x1, y1, x2, useAbsCoords);
if (type.equals(FILL_CIRCLE)) listner.fillCircle(x1, y1, x2, useAbsCoords);
if (type.equals(RECT)) listner.drawRect(x1, y1, x2 - x1, y2 - y1, useAbsCoords);
if (type.equals(ARC)) listner.drawArc(x1, y1, radius, startAngle, arcAngle);
if (type.equals(ARC)) listner.drawArc(x1, y1, radius, startAngle, arcAngle, useAbsCoords);
if (type.equals(FILL_RECT)) listner.fillRect(x1, y1, x2 - x1, y2 - y1, useAbsCoords);
if (type.equals(FILL_ARC)) listner.fillArc(x1, y1, radius, startAngle, arcAngle);
if (type.equals(FILL_ARC)) listner.fillArc(x1, y1, radius, startAngle, arcAngle, useAbsCoords);
if (type.equals(LINE)) listner.drawLine(x1, y1, x2, y2, useAbsCoords);
if (type.equals(TEXT)) listner.showText(x1, y1, text, useAbsCoords);
}
Expand Down Expand Up @@ -495,27 +495,25 @@ private void showText(double X, double Y, String text, boolean useAbsCoords)
graphics.setFont(oldFont);
}

private void fillArc(double centerX, double centerY, double radius, double startAngle, double arcAngle) {
Point2I topLeft = toCanvasPosition(centerX - radius, centerY - radius);
Point2I size = toCanvasOffset(2.0D * radius, 2.0D * radius);
private void fillArc(double centerX, double centerY, double radius, double startAngle, double arcAngle, boolean useAbsCoords) {
Point2I topLeft = useAbsCoords ? new Point2I(centerX - radius, centerY - radius) : toCanvasPosition(centerX - radius, centerY - radius);
Point2I size = useAbsCoords ? new Point2I(2.0D * radius, 2.0D * radius) : toCanvasOffset(2.0D * radius, 2.0D * radius);

// Convert from radians to degrees
int startAngleInt = (int) (Math.round(Math.toDegrees(startAngle)));
int arcAngleInt = (int) (Math.round(Math.toDegrees(arcAngle)));


graphics.fillArc(topLeft.getX(), topLeft.getY(), size.getX(), size.getY(), startAngleInt, arcAngleInt);
}

private void drawArc(double centerX, double centerY, double radius, double startAngle, double arcAngle) {
Point2I topLeft = toCanvasPosition(centerX - radius, centerY - radius);
Point2I size = toCanvasOffset(2.0D * radius, 2.0D * radius);
private void drawArc(double centerX, double centerY, double radius, double startAngle, double arcAngle, boolean useAbsCoords) {
Point2I topLeft = useAbsCoords ? new Point2I(centerX - radius, centerY - radius) : toCanvasPosition(centerX - radius, centerY - radius);
Point2I size = useAbsCoords ? new Point2I(2.0D * radius, 2.0D * radius) : toCanvasOffset(2.0D * radius, 2.0D * radius);

// Convert from radians to degrees
int startAngleInt = (int) (Math.round(Math.toDegrees(startAngle)));
int arcAngleInt = (int) (Math.round(Math.toDegrees(arcAngle)));


graphics.drawArc(topLeft.getX(), topLeft.getY(), size.getX(), size.getY(), startAngleInt, arcAngleInt);
}

Expand Down

0 comments on commit 649fb95

Please sign in to comment.