diff --git a/gral-core/src/main/java/de/erichseifert/gral/plots/axes/LogarithmicRenderer2D.java b/gral-core/src/main/java/de/erichseifert/gral/plots/axes/LogarithmicRenderer2D.java index 075a7176..edd7d7c0 100644 --- a/gral-core/src/main/java/de/erichseifert/gral/plots/axes/LogarithmicRenderer2D.java +++ b/gral-core/src/main/java/de/erichseifert/gral/plots/axes/LogarithmicRenderer2D.java @@ -65,8 +65,9 @@ public double worldToView(Axis axis, Number value, boolean extrapolate) { } double minLog = (min > 0.0) ? Math.log10(min) : 0.0; double maxLog = (max > 0.0) ? Math.log10(max) : 1.0; - return (Math.log10(val) - minLog)*getShapeLength() / + double result = (Math.log10(val) - minLog)*getShapeLength() / (maxLog - minLog); + return Double.isFinite(result) ? result : 0; } /** @@ -92,8 +93,9 @@ public Number viewToWorld(Axis axis, double value, boolean extrapolate) { } double minLog = (min > 0.0) ? Math.log10(min) : 0.0; double maxLog = (max > 0.0) ? Math.log10(max) : 1.0; - return Math.pow(10.0, + double result = Math.pow(10.0, value*(maxLog - minLog)/getShapeLength() + minLog); + return Double.isFinite(result) ? result : 0; } @Override diff --git a/gral-core/src/test/java/de/erichseifert/gral/plots/axes/LogarithmicRenderer2DTest.java b/gral-core/src/test/java/de/erichseifert/gral/plots/axes/LogarithmicRenderer2DTest.java index 5a92ffef..a963010d 100644 --- a/gral-core/src/test/java/de/erichseifert/gral/plots/axes/LogarithmicRenderer2DTest.java +++ b/gral-core/src/test/java/de/erichseifert/gral/plots/axes/LogarithmicRenderer2DTest.java @@ -63,7 +63,7 @@ public void testDraw() { @Test public void testWorldToView() { - assertEquals(Double.NEGATIVE_INFINITY, renderer.worldToView(axis, 0.0, true), DELTA); + assertEquals(0, renderer.worldToView(axis, 0.0, true), DELTA); assertEquals(Math.log10( 0.1), renderer.worldToView(axis, 0.1, true), DELTA); assertEquals(Math.log10( 1.0), renderer.worldToView(axis, 1.0, true), DELTA); assertEquals(Math.log10( 5.0), renderer.worldToView(axis, 5.0, true), DELTA);