Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. class Collection:
  2.     [...]
  3.    
  4.     # Vérifie si un point appartient à la collection
  5.     #
  6.     # -?-
  7.     # [Point] point:    Point à tester
  8.     # -!-
  9.     # [bool]
  10.     # -$-
  11.     # [TypeError]       ! -?-
  12.     def appartient( self, point ):
  13.         if( not isinstance( point, Point ) ):
  14.             raise TypeError( '<point> n\'est pas une instance de [Point] !' )
  15.  
  16.         for pointCourant in self.liste:
  17.             distance = point.distance( pointCourant )
  18.  
  19.             if( distance < 0.00001 ):
  20.                 return True
  21.         return False
  22.        
  23.     # Trie la collection
  24.     def trier( self ):
  25.         resultat = list()
  26.         liste = list( self.liste )
  27.  
  28.         while len( liste ):
  29.             # Recherche du plus petit
  30.             indiceMini = 0
  31.  
  32.             for indice in xrange( len( liste ) ):
  33.                 if( liste[indice].inf_ou_egal( liste[indiceMini] ) ):
  34.                     indiceMini = indice
  35.  
  36.             resultat.append( liste.pop( indiceMini ) )
  37.  
  38.         self.liste = resultat
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement