def test_three_lines_no_crossing(self): # This test gave an error at some point p = np.array([[ 0., 0., 0.3, 1., 1., 0.5], [2/3, 1/.7, 0.3, 2/3, 1/.7, 0.5]]) lines = np.array([[0, 3], [1, 4], [2, 5]]).T box = np.array([[1], [2]]) new_pts, new_lines = basics.remove_edge_crossings(p, lines, box=box) p_known = basics.snap_to_grid(p, box=box) assert np.allclose(new_pts, p_known) assert np.allclose(new_lines, lines)
def test_split_segment_partly_overlapping(self): p = np.array([[0, 1, 2, 3], [0, 0, 0, 0]]) lines = np.array([[0, 2], [1, 3]]).T box = np.array([[1], [1]]) new_pts, new_lines = basics.remove_edge_crossings(p, lines, box=box) p_known = basics.snap_to_grid(p, box=box) lines_known = np.array([[0, 1], [1, 2], [2, 3]]).T assert np.allclose(new_pts, p_known) assert np.allclose(new_lines, lines_known)
def test_three_lines_one_crossing(self): # This test gave an error at some point p = np.array([[ 0., 0.5, 0.3, 1., 0.3, 0.5], [2/3, 0.3, 0.3, 2/3, 0.5, 0.5]]) lines = np.array([[0, 3], [2, 5], [1, 4]]).T box = np.array([[1], [2]]) new_pts, new_lines = basics.remove_edge_crossings(p, lines, box=box) p_known = np.hstack((p, np.array([[0.4], [0.4]]))) p_known = basics.snap_to_grid(p_known, box=box) lines_known = np.array([[0, 3], [2, 6], [6, 5], [1, 6], [6, 4]]).T assert np.allclose(new_pts, p_known) assert np.allclose(new_lines, lines_known)
def test_split_segment_fully_overlapping_switched_order(self): p = np.array([[0, 1, 2, 3], [0, 0, 0, 0]]) lines = np.array([[0, 3], [2, 1]]).T box = np.array([[1], [1]]) new_pts, new_lines = basics.remove_edge_crossings(p, lines, box=box) new_lines = np.sort(new_lines, axis=0) p_known = basics.snap_to_grid(p, box=box) lines_known = np.array([[0, 1], [1, 2], [2, 3]]).T assert np.allclose(new_pts, p_known) assert np.allclose(new_lines, lines_known)
def test_split_segment_partly_overlapping_switched_order(self): # Same partly overlapping test, but switch order of edge-point # connection. Should make no difference p = np.array([[0, 1, 2, 3], [0, 0, 0, 0]]) lines = np.array([[0, 2], [3, 1]]).T box = np.array([[1], [1]]) new_pts, new_lines = basics.remove_edge_crossings(p, lines, box=box) new_lines = np.sort(new_lines, axis=0) p_known = basics.snap_to_grid(p, box=box) lines_known = np.array([[0, 1], [1, 2], [2, 3]]).T assert np.allclose(new_pts, p_known) assert np.allclose(new_lines, lines_known)
def test_lines_crossing_origin(self): p = np.array([[-1, 1, 0, 0], [0, 0, -1, 1]]) lines = np.array([[0, 2], [1, 3], [1, 2], [3, 4]]) box = np.array([[2], [2]]) new_pts, new_lines = basics.remove_edge_crossings(p, lines, box=box) p_known = np.hstack((p, np.array([[0], [0]]))) p_known = basics.snap_to_grid(p_known, box=box) lines_known = np.array([[0, 4, 2, 4], [4, 1, 4, 3], [1, 1, 2, 2], [3, 3, 4, 4]]) assert np.allclose(new_pts, p_known) assert np.allclose(new_lines, lines_known)
def test_aniso_snapping(self): p_snapped = basics.snap_to_grid(self.p, box=self.anisobox, tol=1) assert np.allclose(p_snapped, np.array([0, 1]))