本文整理汇总了Python中block.Block.get_middle方法的典型用法代码示例。如果您正苦于以下问题:Python Block.get_middle方法的具体用法?Python Block.get_middle怎么用?Python Block.get_middle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类block.Block
的用法示例。
在下文中一共展示了Block.get_middle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_main_line
# 需要导入模块: from block import Block [as 别名]
# 或者: from block.Block import get_middle [as 别名]
def get_main_line(self):
blocks = self.get_blocks()
if len(blocks) == 0:
block = Block(self.img_width / 2, self.img_width / 2, min(1, self.img_height), min(1, self.img_height))
self.add_block(block)
return Line(block,
Block(self.img_width / 2, self.img_width / 2, 0, 0))
elif len(blocks) == 1:
return Line(blocks[0], Block(blocks[0].get_middle()[0],blocks[0].get_middle()[0],0,0))
else:
blocks = []
next_block = None
prev_block = Block(self.get_img_width() / 2, self.get_img_width() / 2, self.get_img_height(),
self.get_img_height())
for block in self.get_blocks():
if block != prev_block and (next_block is None or
(block.distance_from(prev_block) < next_block.distance_from(prev_block))):
next_block = block
blocks.append(next_block)
while True:
prev_block = blocks[-1]
blocks_in_range = []
for block in self.get_blocks():
if block.distance_from(prev_block) < Image.dist_threshold \
and block not in blocks and block.get_middle()[1] <= prev_block.get_middle()[1]: # TODO: lijn die terugkeert ondersteunen
blocks_in_range.append(block)
if len(blocks_in_range) == 0:
break
elif len(blocks)>1:
rico = get_rico(blocks[-2],blocks[-1])
else:
rico = -10000
smallest_dif = math.pi/2.2 #we do not want anything behind us
next_block = None
for block in blocks_in_range:
current_diff = Image.calculate_diff(math.atan(get_rico(prev_block, block)), math.atan(rico))
if current_diff < smallest_dif:
smallest_dif = current_diff
next_block = block
if next_block is None:
break
else:
blocks.append(next_block)
try:
x = (-blocks[-1].get_middle()[1])/get_rico(blocks[0],blocks[-1])+blocks[-1].get_middle()[0]
blocks.append(Block(x,x,0,0))
except ZeroDivisionError:
print get_rico(blocks[0],blocks[-1])
print blocks
print "-----------STOP---------------------------------------------------------------"
return Line(*blocks)