本文整理汇总了Python中polygon.Polygon.add_line方法的典型用法代码示例。如果您正苦于以下问题:Python Polygon.add_line方法的具体用法?Python Polygon.add_line怎么用?Python Polygon.add_line使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类polygon.Polygon
的用法示例。
在下文中一共展示了Polygon.add_line方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: project
# 需要导入模块: from polygon import Polygon [as 别名]
# 或者: from polygon.Polygon import add_line [as 别名]
def project(self, perspective=False):
p = Polygon()
for line in self.lines:
line2d = line.project(perspective)
p.add_line(line2d)
return p
示例2: PrimitiveParser
# 需要导入模块: from polygon import Polygon [as 别名]
# 或者: from polygon.Polygon import add_line [as 别名]
class PrimitiveParser(object):
def __init__(self):
self.PRIMITIVE_MAP = {
"Line" : self.make_line,
"moveto" : self.move_to,
"lineto" : self.line_to,
"stroke" : self.stroke,
}
self.polygon = Polygon()
self.pen = None
def parse(self, string):
parts = string.split(" ")
definition = parts[:-1]
identifier = parts[-1].strip()
if identifier in self.PRIMITIVE_MAP:
return self.PRIMITIVE_MAP[identifier](definition)
else:
raise RuntimeError("NotImplemented Error: Primitive [%s]" % identifier)
def make_line(self, parts):
parts = [int(p) for p in parts[:4]]
p1 = Point([parts[0], parts[1]])
p2 = Point([parts[2], parts[3]])
return Line(p1, p2)
def move_to(self, parts):
x, y = [int(c) for c in parts[0:2]]
self.pen = Point([x, y])
return None
def line_to(self, parts):
assert(self.pen is not None)
last_point = self.pen
self.move_to(parts)
current_point = self.pen
line = Line(last_point, current_point)
self.polygon.add_line(line)
return None
def stroke(self, parts=None):
polygon = self.polygon
self.polygon = Polygon()
return polygon