From d4fbe3e7e4b670256bf99bc6b00546ca24244e97 Mon Sep 17 00:00:00 2001 From: jan Date: Thu, 5 Apr 2018 15:50:24 -0700 Subject: [PATCH] minor cleanup --- chop/split.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/chop/split.py b/chop/split.py index d87a31f..bbd61be 100644 --- a/chop/split.py +++ b/chop/split.py @@ -44,7 +44,7 @@ def split(poly, plane, same_only: bool = False): ''' vertices = poly['vertices'] neighbors = poly['neighbors'] - num_start = poly['vertices'].shape[0] + num_start = neighbors.shape[0] dists = plane[1] + (vertices @ plane[0]) left = dists > 0 @@ -94,6 +94,13 @@ def split(poly, plane, same_only: bool = False): num_new_vertices = rverts.size + ''' + figure out new vertex positions + ''' + d_right = dists[rverts][:, None] + d_left = dists[lverts][:, None] + new_vertices = (d_right * vertices[lverts] - d_left * vertices[rverts]) / (d_right - d_left) + ''' walk to next crossing edge ''' @@ -131,10 +138,6 @@ def split(poly, plane, same_only: bool = False): arr = numpy.column_stack((rverts, lverts)) target_edge_inds = _get_map_rows(arr, edge_walk_results) - d_right = dists[rverts][:, None] - d_left = dists[lverts][:, None] - new_vertices = (d_right * vertices[lverts] - d_left * vertices[rverts]) / (d_right - d_left) - ''' map from old vertex ind to new ''' @@ -150,9 +153,9 @@ def split(poly, plane, same_only: bool = False): target_order + num_left, # new vertex indices are same as edge indices + offset target_edge_inds + num_left)) - old_vertices_left = poly['vertices'][left] + old_vertices_left = vertices[left] - old_neighbors_left = poly['neighbors'].copy() + old_neighbors_left = neighbors.copy() old_neighbors_left[left] = ind_map_left[old_neighbors_left[left]] # map vertices on left side, wrongly mapping any right-side vertices to 0 old_neighbors_left[(lverts, src_pns)] = num_left + numpy.arange(num_new_vertices) old_neighbors_left = old_neighbors_left[left] @@ -173,9 +176,9 @@ def split(poly, plane, same_only: bool = False): target_edge_inds + num_right, # new vertex indices are same as edge indices + offset target_order + num_right)) - old_vertices_right = poly['vertices'][right] + old_vertices_right = vertices[right] - old_neighbors_right = poly['neighbors'].copy() + old_neighbors_right = neighbors.copy() old_neighbors_right[right] = ind_map_right[old_neighbors_right[right]] old_neighbors_right[(rverts, rl_edge_inds)] = num_right + numpy.arange(num_new_vertices) old_neighbors_right = old_neighbors_right[right]