From 2bd314cc913739e7a663a91e9ab3f04ecca81fc0 Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Thu, 8 Jun 2023 22:00:15 +0800 Subject: [PATCH] Enhance boundary algorithm --- api/s32_region_util.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/api/s32_region_util.py b/api/s32_region_util.py index d76d9f2..6a4f6cc 100644 --- a/api/s32_region_util.py +++ b/api/s32_region_util.py @@ -150,8 +150,16 @@ def calculate_boundary(name: str, nodes: list[str]) -> list[tuple[float, float]] paths: list[str] = [] while True: - #print(cursor) + # prevent duplicated node + if len(paths) > 0 and cursor == paths[-1]: + break + + # prevent duplicated path + if len(paths) >= 3 and paths[0] == paths[-1] and paths[1] == cursor: + break + paths.append(cursor) + sorted_links = [] overlapped_link = '' for link in t_nodes[cursor]['links']: @@ -164,10 +172,7 @@ def calculate_boundary(name: str, nodes: list[str]) -> list[tuple[float, float]] # work into a branch, return if len(sorted_links) == 0: cursor = paths[-2] - if cursor == topology.max_x_node(): - paths.append(cursor) - break - in_angle = in_angle = _angle_of_node_link(cursor, overlapped_link, t_nodes, t_links) + in_angle = _angle_of_node_link(cursor, overlapped_link, t_nodes, t_links) continue sorted_links = sorted(sorted_links, key=lambda s:s[0]) @@ -178,11 +183,6 @@ def calculate_boundary(name: str, nodes: list[str]) -> list[tuple[float, float]] break cursor = t_links[out_link]['node1'] if cursor == t_links[out_link]['node2'] else t_links[out_link]['node2'] - # end up trip :) - if cursor == topology.max_x_node(): - paths.append(cursor) - break - in_angle = _angle_of_node_link(cursor, out_link, t_nodes, t_links) boundary: list[tuple[float, float]] = []