Skip to content

Commit

Permalink
Improve the ShapeRenderer class
Browse files Browse the repository at this point in the history
Use a copy of the old transform to avoid floating point precision errors
Apply the supplied transforms on top of the existing transform
  • Loading branch information
TheRamenChef committed Nov 24, 2018
1 parent 34ad0b2 commit ca5947d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/de/gurkenlabs/litiengine/graphics/ShapeRenderer.java
Expand Up @@ -18,9 +18,10 @@ public static void render(final Graphics2D g, final Shape shape) {
}

public static void render(final Graphics2D g, final Shape shape, double x, double y) {
AffineTransform oldTransform = g.getTransform();
g.translate(x, y);
render(g, shape);
g.translate(-x, -y);
g.setTransform(oldTransform);
}

public static void render(final Graphics2D g, final Shape shape, Point2D location) {
Expand All @@ -44,7 +45,7 @@ public static void renderOutline(final Graphics2D g, final Shape shape, final St

public static void renderTransformed(final Graphics2D g, final Shape shape, AffineTransform transform) {
final AffineTransform oldTransForm = g.getTransform();
g.setTransform(transform);
g.transform(transform);
render(g, shape);
g.setTransform(oldTransForm);
}
Expand All @@ -55,7 +56,7 @@ public static void renderOutlineTransformed(final Graphics2D g, final Shape shap

public static void renderOutlineTransformed(final Graphics2D g, final Shape shape, AffineTransform transform, final Stroke stroke) {
final AffineTransform oldTransForm = g.getTransform();
g.setTransform(transform);
g.transform(transform);
renderOutline(g, shape, stroke);
g.setTransform(oldTransForm);
}
Expand Down

0 comments on commit ca5947d

Please sign in to comment.