Use char type for circle_perimeter method for speedup

This commit is contained in:
Johannes Schönberger
2013-01-13 11:44:09 +01:00
parent 075c43109a
commit 70825a420e
+5 -2
View File
@@ -231,10 +231,13 @@ def circle_perimeter(int cy, int cx, int radius, method='bresenham'):
cdef int x = 0
cdef int y = radius
cdef int d = 0
cdef char cmethod
if method == 'bresenham':
d = 3 - 2 * radius
cmethod = 'b'
elif method == 'andres':
d = radius - 1
cmethod = 'a'
else:
raise ValueError('Wrong method')
@@ -242,14 +245,14 @@ def circle_perimeter(int cy, int cx, int radius, method='bresenham'):
rr.extend([y, -y, y, -y, x, -x, x, -x])
cc.extend([x, x, -x, -x, y, y, -y, -y])
if method == 'bresenham':
if cmethod == 'b':
if d < 0:
d += 4 * x + 6
else:
d += 4 * (x - y) + 10
y -= 1
x += 1
elif method == 'andres':
elif cmethod == 'a':
if d >= 2 * (x - 1):
d = d - 2 * x
x = x + 1