From 9189109c08260bd71dd33958dc9326c2549f5c93 Mon Sep 17 00:00:00 2001 From: jan Date: Wed, 28 Mar 2018 22:57:38 -0700 Subject: [PATCH] simplify by splitting up r2ledges into rverts, lverts --- chop/split.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/chop/split.py b/chop/split.py index c158f85..425163d 100644 --- a/chop/split.py +++ b/chop/split.py @@ -88,22 +88,25 @@ def split(poly, plane, same_only: bool = False): Some edges cross the plane ''' right_inds3 = numpy.repeat(right_inds, 3) - pnbr_inds = numpy.arange(3 * num_right) % 3 # array of [[clipped vertex (cv0), connected vertex pv00], [cv0, pv01], [cv0, pv02], [cv1, pv10], ...] # which is effectively a list of all edges which touch the right half-plane - r2l_edges = numpy.column_stack((right_inds3, next_vertex, pnbr_inds)) - r2l_edges = r2l_edges[far_vertex_left, :] # remove edges which don't also touch the left half-plane + # remove edges which don't also touch the left half-plane + rverts = right_inds3[far_vertex_left] + lverts = next_vertex[far_vertex_left] + pinds = (numpy.arange(3 * num_right) % 3)[far_vertex_left] +# r2l_edges = numpy.column_stack((right_inds3, next_vertex, pnbr_inds)) +# r2l_edges = r2l_edges[far_vertex_left, :] # remove edges which don't also touch the left half-plane - num_new_vertices = r2l_edges.shape[0] + num_new_vertices = rverts.size ''' walk to next crossing edge ''' - prev_verts = r2l_edges[:, 0] - cur_verts = r2l_edges[:, 1] + prev_verts = rverts + cur_verts = lverts edge_walk_inds = numpy.arange(num_new_vertices) - edge_walk_results = numpy.empty((r2l_edges.shape[0], 2), dtype=int) + edge_walk_results = numpy.empty((rverts.size, 2), dtype=int) src_pns = None while cur_verts.size > 0: # Get the list of our current neighbors, find which one points to the @@ -131,10 +134,10 @@ def split(poly, plane, same_only: bool = False): # now edge_walk_results is list of [[target clipped adjacent vertex, target connected vertex], ...] # figure out the index of each target edge... - target_edge_inds = _get_map_rows(r2l_edges[:, :2], edge_walk_results) + arr = numpy.column_stack((rverts, lverts)) + target_edge_inds = _get_map_rows(arr, edge_walk_results) - re = r2l_edges[:, 0] - le = r2l_edges[:, 1] + re, le = rverts, lverts d_right = dists[re][:, None] d_left = dists[le][:, None] new_vertices = (d_right * vertices[le] - d_left * vertices[re]) / (d_right - d_left) @@ -181,7 +184,7 @@ def split(poly, plane, same_only: bool = False): old_neighbors_right = poly['neighbors'].copy() old_neighbors_right[right] = ind_map_right[old_neighbors_right[right]] - old_neighbors_right[(re, r2l_edges[:, 2])] = num_right + numpy.arange(num_new_vertices) + old_neighbors_right[(re, pinds)] = num_right + numpy.arange(num_new_vertices) old_neighbors_right = old_neighbors_right[right] right_poly = {