This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via 7c4bb66768b4757c3944e0d99e6ba5fb3060fcee (commit) via 2de090f680f9cba9f40a1516a231db982880e928 (commit) via 8fffa8a364bdde37f5401f6c3b7250520721b76f (commit) from 029e3ccf2b47c2d3c884aa6e2be2c7fa6231433c (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/7c4bb66768b4757c3944e0d99e6ba5fb3060f...
commit 7c4bb66768b4757c3944e0d99e6ba5fb3060fcee Author: Tomas Gavenciak gavento@ucw.cz Date: Mon Jan 28 19:48:54 2013 +0100
pylib: test: tests for Polygon and FillPolygon
diff --git a/tests/pylib/test_gfx.py b/tests/pylib/test_gfx.py index 784dce1..9b854cb 100644 --- a/tests/pylib/test_gfx.py +++ b/tests/pylib/test_gfx.py @@ -4,18 +4,18 @@ from unittest import SkipTest from testutils import *
from gfxprim.core import Context -from gfxprim import gfx +from gfxprim import gfx, core
def test_gfx_submodule_loads(): "gfx is present in a Context" - c = Context(1, 1, 1) + c = Context(1, 1, core.C.PIXEL_RGB888) assert c.gfx
def test_gfx_submodule_has_C(): "gfx contains C" - c = Context(1, 1, 1) + c = Context(1, 1, core.C.PIXEL_RGB888) assert c.gfx.C assert gfx.C
@@ -53,7 +53,7 @@ gfx_params = {
def test_all_methods_are_known(): "All methods of gfx submodule have known param types in this test" - c = Context(1, 1, 1) + c = Context(1, 1, core.C.PIXEL_RGB888) for name in dir(c.gfx): if name[0] != '_' and name not in ['C', 'ctx']: assert name in gfx_params @@ -85,12 +85,33 @@ def gen_dummy_args(params): return tuple(args)
@for_each_case(gfx_params) -def test_method_callable(n, params): - "Call with dummy parameters" - c = Context(10, 10, 1) +def test_method_call(n, params): + "Calling with dummy parameters:" + c = ContextRand(10, 10, core.C.PIXEL_RGB888) if isinstance(params, str): c.gfx.__getattribute__(n)(*gen_dummy_args(params)) else: assert isinstance(params, tuple) and isinstance(params[-1], dict) c.gfx.__getattribute__(n)(*params[:-1], **params[-1])
+def test_Polygon(): + "Polygon() works" + c0 = ContextRand(13, 12, core.C.PIXEL_RGB888, seed=42) + c1 = ContextRand(13, 12, core.C.PIXEL_RGB888, seed=42) + c2 = ContextRand(13, 12, core.C.PIXEL_RGB888, seed=42) + assert c1 == c0 + c1.gfx.Polygon([1,2,0,4,7,9,5,4,3,2], 43) + c2.gfx.Polygon([(1,2),(0,4),(7,9),(5,4),(3,2)], 43) + assert c1 == c2 + assert c1 != c0 + +def test_FillPolygon(): + "FillPolygon() works" + c0 = ContextRand(13, 9, core.C.PIXEL_RGB888, seed=41) + c1 = ContextRand(13, 9, core.C.PIXEL_RGB888, seed=41) + c2 = ContextRand(13, 9, core.C.PIXEL_RGB888, seed=41) + assert c1 == c0 + c1.gfx.FillPolygon([1,2,0,4,7,9,5,4,3,2], 0) + c2.gfx.FillPolygon([(1,2),(0,4),(7,9),(5,4),(3,2)], 0) + assert c1 == c2 + assert c1 != c0
http://repo.or.cz/w/gfxprim.git/commit/2de090f680f9cba9f40a1516a231db982880e...
commit 2de090f680f9cba9f40a1516a231db982880e928 Author: Tomas Gavenciak gavento@ucw.cz Date: Mon Jan 28 19:46:22 2013 +0100
pywrap: gfx: implement [Fill]Polygon interface
diff --git a/pylib/gfxprim/gfx/__init__.py b/pylib/gfxprim/gfx/__init__.py index 62ce4f0..f7fe741 100644 --- a/pylib/gfxprim/gfx/__init__.py +++ b/pylib/gfxprim/gfx/__init__.py @@ -42,12 +42,45 @@ def _init(module):
for name in [ 'ArcSegment', 'Circle', 'Ellipse', 'Fill', 'FillCircle', 'FillEllipse', - 'FillPolygon', 'FillRect', 'FillRect_AA', 'FillRing', 'FillSymbol', + 'FillRect', 'FillRect_AA', 'FillRing', 'FillSymbol', 'FillTetragon', 'FillTriangle', 'HLine', 'HLineAA', 'Line', 'LineAA', - 'Polygon', 'PutPixelAA', 'Rect', 'Ring', 'Symbol', 'Tetragon', + 'PutPixelAA', 'Rect', 'Ring', 'Symbol', 'Tetragon', 'Triangle', 'VLine', 'VLineAA']: extend_submodule(GfxSubmodule, name, c_gfx.__getattribute__('GP_' + name))
+ def flatten_coords(points): + "Helper for Polygon and FillPolygon coordinates" + l = [] + for p in points: + if hasattr(p, '__iter__'): + l.extend(p) + else: + l.append(p) + for i in l: + assert isinstance(i, int) + return tuple(l) + + @extend(GfxSubmodule) + def Polygon(self, points, pixel): + """ + Polygon(context, coordinates, pixel) + + Draw a polygon with color `pixel`. + `coordinates` is either an iterable of `int` coordinates `(x0, y0, x1, y1, ...)` + or an iterable of tuples `[(x0, y0), (x1, y1), ...]`. + """ + c_gfx.GP_Polygon_wrap(self.ctx, flatten_coords(points), pixel) + + @extend(GfxSubmodule) + def FillPolygon(self, points, pixel): + """ + FillPolygon(context, coordinates, pixel) + + Draw a filled polygon with color `pixel`. + `coordinates` is either an iterable of `int` coordinates `(x0, y0, x1, y1, ...)` + or an iterable of tuples `[(x0, y0), (x1, y1), ...]`. + """ + c_gfx.GP_FillPolygon_wrap(self.ctx, flatten_coords(points), pixel)
_init(locals()) del _init diff --git a/pylib/gfxprim/gfx/gfx.i b/pylib/gfxprim/gfx/gfx.i index 881d2ca..9d3b0c4 100644 --- a/pylib/gfxprim/gfx/gfx.i +++ b/pylib/gfxprim/gfx/gfx.i @@ -30,3 +30,38 @@ %include "GP_LineAA.h" %include "GP_RectAA.h"
+%inline %{ +static GP_Coord *GP_Polygon_unpack_coordinates(PyObject *coords) +{ + unsigned int i, vertex_count; + GP_Coord *cs; + + GP_ASSERT(PyTuple_Check(coords)); + vertex_count = PyTuple_Size(coords); + GP_ASSERT(vertex_count % 2 == 0); + cs = malloc(sizeof(GP_Coord[vertex_count])); + GP_ASSERT(cs != NULL); + for (i = 0; i < vertex_count; i++) { + PyObject *e = PyTuple_GetItem(coords, i); // Borrowed or ? + GP_ASSERT(PyInt_Check(e)); + cs[i] = PyInt_AsLong(e); + } + return cs; +} + +void GP_Polygon_wrap(GP_Context *context, PyObject *coords, GP_Pixel pixel) +{ + GP_Coord *cs = GP_Polygon_unpack_coordinates(coords); + GP_Polygon(context, PyTuple_Size(coords) / 2, cs, pixel); + free(cs); +} + +void GP_FillPolygon_wrap(GP_Context *context, PyObject *coords, GP_Pixel pixel) +{ + GP_Coord *cs = GP_Polygon_unpack_coordinates(coords); + GP_FillPolygon(context, PyTuple_Size(coords) / 2, cs, pixel); + free(cs); +} +%} + +
http://repo.or.cz/w/gfxprim.git/commit/8fffa8a364bdde37f5401f6c3b7250520721b...
commit 8fffa8a364bdde37f5401f6c3b7250520721b76f Author: Tomas Gavenciak gavento@ucw.cz Date: Mon Jan 28 15:58:56 2013 +0100
pylib: test: Fix Py3 syntax, improve filter gens.
diff --git a/tests/pylib/test_gfx.py b/tests/pylib/test_gfx.py index e502e22..784dce1 100644 --- a/tests/pylib/test_gfx.py +++ b/tests/pylib/test_gfx.py @@ -28,7 +28,7 @@ gfx_params = { 'Fill': 'P', 'FillCircle': 'IIIP', 'FillEllipse': 'IIIIP', - 'FillPolygon': None, + 'FillPolygon': ([(0,0),(1,1),(1,0)], 0, {}), 'FillRect': 'IIIIP', 'FillRect_AA': 'FFFFP', 'FillRing': 'IIIIP', @@ -39,7 +39,7 @@ gfx_params = { 'HLineAA': 'FFFP', 'Line': 'IIIIP', 'LineAA': 'FFFFP', - 'Polygon': None, + 'Polygon': ([(0,0),(1,1),(1,0)], 0, {}), 'PutPixelAA': 'FFP', 'Rect': 'IIIIP', 'Ring': 'IIIIP', @@ -84,9 +84,13 @@ def gen_dummy_args(params): assert False return tuple(args)
-@for_each_case(gfx_params, _filter=(lambda(n, params): params is not None)) +@for_each_case(gfx_params) def test_method_callable(n, params): "Call with dummy parameters" c = Context(10, 10, 1) - c.gfx.__getattribute__(n)(*gen_dummy_args(params)) + if isinstance(params, str): + c.gfx.__getattribute__(n)(*gen_dummy_args(params)) + else: + assert isinstance(params, tuple) and isinstance(params[-1], dict) + c.gfx.__getattribute__(n)(*params[:-1], **params[-1])
diff --git a/tests/pylib/testutils.py b/tests/pylib/testutils.py index 6c7ee5f..8c1badc 100644 --- a/tests/pylib/testutils.py +++ b/tests/pylib/testutils.py @@ -12,23 +12,21 @@ def alltypes(_filter=None): """ Creates one test for each PixelType (except INVALID). The pixeltype is given to the test function and the name - is appended to its name and docstring. + is appended to its name and is mentioned in the new docstring. """ - flt = lambda n, t: _filter(t) - return for_each_case(dict([(t.name, t) for t in core.PixelTypes[1:]]), - givename=False, _filter=(flt if _filter else None)) + if _filter is None: + _filter = lambda x: True + cases = dict([(t.name, t) for t in core.PixelTypes[1:] if _filter(t)]) + return for_each_case(cases, givename=False)
-def for_each_case(cases, givename=True, _filter=None): +def for_each_case(cases, givename=True): """ Creates one test for each of `cases`.
Cases is either list of strings or or string dict (with any values). The test is then given (name) for list or (name, value) for dict, or just (value) if givename=False. - - Optional _filter is called with (name) or (name, value) for dict to - determine which values to use (ret. True -> include). """ def decorate(f): for n in cases:
-----------------------------------------------------------------------
Summary of changes: pylib/gfxprim/gfx/__init__.py | 37 ++++++++++++++++++++++++++++++- pylib/gfxprim/gfx/gfx.i | 35 ++++++++++++++++++++++++++++++ tests/pylib/test_gfx.py | 47 +++++++++++++++++++++++++++++++--------- tests/pylib/testutils.py | 14 +++++------- 4 files changed, 112 insertions(+), 21 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.