def test_reduce_to_fewest_nodes_min_max_spacing(spacing): distance_along_segment = np.cumsum(spacing) if np.any(np.diff(distance_along_segment) <= 0): raise ValueError(f"array not sorted ({distance_along_segment})") xy_of_node = list(zip(distance_along_segment, [0.0] * len(distance_along_segment))) min_spacing = np.diff(distance_along_segment).min() nodes = _reduce_to_fewest_nodes(xy_of_node, spacing=min_spacing) assert np.all(nodes == np.arange(len(spacing))) nodes = _reduce_to_fewest_nodes( xy_of_node, spacing=distance_along_segment[-1] - distance_along_segment[0], ) assert nodes == [0, len(spacing) - 1]
def test_reduce_to_fewest_nodes(): x = [0.0, 1.0, 2.0, 3.0, 3.5] y = [0.0] * len(x) nodes = _reduce_to_fewest_nodes(list(zip(x, y)), spacing=1.0) assert nodes == [0, 1, 2, 3, 4] nodes = _reduce_to_fewest_nodes(list(zip(x, y)), spacing=0.5) assert nodes == [0, 1, 2, 3, 4] x = [0.0, 1.0, 2.0, 3.0, 4.0] y = [0.0] * len(x) nodes = _reduce_to_fewest_nodes(list(zip(x, y)), spacing=1.75) assert nodes == [0, 2, 4] nodes = _reduce_to_fewest_nodes(list(zip(x, y)), spacing=[1.0, 1.0, 2.0, 2.0, 2.0]) assert nodes == [0, 1, 2, 4] nodes = _reduce_to_fewest_nodes(list(zip(x, y)), spacing=1000.0) assert nodes == [0, 4] x = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0] y = [0.0] * len(x) nodes = _reduce_to_fewest_nodes(list(zip(x, y)), spacing=2.0) assert nodes == [0, 2, 4, 5]
def test_educe_to_fewest_nodes_wraparound(): x = [0.0, 0.0, 0.0, 1.0, 1.0, 1.0] y = [0.0, 1.0, 2.0, 2.0, 1.0, 0.0] assert _reduce_to_fewest_nodes(list(zip(x, y)), spacing=1.001) == [0, 5]
def test_reduce_to_fewest_nodes_stay_the_same(x, spacing): y = [0.0] * len(x) nodes = _reduce_to_fewest_nodes(list(zip(x, y)), spacing=spacing) assert nodes == [0, 1, 2, 3, 4]