Skip to content

Commit

Permalink
Add a check for proper contour calls
Browse files Browse the repository at this point in the history
  • Loading branch information
tushar5526 committed Aug 1, 2022
1 parent dd98735 commit 99a4aa2
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions p5/core/vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
is_curve = False
is_quadratic = False
is_contour = False
has_contour = False
is_first_contour = True

__all__ = ['begin_shape', 'end_shape', 'begin_contour', 'end_contour',
Expand All @@ -47,11 +48,11 @@ def begin_shape(kind=TESS):
:param kind: TESS, POINTS, LINES, TRIANGLES, TRIANGLE_FAN, TRIANGLE_STRIP, QUADS, or QUAD_STRIP; defaults to TESS
:type kind: SType
"""
global shape_kind, vertices, contour_vertices, vertices_types, contour_vertices_types, is_contour
global shape_kind, vertices, contour_vertices, vertices_types, contour_vertices_types, has_contour
global curr_contour_vertices, curr_contour_vertices_types

shape_kind = kind
is_contour = False
has_contour = False
vertices = []
vertices_types = []
contour_vertices = []
Expand Down Expand Up @@ -88,7 +89,7 @@ def curve_vertex(x, y, z=0):
if p5.mode == "3D":
return
if builtins.current_renderer == 'vispy':
if is_contour:
if has_contour:
curr_contour_vertices.append((x, y, z))
curr_contour_vertices_types.append(2)
else:
Expand Down Expand Up @@ -126,15 +127,15 @@ def bezier_vertex(x2, y2, x3, y3, x4, y4):
if p5.mode == "3D":
return
if builtins.current_renderer == 'vispy':
if is_contour:
if has_contour:
curr_contour_vertices.append((x2, y2, x3, y3, x4, y4))
curr_contour_vertices_types.append(3)
else:
vertices.append((x2, y2, x3, y3, x4, y4))
vertices_types.append(3)
elif builtins.current_renderer == 'skia':
vert_data = [x2, y2, x3, y3, x4, y4, {"is_vert": False}]
if is_contour:
if has_contour:
contour_vertices.append(vert_data)
else:
vertices.append(vert_data)
Expand Down Expand Up @@ -164,15 +165,15 @@ def quadratic_vertex(cx, cy, x3, y3):
is_quadratic = True

if builtins.current_renderer == 'vispy':
if is_contour:
if has_contour:
curr_contour_vertices.append((cx, cy, x3, y3))
curr_contour_vertices_types.append(4)
else:
vertices.append((cx, cy, x3, y3))
vertices_types.append(3)
elif builtins.current_renderer == 'skia':
vert_data = [cx, cy, x3, y3, {"is_vert": False}]
if is_contour:
if has_contour:
contour_vertices.append(vert_data)
else:
vertices.append(vert_data)
Expand All @@ -198,7 +199,7 @@ def vertex(x, y, z=0):
if p5.mode == "3D":
return
if builtins.current_renderer == 'vispy':
if is_contour:
if has_contour:
curr_contour_vertices.append((x, y, z))
curr_contour_vertices_types.append(1)
else:
Expand All @@ -209,7 +210,7 @@ def vertex(x, y, z=0):
tuple(255 * c for c in p5.renderer.style.stroke_color), {}]
vert_data[-1]["is_vert"] = True

if is_contour:
if has_contour:
if len(contour_vertices) == 0:
vert_data[-1]["move_to"] = True
contour_vertices.append(vert_data)
Expand All @@ -229,7 +230,8 @@ def begin_contour():
for internal shapes, draw vertices shape in counter-clockwise.
"""
global is_contour, contour_vertices, contour_vertices_types
global has_contour, contour_vertices, contour_vertices_types, has_contour, is_contour
has_contour = True
is_contour = True
contour_vertices = []
contour_vertices_types = []
Expand All @@ -240,7 +242,8 @@ def end_contour():
For more info, see :any:`begin_contour`.
"""
global is_contour, curr_contour_vertices, curr_contour_vertices_types, is_first_contour
global has_contour, curr_contour_vertices, curr_contour_vertices_types, is_first_contour, has_contour, is_contour
is_contour = False

if builtins.current_renderer == 'vispy':
# Close contour
Expand Down Expand Up @@ -355,10 +358,10 @@ def end_shape(mode=""):
:type mode: str
"""
global is_bezier, is_curve, is_quadratic, is_contour, is_first_contour
global is_bezier, is_curve, is_quadratic, has_contour, is_first_contour, has_contour, is_contour
if is_curve or is_bezier or is_quadratic:
assert shape_kind == TESS, "Should not specify primitive type for a curve"

assert not is_contour, "begin_contour called without calling end_contour"
if len(vertices) == 0:
return

Expand Down Expand Up @@ -396,15 +399,15 @@ def end_shape(mode=""):

elif builtins.current_renderer == 'skia':
close_shape = mode == 'CLOSE'
if close_shape and not is_contour:
if close_shape and not has_contour:
vertices.append(vertices[0])
p5.renderer.end_shape(mode, vertices, is_curve, is_bezier, is_quadratic, is_contour,
p5.renderer.end_shape(mode, vertices, is_curve, is_bezier, is_quadratic, has_contour,
None if shape_kind == TESS else shape_kind)
if close_shape:
vertices.pop()

is_bezier = False
is_curve = False
is_quadratic = False
is_contour = False
has_contour = False
is_first_contour = True

0 comments on commit 99a4aa2

Please sign in to comment.