Skip to content

Commit

Permalink
Merge pull request #31 from earlygrey/fixes/libgdx-1.9.12-compatibility
Browse files Browse the repository at this point in the history
Fixes/libgdx 1.9.12 compatibility
  • Loading branch information
earlygrey authored Nov 2, 2020
2 parents c82f0d3 + 5a942cd commit 75c9da1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[UNRELEASED]
- fix compatibility with libGDX 1.9.12

[2.3.0]
- fixed bug where pixels outside specified region were sometimes drawn
Expand Down
8 changes: 4 additions & 4 deletions drawer/src/space/earlygrey/shapedrawer/Joiner.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class Joiner {
static float preparePointyJoin(Vector2 A, Vector2 B, Vector2 C, Vector2 D, Vector2 E, float halfLineWidth) {
AB.set(B).sub(A);
BC.set(C).sub(B);
float angle = AB.angleRad(BC);
float angle = ShapeUtils.angleRad(AB, BC);
if (ShapeUtils.epsilonEquals(angle, 0) || ShapeUtils.epsilonEquals(angle, ShapeUtils.PI2)) {
prepareStraightJoin(B, D, E, halfLineWidth);
return angle;
}
float len = (float) (halfLineWidth / Math.sin(angle));
boolean bendsLeft = angle>0;
boolean bendsLeft = angle < 0;
AB.setLength(len);
BC.setLength(len);
Vector insidePoint = bendsLeft?D:E;
Expand All @@ -42,15 +42,15 @@ static float preparePointyJoin(Vector2 A, Vector2 B, Vector2 C, Vector2 D, Vecto
static boolean prepareSmoothJoin(Vector2 A, Vector2 B, Vector2 C, Vector2 D, Vector2 E, float halfLineWidth, boolean startOfEdge) {
AB.set(B).sub(A);
BC.set(C).sub(B);
float angle = AB.angleRad(BC);
float angle = ShapeUtils.angleRad(AB, BC);
if (ShapeUtils.epsilonEquals(angle, 0) || ShapeUtils.epsilonEquals(angle, ShapeUtils.PI2)) {
prepareStraightJoin(B, D, E, halfLineWidth);
return true;
}
float len = (float) (halfLineWidth / Math.sin(angle));
AB.setLength(len);
BC.setLength(len);
boolean bendsLeft = angle>0;
boolean bendsLeft = angle < 0;
Vector insidePoint = bendsLeft?D:E;
Vector outsidePoint = bendsLeft?E:D;
insidePoint.set(B).sub(AB).add(BC);
Expand Down
5 changes: 5 additions & 0 deletions drawer/src/space/earlygrey/shapedrawer/ShapeUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package space.earlygrey.shapedrawer;

import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;

public class ShapeUtils {

Expand Down Expand Up @@ -34,4 +35,8 @@ public static float ceil(float x, float interval) {
return (float) (Math.ceil(x / interval) * interval);
}

public static float angleRad (Vector2 v, Vector2 reference) {
return (float) Math.atan2(reference.x * v.y - reference.y * v.x, v.x * reference.x + v.y * reference.y);
}

}

0 comments on commit 75c9da1

Please sign in to comment.