From 34f2edb8feef318c692af6df8ded7391ca5153a8 Mon Sep 17 00:00:00 2001 From: Dexer <73297572+DexerBR@users.noreply.github.com> Date: Tue, 28 Mar 2023 14:34:41 -0300 Subject: [PATCH] `Line`/`SmoothLine` - `ellipse`: Handle the number of segments to match `Ellipse` (#8187) --- kivy/graphics/vertex_instructions_line.pxi | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/kivy/graphics/vertex_instructions_line.pxi b/kivy/graphics/vertex_instructions_line.pxi index b24f03dc7..e712ebe58 100644 --- a/kivy/graphics/vertex_instructions_line.pxi +++ b/kivy/graphics/vertex_instructions_line.pxi @@ -927,7 +927,10 @@ cdef class Line(VertexInstruction): * (optional) angle_start and angle_end are in degree. The default value is 0 and 360. * (optional) segments is the precision of the ellipse. The default - value is calculated from the range between angle. + value is calculated from the range between angle. You can use this + property to create polygons with 3 or more sides. Values smaller than + 3 will not be represented and the number of segments will be + automatically calculated. Note that it's up to you to :attr:`close` or not. If you choose to close, use :attr:`close_mode` to define how the figure @@ -950,6 +953,8 @@ cdef class Line(VertexInstruction): .. versionchanged:: 2.2.0 Now you can get the ellipse generated through the property. + The minimum number of segments allowed is 3. Smaller values will be + ignored and the number of segments will be automatically calculated. ''' def __get__(self): @@ -988,7 +993,9 @@ cdef class Line(VertexInstruction): if 0 in (w, h): return - if segments <= 0: + if segments < 3: + if segments != 0: + Logger.warning(f'{self.__class__.__name__} - ellipse: A minimum of 3 segments is required. The default value will be used instead.') segments = int(abs(angle_end - angle_start) / 2) + extra_segments segments += extra_segments @@ -998,7 +1005,7 @@ cdef class Line(VertexInstruction): angle_dir = 1 else: angle_dir = -1 - + # Resulting ellipse self._ellipse = (x, y, w, h, angle_start, angle_end, segments) # Reset other properties