|
|
@@ -28,6 +28,7 @@ import static org.junit.Assert.assertArrayEquals; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
|
|
|
|
import org.apache.batik.ext.awt.LinearGradientPaint; |
|
|
|
import org.apache.batik.ext.awt.RadialGradientPaint; |
|
|
|
|
|
|
|
public class GradientTestCase { |
|
|
|
|
|
|
@@ -67,8 +68,13 @@ public class GradientTestCase { |
|
|
|
return this; |
|
|
|
} |
|
|
|
|
|
|
|
ShadingChecker coords(Double... expectedCoords) { |
|
|
|
assertArrayEquals(expectedCoords, shading.getCoords().toArray()); |
|
|
|
ShadingChecker coords(double... expectedCoords) { |
|
|
|
double[] coords = new double[shading.getCoords().size()]; |
|
|
|
int index = 0; |
|
|
|
for (Double d : shading.getCoords()) { |
|
|
|
coords[index++] = d; |
|
|
|
} |
|
|
|
assertArrayEquals(expectedCoords, coords, 0.0001); |
|
|
|
return this; |
|
|
|
} |
|
|
|
|
|
|
@@ -100,7 +106,7 @@ public class GradientTestCase { |
|
|
|
return this; |
|
|
|
} |
|
|
|
|
|
|
|
FunctionChecker bounds(Double... expectedBounds) { |
|
|
|
FunctionChecker bounds(Float... expectedBounds) { |
|
|
|
assertArrayEquals(expectedBounds, function.getBounds().toArray()); |
|
|
|
return this; |
|
|
|
} |
|
|
@@ -131,7 +137,7 @@ public class GradientTestCase { |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testGradient() { |
|
|
|
public void simpleLinearGradient() { |
|
|
|
LinearGradientPaint gradient = new LinearGradientPaint(0f, 0f, 100f, 100f, |
|
|
|
fractions(0f, 1f), colors(Color.BLUE, Color.RED)); |
|
|
|
Pattern pattern = GradientMaker.makeLinearGradient(gradient, |
|
|
@@ -158,6 +164,122 @@ public class GradientTestCase { |
|
|
|
.functions(0); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void simpleRadialGradient() { |
|
|
|
RadialGradientPaint gradient = new RadialGradientPaint(100, 200, 50, |
|
|
|
fractions(0f, 1f), colors(Color.BLUE, Color.RED)); |
|
|
|
Pattern pattern = GradientMaker.makeRadialGradient(gradient, new AffineTransform(), new AffineTransform()); |
|
|
|
PatternChecker patternChecker = new PatternChecker(pattern).type(2); |
|
|
|
ShadingChecker shadingChecker = patternChecker.shading() |
|
|
|
.shadingType(3) |
|
|
|
.coords(100.0, 200.0, 0.0, 100.0, 200.0, 50.0) |
|
|
|
.extend(true, true); |
|
|
|
FunctionChecker functionChecker = shadingChecker.function() |
|
|
|
.functionType(3) |
|
|
|
.domain(0.0, 1.0) |
|
|
|
.bounds() |
|
|
|
.encode(0.0, 1.0) |
|
|
|
.functions(1); |
|
|
|
functionChecker.function(0) |
|
|
|
.functionType(2) |
|
|
|
.domain(0.0, 1.0) |
|
|
|
.cZero(0f, 0f, 1f) |
|
|
|
.cOne(1f, 0f, 0f) |
|
|
|
.functions(0); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void threeColorLinearGradient() { |
|
|
|
LinearGradientPaint gradient = new LinearGradientPaint(0f, 10f, 20f, 30f, |
|
|
|
fractions(0f, 0.5f, 1f), colors(Color.BLUE, Color.RED, Color.GREEN)); |
|
|
|
Pattern pattern = GradientMaker.makeLinearGradient(gradient, new AffineTransform(), new AffineTransform()); |
|
|
|
PatternChecker patternChecker = new PatternChecker(pattern) |
|
|
|
.type(2) |
|
|
|
.matrix(1.0, 0.0, 0.0, 1.0, 0.0, 0.0); |
|
|
|
ShadingChecker shadingChecker = patternChecker.shading() |
|
|
|
.shadingType(2) |
|
|
|
.coords(0.0, 10.0, 20.0, 30.0) |
|
|
|
.extend(true, true); |
|
|
|
FunctionChecker functionChecker = shadingChecker.function() |
|
|
|
.functionType(3) |
|
|
|
.domain(0.0, 1.0) |
|
|
|
.bounds(0.5f) |
|
|
|
.encode(0.0, 1.0, 0.0, 1.0) |
|
|
|
.functions(2); |
|
|
|
functionChecker.function(0) |
|
|
|
.functionType(2) |
|
|
|
.domain(0.0, 1.0) |
|
|
|
.cZero(0f, 0f, 1f) |
|
|
|
.cOne(1f, 0f, 0f) |
|
|
|
.functions(0); |
|
|
|
functionChecker.function(1) |
|
|
|
.functionType(2) |
|
|
|
.domain(0.0, 1.0) |
|
|
|
.cZero(1f, 0f, 0f) |
|
|
|
.cOne(0f, 1f, 0f) |
|
|
|
.functions(0); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void fourColorRadialGradientNonZeroFirstStop() { |
|
|
|
RadialGradientPaint gradient = new RadialGradientPaint(100, 200, 50, 110, 220, |
|
|
|
fractions(0.2f, 0.5f, 0.7f, 1f), colors(Color.BLUE, Color.RED, Color.GREEN, Color.WHITE)); |
|
|
|
Pattern pattern = GradientMaker.makeRadialGradient(gradient, new AffineTransform(), new AffineTransform()); |
|
|
|
ShadingChecker shadingChecker = new PatternChecker(pattern).shading() |
|
|
|
.coords(110.0, 220.0, 0.0, 100.0, 200.0, 50.0); |
|
|
|
FunctionChecker functionChecker = shadingChecker.function() |
|
|
|
.functionType(3) |
|
|
|
.bounds(0.2f, 0.5f, 0.7f) |
|
|
|
.encode(0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0) |
|
|
|
.functions(4); |
|
|
|
functionChecker.function(0) |
|
|
|
.functionType(2) |
|
|
|
.cZero(0f, 0f, 1f) |
|
|
|
.cOne(0f, 0f, 1f); |
|
|
|
functionChecker.function(1) |
|
|
|
.functionType(2) |
|
|
|
.cZero(0f, 0f, 1f) |
|
|
|
.cOne(1f, 0f, 0f); |
|
|
|
functionChecker.function(2) |
|
|
|
.functionType(2) |
|
|
|
.cZero(1f, 0f, 0f) |
|
|
|
.cOne(0f, 1f, 0f); |
|
|
|
functionChecker.function(3) |
|
|
|
.functionType(2) |
|
|
|
.cZero(0f, 1f, 0f) |
|
|
|
.cOne(1f, 1f, 1f); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void fourColorRadialGradientNonZeroLastStopFocalOut() { |
|
|
|
RadialGradientPaint gradient = new RadialGradientPaint(0, 0, 100, 100, 100, |
|
|
|
fractions(0f, 0.3f, 0.6f, 0.9f), colors(Color.WHITE, Color.RED, Color.GREEN, Color.BLUE)); |
|
|
|
Pattern pattern = GradientMaker.makeRadialGradient(gradient, new AffineTransform(), new AffineTransform()); |
|
|
|
ShadingChecker shadingChecker = new PatternChecker(pattern).shading() |
|
|
|
.coords(70.7036, 70.7036, 0.0, 0.0, 0.0, 100.0); |
|
|
|
FunctionChecker functionChecker = shadingChecker.function() |
|
|
|
.functionType(3) |
|
|
|
.bounds(0.3f, 0.6f, 0.9f) |
|
|
|
.encode(0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0) |
|
|
|
.functions(4); |
|
|
|
functionChecker.function(0) |
|
|
|
.functionType(2) |
|
|
|
.cZero(1f, 1f, 1f) |
|
|
|
.cOne(1f, 0f, 0f); |
|
|
|
functionChecker.function(1) |
|
|
|
.functionType(2) |
|
|
|
.cZero(1f, 0f, 0f) |
|
|
|
.cOne(0f, 1f, 0f); |
|
|
|
functionChecker.function(2) |
|
|
|
.functionType(2) |
|
|
|
.cZero(0f, 1f, 0f) |
|
|
|
.cOne(0f, 0f, 1f); |
|
|
|
functionChecker.function(3) |
|
|
|
.functionType(2) |
|
|
|
.cZero(0f, 0f, 1f) |
|
|
|
.cOne(0f, 0f, 1f); |
|
|
|
} |
|
|
|
|
|
|
|
private float[] fractions(float... fractions) { |
|
|
|
return fractions; |
|
|
|
} |