11import pygame
22from pygame .locals import *
33
4- from py2d .Math import *
4+ import py2d .Math
55import py2d .examples .Main
66
77class Decompose (py2d .examples .Main .Example ):
@@ -31,7 +31,7 @@ def __init__(self, runner):
3131 self .runner = runner
3232 self .title = "Polygon Decomposition"
3333
34- self .polys = [Polygon () for i in range (10 )]
34+ self .polys = [py2d . Math . Polygon () for i in range (10 )]
3535 self .active_poly = 0
3636
3737 self .decomp = []
@@ -96,7 +96,7 @@ def draw_poly(self, poly, color, fill):
9696 def mouse_down (self , pos , button ):
9797 if button == 1 :
9898
99- self .polys [self .active_poly ].add_point (Vector (pos [0 ], pos [1 ]))
99+ self .polys [self .active_poly ].add_point (py2d . Math . Vector (pos [0 ], pos [1 ]))
100100
101101 self .update_decomp ()
102102
@@ -109,7 +109,7 @@ def update_decomp(self):
109109 def debug_point (p ,c ,t ):
110110 self .debug_points .append ((p ,c ,t ))
111111
112- self .decomp = Polygon .convex_decompose (self .polys [0 ], holes , debug_callback = debug_point )
112+ self .decomp = py2d . Math . Polygon .convex_decompose (self .polys [0 ], holes , debug_callback = debug_point )
113113 else :
114114 self .decomp = []
115115
@@ -135,7 +135,7 @@ class Offset(py2d.examples.Main.Example):
135135 def __init__ (self , runner ):
136136 self .runner = runner
137137 self .title = "Polygon Offset"
138- self .poly = Polygon ()
138+ self .poly = py2d . Math . Polygon ()
139139
140140 self .update_offset ()
141141
@@ -212,7 +212,7 @@ def draw_poly(self, poly, color):
212212
213213 def mouse_down (self , pos , button ):
214214 if button == 1 :
215- self .poly .add_point (Vector (pos [0 ], pos [1 ]))
215+ self .poly .add_point ([ py2d . Math . Vector (pos [0 ], pos [1 ])] )
216216 self .update_offset ()
217217
218218 def update_offset (self ):
@@ -223,8 +223,8 @@ def debug_point(color):
223223 return lambda p , c , t : self .debug_points .append ((p ,color ,t ))
224224
225225 if len (self .poly ) > 2 :
226- self .shrink = Polygon .offset ([self .poly .clone_ccw ()], - self .amount , self .tip_decorator , debug_callback = debug_point ((255 ,0 ,0 )))
227- self .grow = Polygon .offset ([self .poly .clone_ccw ()], self .amount , self .tip_decorator , debug_callback = debug_point ((0 ,255 ,0 )))
226+ self .shrink = py2d . Math . Polygon .offset ([self .poly .clone_ccw ()], - self .amount , self .tip_decorator , debug_callback = debug_point ((255 ,0 ,0 )))
227+ self .grow = py2d . Math . Polygon .offset ([self .poly .clone_ccw ()], self .amount , self .tip_decorator , debug_callback = debug_point ((0 ,255 ,0 )))
228228 else :
229229 self .shrink = []
230230 self .grow = []
@@ -259,11 +259,11 @@ def __init__(self, runner):
259259 self .title = "Boolean Operations"
260260
261261
262- #self.poly_a = Polygon.from_tuples([(0,0), (4,0), (4,4), (0, 4)])
263- #self.poly_b = Polygon.from_tuples([(2,2), (3,6), (1,6)])
262+ #self.poly_a = py2d.Math. Polygon.from_tuples([(0,0), (4,0), (4,4), (0, 4)])
263+ #self.poly_b = py2d.Math. Polygon.from_tuples([(2,2), (3,6), (1,6)])
264264
265- self .poly_a = Polygon ()
266- self .poly_b = Polygon ()
265+ self .poly_a = py2d . Math . Polygon ()
266+ self .poly_b = py2d . Math . Polygon ()
267267
268268 self .active_poly = True
269269 self .bool = []
@@ -335,16 +335,16 @@ def draw_poly(self, poly, color):
335335 def mouse_down (self , pos , button ):
336336 if button == 1 :
337337 if self .active_poly :
338- self .poly_a .add_point (Vector (pos [0 ], pos [1 ]))
338+ self .poly_a .add_point (py2d . Math . Vector (pos [0 ], pos [1 ]))
339339 else :
340- self .poly_b .add_point (Vector (pos [0 ], pos [1 ]))
340+ self .poly_b .add_point (py2d . Math . Vector (pos [0 ], pos [1 ]))
341341
342342 self .update_bool ()
343343
344344 def update_bool (self ):
345345 if len (self .poly_a ) > 2 and len (self .poly_b ) > 2 :
346346 try :
347- self .bool = Polygon .boolean_operation (self .poly_a , self .poly_b , self .mode )
347+ self .bool = py2d . Math . Polygon .boolean_operation (self .poly_a , self .poly_b , self .mode )
348348 except IndexError :
349349 self .bool = []
350350 else :
0 commit comments