Skip to content

Commit

Permalink
Using CurvedPolygon._metadata in surface-surface intersection.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Jan 8, 2018
1 parent 871d23d commit e253da2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/bezier/surface.py
Expand Up @@ -1134,4 +1134,5 @@ def _make_intersection(edge_info, all_edge_nodes):
new_nodes, degree, start=start, end=end, _copy=False)
edges.append(edge)

return curved_polygon.CurvedPolygon(*edges, _verify=False)
return curved_polygon.CurvedPolygon(
*edges, metadata=edge_info, _verify=False)
18 changes: 2 additions & 16 deletions tests/functional/test_surface_surface.py
Expand Up @@ -85,27 +85,13 @@
CONFIG = utils.Config()


def find_edge_index(edge, root_edges):
for index, root_edge in enumerate(root_edges):
if root_edge.degree != edge.degree:
continue
specialized = root_edge.specialize(edge.start, edge.end)
if np.allclose(specialized._nodes, edge._nodes):
return index

raise RuntimeError('No match found.')


def curved_polygon_edges(intersection, root_edges_pair):
edges1, edges2 = root_edges_pair
root_edges = edges1 + edges2
# Re-sort the edges to be in the same order independent of strategy.
edge_list = intersection._edges
edge_info = [
(find_edge_index(edge, root_edges), edge.start, edge.end)
for edge in edge_list
]
edge_info = intersection._metadata
index = edge_info.index(min(edge_info))
edge_list = intersection._edges
return edge_list[index:] + edge_list[:index]


Expand Down
20 changes: 20 additions & 0 deletions tests/unit/test_surface.py
Expand Up @@ -743,6 +743,16 @@ def _basic_intersect_helper(self, **kwargs):

intersection = intersections[0]
self.assertIsInstance(intersection, bezier.CurvedPolygon)
self.assertEqual(
intersection._metadata,
(
(5, 0.5, 1.0),
(3, 0.0, 0.5),
(1, 0.5, 1.0),
(2, 0.0, 0.5),
),
)

cp_edges = intersection._edges
self.assertEqual(len(cp_edges), 4)
# Edge 0.
Expand Down Expand Up @@ -940,6 +950,16 @@ def test_it(self):
)
result = self._call_function_under_test(edge_info, edge_nodes)
self.assertIsInstance(result, bezier.CurvedPolygon)
self.assertEqual(
result._metadata,
(
(0, 0.0, 0.25),
(5, 0.75, 1.0),
(3, 0.0, 0.25),
(2, 0.75, 1.0),
),
)

self.assertEqual(result.num_sides, 4)
# pylint: disable=unbalanced-tuple-unpacking
edge0, edge1, edge2, edge3 = result._edges
Expand Down

0 comments on commit e253da2

Please sign in to comment.