Skip to content

Commit

Permalink
merged with openjdk branch: fixed handling NaN/Infinity point coordin…
Browse files Browse the repository at this point in the history
…ates
  • Loading branch information
bourgesl committed Mar 18, 2016
1 parent f8491cc commit c5400de
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 52 deletions.
23 changes: 5 additions & 18 deletions src/main/java/org/marlin/pisces/MarlinRenderingEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -629,22 +629,11 @@ private static void pathToLoop(final float[] coords, final PathIterator pi,
{
// ported from DuctusRenderingEngine.feedConsumer() but simplified:
// - removed skip flag = !subpathStarted
boolean pathClosed = false;
// - removed pathClosed (ie subpathStarted not set to false)
boolean subpathStarted = false;
float mx = 0.0f;
float my = 0.0f;

for (; !pi.isDone(); pi.next()) {
final int type = pi.currentSegment(coords);
if (pathClosed) {
pathClosed = false;
if (type != PathIterator.SEG_MOVETO) {
// Force current point back to last moveto point
pc2d.moveTo(mx, my);
subpathStarted = true;
}
}
switch (type) {
switch (pi.currentSegment(coords)) {
case PathIterator.SEG_MOVETO:
/* Checking SEG_MOVETO coordinates if they are out of the
* [LOWER_BND, UPPER_BND] range. This check also handles NaN
Expand All @@ -654,9 +643,7 @@ private static void pathToLoop(final float[] coords, final PathIterator pi,
if (coords[0] < UPPER_BND && coords[0] > LOWER_BND &&
coords[1] < UPPER_BND && coords[1] > LOWER_BND)
{
mx = coords[0];
my = coords[1];
pc2d.moveTo(mx, my);
pc2d.moveTo(coords[0], coords[1]);
subpathStarted = true;
}
break;
Expand Down Expand Up @@ -738,8 +725,8 @@ private static void pathToLoop(final float[] coords, final PathIterator pi,
case PathIterator.SEG_CLOSE:
if (subpathStarted) {
pc2d.closePath();
subpathStarted = false;
pathClosed = true;
// do not set subpathStarted to false
// in case of missing moveTo() after close()
}
break;
default:
Expand Down
49 changes: 15 additions & 34 deletions src/test/java/CrashNaNTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,14 @@ private static void testFillDefaultAt() {
path2.lineTo(0, 200);
path2.closePath();

for (int i = 0; i < 1; i++) {
final long start = System.nanoTime();
g2d.setColor(Color.BLUE);
g2d.fill(path);
g2d.setColor(Color.GREEN);
g2d.fill(path2);

g2d.setColor(Color.BLACK);
g2d.draw(path);
g2d.draw(path2);

final long time = System.nanoTime() - start;
System.out.println("paint: duration= " + (1e-6 * time) + " ms.");
}
g2d.setColor(Color.BLUE);
g2d.fill(path);
g2d.setColor(Color.GREEN);
g2d.fill(path2);

g2d.setColor(Color.BLACK);
g2d.draw(path);
g2d.draw(path2);

if (SAVE_IMAGE) {
try {
Expand Down Expand Up @@ -218,16 +212,9 @@ private static void testDrawComplexAt() {
g2d.scale(0.5, 1.0);
g2d.rotate(Math.PI / 31);

for (int i = 0; i < 1; i++) {
final long start = System.nanoTime();

g2d.setColor(Color.BLACK);
g2d.draw(path);
g2d.draw(path2);

final long time = System.nanoTime() - start;
System.out.println("paint: duration= " + (1e-6 * time) + " ms.");
}
g2d.setColor(Color.BLACK);
g2d.draw(path);
g2d.draw(path2);

if (SAVE_IMAGE) {
try {
Expand Down Expand Up @@ -279,17 +266,11 @@ private static void testPathClosed() {
path.lineTo(0, 80);
path.closePath();

for (int i = 0; i < 1; i++) {
final long start = System.nanoTime();
g2d.setColor(Color.BLUE);
g2d.fill(path);

g2d.setColor(Color.BLACK);
g2d.draw(path);
g2d.setColor(Color.BLUE);
g2d.fill(path);

final long time = System.nanoTime() - start;
System.out.println("paint: duration= " + (1e-6 * time) + " ms.");
}
g2d.setColor(Color.BLACK);
g2d.draw(path);

if (SAVE_IMAGE) {
try {
Expand Down

0 comments on commit c5400de

Please sign in to comment.