File size: 1,368 Bytes
b516e00 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import pytest
from naramotion import Path, Matrix2D, FillRule, Image, Context, Format
def test_path_basic_verbs():
p = Path()
assert p.is_empty()
p.move_to(0, 0)
p.line_to(100, 0)
p.line_to(100, 100)
p.close()
assert not p.is_empty()
assert p.size > 0
bounds = p.get_bounds()
assert bounds.x0 == 0.0
assert bounds.y0 == 0.0
assert bounds.x1 == 100.0
assert bounds.y1 == 100.0
def test_path_hit_test():
p = Path()
p.add_rect(10, 10, 80, 80)
assert p.hit_test(50, 50, FillRule.NON_ZERO) is True
assert p.hit_test(5, 5, FillRule.NON_ZERO) is False
assert p.hit_test(150, 150, FillRule.NON_ZERO) is False
def test_path_transform():
p = Path()
p.add_rect(0, 0, 50, 50)
m = Matrix2D.make_translation(100, 200)
p.transform(m)
bounds = p.get_bounds()
assert bounds.x0 == 100.0
assert bounds.y0 == 200.0
assert bounds.x1 == 150.0
assert bounds.y1 == 250.0
def test_path_render():
img = Image(300, 300, Format.PRGB32)
with Context(img) as ctx:
p = Path()
p.move_to(50, 50)
p.cubic_to(100, 0, 200, 150, 250, 50)
p.quad_to(200, 250, 50, 50)
p.close()
ctx.fill_path(p, "coral")
ctx.stroke_width = 4.0
ctx.stroke_path(p, "navy")
|