Skip to content

Commit

Permalink
defince methods using cpdef
Browse files Browse the repository at this point in the history
other minor changes style
  • Loading branch information
hansent committed Sep 25, 2012
1 parent 819e624 commit 1c2f13e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
25 changes: 14 additions & 11 deletions src/cdt.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,36 @@ cdef class CDT:
cdef c_CDT *me
cdef point_vec polyline

def __init__(self, list polyline):
def __cinit__(self, list polyline=None):
self.polyline = pointvec_factory(0)
for point in polyline:
self.polyline.push_back(new_Point(point.x, point.y))
if polyline:
for point in polyline:
self.polyline.push_back(new_Point(point.x, point.y))
self.me = new_CDT(self.polyline)

def triangulate(self):

cpdef triangulate(self):
cdef Point a,b,c
cdef list triangles = []
self.me.Triangulate()
cdef triangle_vec tri_list = self.me.GetTriangles()
cdef list tris = []
for i in range(tri_list.size()):
cdef int num_triangles = tri_list.size()
for i in range(num_triangles):
a = Point(tri_list.get(i).GetPoint(0).x, tri_list.get(i).GetPoint(0).y)
b = Point(tri_list.get(i).GetPoint(1).x, tri_list.get(i).GetPoint(1).y)
c = Point(tri_list.get(i).GetPoint(2).x, tri_list.get(i).GetPoint(2).y)
tris.append(Triangle(a, b, c))
return tris
triangles.append(Triangle(a, b, c))
return triangles

def add_hole(self, polyline):
cpdef add_hole(self, polyline):
cdef point_vec hole = pointvec_factory(0)
for point in polyline:
hole.push_back(new_Point(point.x, point.y))
self.me.AddHole(hole)

def add_point(self, point):
cpdef add_point(self, point):
cdef c_Point* p = new_Point(point.x, point.y)
self.me.AddPoint(p)

def __dealloc__(self):
del_CDT(self.me)
del_CDT(self.me)
13 changes: 5 additions & 8 deletions src/shapes.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ cdef class Point:
def __get__(self): return self.y
def __set__(self, y): self.y = y

def debug_print(self):
print "(" + str(self.x) + ", " + str(self.y) + ")",
def __str__(self):
return "Point({self.x}, {self.y})".format(self=self)

cdef class Triangle:

Expand All @@ -35,9 +35,6 @@ cdef class Triangle:
property c:
def __get__(self): return self.c

def debug_print(self):
self.a.debug_print()
self.b.debug_print()
self.c.debug_print()
print

def __str__(self):
return "Triangle({self.a}, {self.b}, {self.c})".format(self=self)

0 comments on commit 1c2f13e

Please sign in to comment.