test/test_graphics_context.rb in processing-0.5.31 vs test/test_graphics_context.rb in processing-0.5.32
- old
+ new
@@ -74,10 +74,71 @@
strokeWeight 50
line 100, 100, 500, 500
END
end
+ def test_textFont()
+ graphics do |g|
+ arial10 = g.createFont 'Arial', 10
+ helvetica11 = g.createFont 'Helvetica', 11
+
+ font = -> {g.instance_variable_get(:@textFont__).getInternal__}
+ painterFont = -> {g.instance_variable_get(:@painter__).font}
+
+ assert_not_nil font[] .name
+ assert_not_equal 'Arial', font[] .name
+ assert_equal 12, font[] .size
+ assert_equal 12, painterFont[].size
+
+ g.textFont arial10
+ assert_equal 'Arial', font[] .name
+ assert_equal 10, font[] .size
+ assert_equal 10, painterFont[].size
+
+ g.push do
+ g.textFont helvetica11
+ assert_equal 'Helvetica', font[] .name
+ assert_equal 11, font[] .size
+ assert_equal 11, painterFont[].size
+ end
+
+ assert_equal 'Arial', font[] .name
+ assert_equal 10, font[] .size
+ assert_equal 10, painterFont[].size
+
+ g.push do
+ g.textFont arial10, 13
+ assert_equal 'Arial', font[] .name
+ assert_equal 13, font[] .size
+ assert_equal 13, painterFont[].size
+ end
+
+ assert_equal 'Arial', font[] .name
+ assert_equal 10, font[] .size
+ assert_equal 10, painterFont[].size
+ end
+ end
+
+ def test_textSize()
+ graphics do |g|
+ font = -> {g.instance_variable_get(:@textFont__).getInternal__}
+ painterFont = -> {g.instance_variable_get(:@painter__).font}
+
+ assert_equal 12, font[] .size
+ assert_equal 12, painterFont[].size
+
+ g.push do
+ g.textSize 10
+ assert_equal 10, font[] .size
+ assert_equal 10, painterFont[].size
+ end
+
+ assert_equal 12, font[] .size
+ assert_equal 12, painterFont[].size
+ end
+ end
+
def test_clear()
colors = -> g {get_pixels(g).uniq}
g = graphics
assert_equal [0], colors[g]
@@ -466,10 +527,159 @@
assert_p5_fill src, 'endShape CLOSE'
assert_p5_stroke src, 'endShape CLOSE'
assert_p5_fill_stroke src, 'endShape CLOSE'
end
+ def test_beginShape_with_fill()
+ assert_equal_draw <<~HEADER, <<~EXPECTED, <<~ACTUAL
+ noStroke
+ HEADER
+ fill 0, 255, 0
+ rect 100, 100, 500, 400
+ EXPECTED
+ beginShape
+ fill 0, 255, 0
+ vertex 100, 100
+ vertex 600, 100
+ vertex 600, 500
+ vertex 100, 500
+ endShape
+ ACTUAL
+ end
+
+ def test_curveVertex()
+ src = <<~END
+ beginShape
+ curveVertex 100, 100
+ curveVertex 800, 100
+ curveVertex 800, 800
+ curveVertex 100, 800
+ END
+ assert_p5_fill src, 'endShape'
+ assert_p5_stroke src, 'endShape'
+ assert_p5_fill_stroke src, 'endShape'
+ assert_p5_fill src, 'endShape CLOSE'
+ assert_p5_stroke src, 'endShape CLOSE'
+ assert_p5_fill_stroke src, 'endShape CLOSE'
+
+ src = <<~END
+ beginShape
+ curveVertex 200, 200
+ curveVertex 200, 200
+ curveVertex 800, 200
+ curveVertex 800, 400
+ curveVertex 200, 400
+ curveVertex 200, 800
+ curveVertex 800, 800
+ curveVertex 800, 700
+ curveVertex 800, 700
+ END
+ assert_p5_fill src, 'endShape', threshold: THRESHOLD_TO_BE_FIXED
+ assert_p5_stroke src, 'endShape'
+ assert_p5_fill_stroke src, 'endShape', threshold: THRESHOLD_TO_BE_FIXED
+ assert_p5_fill src, 'endShape CLOSE', threshold: THRESHOLD_TO_BE_FIXED
+ assert_p5_stroke src, 'endShape CLOSE'
+ assert_p5_fill_stroke src, 'endShape CLOSE', threshold: THRESHOLD_TO_BE_FIXED
+ end
+
+ def test_bezierVertex()
+ src = <<~END
+ beginShape
+ vertex 100, 100
+ bezierVertex 900, 100, 900, 900, 200, 500
+ END
+ assert_p5_fill src, 'endShape'
+ assert_p5_stroke src, 'endShape'
+ assert_p5_fill_stroke src, 'endShape'
+ assert_p5_fill src, 'endShape CLOSE'
+ assert_p5_stroke src, 'endShape CLOSE'
+ assert_p5_fill_stroke src, 'endShape CLOSE'
+
+ src = <<~END
+ beginShape
+ vertex 100, 100
+ bezierVertex 900, 100, 900, 500, 300, 500
+ bezierVertex 100, 900, 900, 900, 900, 600
+ END
+ assert_p5_fill src, 'endShape', threshold: THRESHOLD_TO_BE_FIXED
+ assert_p5_stroke src, 'endShape'
+ assert_p5_fill_stroke src, 'endShape', threshold: THRESHOLD_TO_BE_FIXED
+ assert_p5_fill src, 'endShape CLOSE', threshold: THRESHOLD_TO_BE_FIXED
+ assert_p5_stroke src, 'endShape CLOSE'
+ assert_p5_fill_stroke src, 'endShape CLOSE', threshold: THRESHOLD_TO_BE_FIXED
+ end
+
+ def test_quadraticVertex()
+ src = <<~END
+ beginShape
+ vertex 100, 100
+ quadraticVertex 800, 500, 200, 800
+ END
+ assert_p5_fill src, 'endShape'
+ assert_p5_stroke src, 'endShape'
+ assert_p5_fill_stroke src, 'endShape'
+ assert_p5_fill src, 'endShape CLOSE'
+ assert_p5_stroke src, 'endShape CLOSE'
+ assert_p5_fill_stroke src, 'endShape CLOSE'
+
+ src = <<~END
+ beginShape
+ vertex 100, 100
+ quadraticVertex 800, 100, 500, 500
+ quadraticVertex 100, 800, 800, 800
+ END
+ assert_p5_fill src, 'endShape', threshold: THRESHOLD_TO_BE_FIXED
+ assert_p5_stroke src, 'endShape'
+ assert_p5_fill_stroke src, 'endShape', threshold: THRESHOLD_TO_BE_FIXED
+ assert_p5_fill src, 'endShape CLOSE', threshold: THRESHOLD_TO_BE_FIXED
+ assert_p5_stroke src, 'endShape CLOSE'
+ assert_p5_fill_stroke src, 'endShape CLOSE', threshold: THRESHOLD_TO_BE_FIXED
+ end
+
+ def test_contour()
+ src = <<~END
+ beginShape
+ vertex 100, 100
+ vertex 100, 900
+ vertex 900, 900
+ vertex 900, 100
+ beginContour
+ vertex 200, 200
+ vertex 800, 200
+ vertex 700, 700
+ vertex 200, 800
+ endContour
+ END
+ assert_p5_fill src, 'endShape'
+ assert_p5_stroke src, 'endShape'
+ assert_p5_fill_stroke src, 'endShape'
+ assert_p5_fill src, 'endShape CLOSE'
+ assert_p5_stroke src, 'endShape CLOSE'
+ assert_p5_fill_stroke src, 'endShape CLOSE'
+ end
+
+ def test_pixels()
+ g = graphics 2, 2
+
+ g.loadPixels
+ assert_equal [0] * 4, g.pixels
+ assert_equal [0] * 4, g.getInternal__.pixels
+
+ g.pixels.replace [0xffff0000, 0xff00ff00, 0xff0000ff, 0xff000000]
+ assert_equal [0xffff0000, 0xff00ff00, 0xff0000ff, 0xff000000], g.pixels
+ assert_equal [0] * 4, g.getInternal__.pixels
+
+ g.updatePixels
+ assert_nil g.pixels
+ assert_equal [0xffff0000, 0xff00ff00, 0xff0000ff, 0xff000000], g.getInternal__.pixels
+ assert_nothing_raised {g.updatePixels}
+
+ g.loadPixels
+ g.pixels.replace [0xff000000]
+ assert_raise(ArgumentError) {g.updatePixels}
+ end
+
def test_lerp()
g = graphics
assert_equal 1.0, g.lerp(1.0, 2.0, 0.0)
assert_equal 1.5, g.lerp(1.0, 2.0, 0.5)
@@ -487,9 +697,19 @@
assert_equal c[30, 40, 50], g.lerpColor(c[10, 20, 30], c[50, 60, 70], 0.5)
assert_equal c[50, 60, 70], g.lerpColor(c[10, 20, 30], c[50, 60, 70], 1.0)
assert_equal c[-10, 0, 10], g.lerpColor(c[10, 20, 30], c[50, 60, 70], -0.5)
assert_equal c[ 70, 80, 90], g.lerpColor(c[10, 20, 30], c[50, 60, 70], 1.5)
+ end
+
+ def test_createFont()
+ g = graphics
+
+ assert_not_nil g.createFont(nil, nil).getInternal__.name
+ assert_equal 'Arial', g.createFont('Arial', nil).getInternal__.name
+
+ assert_equal 12, g.createFont(nil, nil).getInternal__.size
+ assert_equal 10, g.createFont(nil, 10) .getInternal__.size
end
def test_createShape_line()
assert_equal_draw <<~EXPECTED, <<~ACTUAL
line 100, 200, 800, 900