本文整理匯總了Python中edge.Edge.from_json方法的典型用法代碼示例。如果您正苦於以下問題:Python Edge.from_json方法的具體用法?Python Edge.from_json怎麽用?Python Edge.from_json使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類edge.Edge
的用法示例。
在下文中一共展示了Edge.from_json方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: from_json
# 需要導入模塊: from edge import Edge [as 別名]
# 或者: from edge.Edge import from_json [as 別名]
def from_json(cls, json_world):
point_index = {}
points = set()
json_points = json_world[cls.JSON_KEY_POINTS]
for point_type_key, point_class in [
(cls.JSON_KEY_FOOD_POINTS, FoodPoint),
(cls.JSON_KEY_ANTHILL_POINTS, AnthillPoint),
(cls.JSON_KEY_ORDINARY_POINTS, Point),
]:
for json_point in json_points[point_type_key]:
p = point_class.from_json(json_point)
point_index[p.coordinates] = p
points.add(p)
edges = set()
for json_edge in json_world[cls.JSON_KEY_EDGES]:
e = Edge.from_json(json_edge, point_index)
e.register_with_points()
edges.add(e)
return cls(points, edges)