From 903767f1126a7010e3c5a60bfc5ba576fb675154 Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Mon, 15 Apr 2013 23:11:26 +0200 Subject: [PATCH] line: fix cython exception when calculating ellipse/circle if segments % 2 == 1. closes #1115 --- examples/canvas/lines_extended.py | 16 ++++++++++++++++ kivy/graphics/vertex_instructions_line.pxi | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/examples/canvas/lines_extended.py b/examples/canvas/lines_extended.py index 05970079c7..ec1c649e4f 100644 --- a/examples/canvas/lines_extended.py +++ b/examples/canvas/lines_extended.py @@ -73,6 +73,18 @@ text: 'Circle from 90 to 180\\n10 segments' halign: 'center' +: + canvas: + Color: + rgba: .1, 1, .1, .9 + Line: + width: 2. + circle: (self.center_x, self.center_y, min(self.width, self.height) / 2, 0, 360) + Label: + center: root.center + text: 'Circle from 0 to 360' + halign: 'center' + : canvas: Color: @@ -118,6 +130,9 @@ class LineCircle2(Widget): class LineCircle3(Widget): pass +class LineCircle4(Widget): + pass + class LineRectangle(Widget): pass @@ -133,6 +148,7 @@ def build(self): root.add_widget(LineCircle1()) root.add_widget(LineCircle2()) root.add_widget(LineCircle3()) + root.add_widget(LineCircle4()) root.add_widget(LineRectangle()) root.add_widget(LineBezier()) return root diff --git a/kivy/graphics/vertex_instructions_line.pxi b/kivy/graphics/vertex_instructions_line.pxi index d858c1f923..edec2ef87c 100644 --- a/kivy/graphics/vertex_instructions_line.pxi +++ b/kivy/graphics/vertex_instructions_line.pxi @@ -869,6 +869,8 @@ cdef class Line(VertexInstruction): angle_dir = -1 if segments == 0: segments = int(abs(angle_end - angle_start) / 2) + 3 + if segments % 2 == 1: + segments += 1 # rad = deg * (pi / 180), where pi/180 = 0.0174... angle_start = angle_start * 0.017453292519943295 angle_end = angle_end * 0.017453292519943295 @@ -949,6 +951,8 @@ cdef class Line(VertexInstruction): angle_dir = -1 if segments == 0: segments = int(abs(angle_end - angle_start) / 2) + 3 + if segments % 2 == 1: + segments += 1 # rad = deg * (pi / 180), where pi/180 = 0.0174... angle_start = angle_start * 0.017453292519943295 angle_end = angle_end * 0.017453292519943295