当前位置: 首页>>代码示例>>Python>>正文


Python Rect.normalize方法代码示例

本文整理汇总了Python中pygame.Rect.normalize方法的典型用法代码示例。如果您正苦于以下问题:Python Rect.normalize方法的具体用法?Python Rect.normalize怎么用?Python Rect.normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygame.Rect的用法示例。


在下文中一共展示了Rect.normalize方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_normalize

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import normalize [as 别名]
 def test_normalize( self ):
     r = Rect( 1, 2, -3, -6 )
     r2 = Rect(r)
     r2.normalize()
     self.failUnless( r2.width >= 0 )
     self.failUnless( r2.height >= 0 )
     self.assertEqual( (abs(r.width),abs(r.height)), r2.size )
     self.assertEqual( (-2,-4), r2.topleft )
开发者ID:CTPUG,项目名称:pygame_cffi,代码行数:10,代码来源:rect_test.py

示例2: get_rect

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import normalize [as 别名]
 def get_rect(*args):
     """Get all points in the described rectangle, inclusive"""
     if args == (None,):
         return []
     rect = Rect(args)
     rect.normalize()
     return [(x, y) for x in xrange(rect.x, rect.x+rect.w)
                    for y in xrange(rect.y, rect.y+rect.h)]
开发者ID:fish-face,项目名称:agutaywusyg,代码行数:10,代码来源:generator.py

示例3: calculateIntersectPoint

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import normalize [as 别名]
def calculateIntersectPoint(p1, p2, p3, p4):
  
   p = getIntersectPoint(p1, p2, p3, p4)
  
   if p is not None:               
       width = p2[0] - p1[0]
       height = p2[1] - p1[1]       
       r1 = Rect(p1, (width , height))
       r1.normalize()
      
       width = p4[0] - p3[0]
       height = p4[1] - p3[1]
       r2 = Rect(p3, (width, height))
       r2.normalize()              
 
       # Ensure both rects have a width and height of at least 'tolerance' else the
       # collidepoint check of the Rect class will fail as it doesn't include the bottom
       # and right hand side 'pixels' of the rectangle
       tolerance = 1
       if r1.width < tolerance:
        r1.width = tolerance
                    
       if r1.height < tolerance:
        r1.height = tolerance
开发者ID:Exodus111,项目名称:Infinite-Adventure,代码行数:26,代码来源:geometry.py

示例4: Controller

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import normalize [as 别名]
class Controller():
    def __init__(self, canvas, parent):
        self.canvas = canvas
        self.parent = parent

        self.objects = OrderedDict()
        self.objects["LOW"] = Low(self)
        self.objects["HIGH"] = High(self)
        
        self.selected = []
        self.select = False
        self.select_start = False
        self.select_rect = Rect(0, 0, 0, 0)
        
        self.possible_move = False
        
        self.pan = False
        self.pan_x = 0
        self.pan_y = 0
        self.pan_offset_x = 0
        self.pan_offset_y = 0

        self.new_node = False
        self.new_node_direction = NODE_DIR_NA

        self.zoom = 1.0
        self.zoom_step = 0.1
             
        self.obj_id = 0
        self.net_id = 0
        
        self.highlight_mode = LIGHT_NONE
        self.highlight_pos = False
        
        self.add_index = 0
        self.add_list = ["label", "and", "or", "nand", "nor", "xor", "not", "diode", "led", "hex", "tgl", "push", "clk", "input", "output", "memory"]
        
        self.font = pygame.font.Font(pygame.font.get_default_font(), int(self.canvas.style["d_font"] * self.zoom))
        self.label_font = pygame.font.Font(pygame.font.get_default_font(), int(self.canvas.style["d_label_font"] * self.zoom))
        
        self.need_solve_drawable = True
        self.drawable = []
        
        self.read_only = True
        
    def highlight(self, mode, pos = False):
        self.highlight_mode = mode
        self.highlight_pos = pos
        self.canvas.request_io_redraw()
        
    def get_obj_id(self):
        self.obj_id += 1
        return self.obj_id
    
    def get_net_id(self):
        self.net_id += 1
        return self.net_id    
        
    def normalize_positons(self):
        big_rect = False
        for k in self.objects:
            o = self.objects[k]
            if not isinstance(o, Invisible):
                if big_rect:
                    big_rect = big_rect.union(o.rect)
                else:
                    big_rect = o.rect
        
        offset_x = big_rect[0]
        offset_y = big_rect[1]
        
        for k in self.objects:
            o = self.objects[k]
            pos_x = o.rect[0] - offset_x
            pos_y = o.rect[1] - offset_y
            o.set_pos(pos_x, pos_y)
        
        
               
    def write_file(self, filename):
        if self.read_only:
            return
        
        lines = ""
        
        self.normalize_positons()
        
#         print "Writing file", filename
        line_n = 0
        for k in self.objects:
            if k in ["HIGH", "LOW"]:
                continue
            o = self.objects[k]
            
            name = o.name
            fcs = o.fcs
            p = o.get_params()
            if p == False:
                continue
            params = " ".join(p)
#.........这里部分代码省略.........
开发者ID:fhorinek,项目名称:pi8bit,代码行数:103,代码来源:controller.py

示例5: intersection_pt

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import normalize [as 别名]
def intersection_pt(p1, p2, p3, p4):
  
	p = getIntersectPoint(p1, p2, p3, p4)
  
	if p is not None:               
		width = p2[0] - p1[0]
		height = p2[1] - p1[1]       
		r1 = Rect(p1, (width , height))
		r1.normalize()

		width = p4[0] - p3[0]
		height = p4[1] - p3[1]
		r2 = Rect(p3, (width, height))
		r2.normalize()              
 
	   # Ensure both rects have a width and height of at least 'tolerance' else the
	   # collidepoint check of the Rect class will fail as it doesn't include the bottom
	   # and right hand side 'pixels' of the rectangle
		tolerance = 1
		if r1.width <tolerance:
			r1.width = tolerance
					
		if r1.height <tolerance:
			r1.height = tolerance
		
		if r2.width <tolerance:
			r2.width = tolerance
					
		if r2.height <tolerance:
			r2.height = tolerance
 
		for point in p:                 
			try:    
				res1 = r1.collidepoint(point)
				res2 = r2.collidepoint(point)
				if res1 and res2:
					point = [int(pp) for pp in point]                                
					return point
			except:
				# sometimes the value in a point are too large for PyGame's Rect class
				str = "point was invalid  ", point                
				print str
				
		# This is the case where the infinately long lines crossed but 
		# the line segments didn't
		return None            
	
	else:
		return None
		
		
# # Test script below...
# if __name__ == "__main__":
 
# 	# line 1 and 2 cross, 1 and 3 don't but would if extended, 2 and 3 are parallel
# 	# line 5 is horizontal, line 4 is vertical
# 	p1 = (1,5)
# 	p2 = (4,7)
	
# 	p3 = (4,5)
# 	p4 = (3,7)
	
# 	p5 = (4,1)
# 	p6 = (3,3)
	
# 	p7 = (3,1)
# 	p8 = (3,10)
	
# 	p9 =  (0,6)
# 	p10 = (5,6)
	
# 	p11 = (472.0, 116.0)
# 	p12 = (542.0, 116.0)  
	
# 	assert None != calculateIntersectPoint(p1, p2, p3, p4), "line 1 line 2 should intersect"
# 	assert None != calculateIntersectPoint(p3, p4, p1, p2), "line 2 line 1 should intersect"
# 	assert None == calculateIntersectPoint(p1, p2, p5, p6), "line 1 line 3 shouldn't intersect"
# 	assert None == calculateIntersectPoint(p3, p4, p5, p6), "line 2 line 3 shouldn't intersect"
# 	assert None != calculateIntersectPoint(p1, p2, p7, p8), "line 1 line 4 should intersect"
# 	assert None != calculateIntersectPoint(p7, p8, p1, p2), "line 4 line 1 should intersect"
# 	assert None != calculateIntersectPoint(p1, p2, p9, p10), "line 1 line 5 should intersect"
# 	assert None != calculateIntersectPoint(p9, p10, p1, p2), "line 5 line 1 should intersect"
# 	assert None != calculateIntersectPoint(p7, p8, p9, p10), "line 4 line 5 should intersect"
# 	assert None != calculateIntersectPoint(p9, p10, p7, p8), "line 5 line 4 should intersect"
	
# 	print "\nSUCCESS! All asserts passed for doLinesIntersect"
开发者ID:manikantareddyd,项目名称:Unsupervised-Learning-Manifolds,代码行数:88,代码来源:geometry.py

示例6: calculateIntersectPoint

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import normalize [as 别名]
# If the point where two lines intersect is inside both line's bounding
# rectangles then the lines intersect. Returns intersect point if the line
# intesect o None if not
def calculateIntersectPoint(points):
    p1 = points[0][0]
    p2 = points[0][1]
    p3 = points[1][0]
    p4 = points[1][1]
  
   p = getIntersectPoint(p1, p2, p3, p4)
  
   if p is not None:               
       width = p2[0] - p1[0]
       height = p2[1] - p1[1]       
       r1 = Rect(p1, (width , height))
       r1.normalize()
      
       width = p4[0] - p3[0]
       height = p4[1] - p3[1]
       r2 = Rect(p3, (width, height))
       r2.normalize()              

       # Ensure both rects have a width and height of at least 'tolerance' else the
       # collidepoint check of the Rect class will fail as it doesn't include the bottom
       # and right hand side 'pixels' of the rectangle
       tolerance = 1
       if r1.width < tolerance:
            r1.width = tolerance
                    
       if r1.height < tolerance:
            r1.height = tolerance
开发者ID:jarriett,项目名称:will-it-fit,代码行数:33,代码来源:geometry.py

示例7: calculateIntersectPoint

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import normalize [as 别名]
def calculateIntersectPoint(p1, p2, p3, p4):

    p = getIntersectPoint(p1, p2, p3, p4)

    if p is not None:
        width = p2[0] - p1[0]
        height = p2[1] - p1[1]
        r1 = Rect(p1, (width, height))
        r1.normalize()

        width = p4[0] - p3[0]
        height = p4[1] - p3[1]
        r2 = Rect(p3, (width, height))
        r2.normalize()

        # Ensure both rects have a width and height of at least 'tolerance' else the
        # collidepoint check of the Rect class will fail as it doesn't include the bottom
        # and right hand side 'pixels' of the rectangle
        tolerance = 1
        if r1.width < tolerance:
            r1.width = tolerance

        if r1.height < tolerance:
            r1.height = tolerance

        if r2.width < tolerance:
            r2.width = tolerance

        if r2.height < tolerance:
            r2.height = tolerance

        for point in p:
            try:
                res1 = r1.collidepoint(point)
                res2 = r2.collidepoint(point)
                if res1 and res2:
                    point = [int(pp) for pp in point]
                    return point
            except:
                # sometimes the value in a point are too large for PyGame's Rect class
                str = "point was invalid  ", point
                print(str)

        # This is the case where the infinately long lines crossed but
        # the line segments didn't
        return None

    else:
        return None
开发者ID:anasazi,项目名称:Swarm-AI---Zombies,代码行数:51,代码来源:geometry.py


注:本文中的pygame.Rect.normalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。