`Line`/`SmoothLine` - `ellipse`: Handle the number of segments to match `Ellipse` (#8187)

This commit is contained in:
Dexer 2023-03-28 14:34:41 -03:00 committed by GitHub
parent f0786c4e42
commit 34f2edb8fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 3 deletions

View File

@ -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