本文整理匯總了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