diff options
Diffstat (limited to 'docs/examples/userguide/early_binding_for_speed/rectangle_cdef.pyx')
-rw-r--r-- | docs/examples/userguide/early_binding_for_speed/rectangle_cdef.pyx | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/docs/examples/userguide/early_binding_for_speed/rectangle_cdef.pyx b/docs/examples/userguide/early_binding_for_speed/rectangle_cdef.pyx index 5502b4568..3b64d766b 100644 --- a/docs/examples/userguide/early_binding_for_speed/rectangle_cdef.pyx +++ b/docs/examples/userguide/early_binding_for_speed/rectangle_cdef.pyx @@ -1,22 +1,26 @@ -cdef class Rectangle:
- cdef int x0, y0
- cdef int x1, y1
-
- def __init__(self, int x0, int y0, int x1, int y1):
- self.x0 = x0
- self.y0 = y0
- self.x1 = x1
- self.y1 = y1
-
- cdef int _area(self):
- area = (self.x1 - self.x0) * (self.y1 - self.y0)
- if area < 0:
- area = -area
- return area
-
- def area(self):
- return self._area()
-
-def rectArea(x0, y0, x1, y1):
- rect = Rectangle(x0, y0, x1, y1)
- return rect.area()
+ +cdef class Rectangle: + cdef int x0, y0 + cdef int x1, y1 + + + + def __init__(self, int x0, int y0, int x1, int y1): + self.x0 = x0 + self.y0 = y0 + self.x1 = x1 + self.y1 = y1 + + + cdef int _area(self): + cdef int area = (self.x1 - self.x0) * (self.y1 - self.y0) + if area < 0: + area = -area + return area + + def area(self): + return self._area() + +def rectArea(x0, y0, x1, y1): + cdef Rectangle rect = Rectangle(x0, y0, x1, y1) + return rect._area() |