def test_compute_square_distance_to_segment(self): # Check that this is correct for a bunch of lines # pt = endpoint pt = [0., 0.] seg = [[0., 0.], [1., 2.]] dist_sq = su.compute_squared_distance_to_segment(pt, seg) assert numpy.allclose(dist_sq, 0.) pt = [1., 2.] seg = [[0., 0.], [1., 2.]] dist_sq = su.compute_squared_distance_to_segment(pt, seg) assert numpy.allclose(dist_sq, 0.) # pt on line pt = [0.25, 0.5] seg = [[0., 0.], [1., 2.]] dist_sq = su.compute_squared_distance_to_segment(pt, seg) assert numpy.allclose(dist_sq, 0.) # pt nearest end point pt = [1., 3.] seg = [[0., 0.], [1., 2.]] dist_sq = su.compute_squared_distance_to_segment(pt, seg) assert numpy.allclose(dist_sq, 1.) # pt nearest end point pt = [1.01, 30.] seg = [[0., 0.], [1., 2.]] dist_sq = su.compute_squared_distance_to_segment(pt, seg) expectedDistSq = ((seg[1][0] - pt[0])**2 + (seg[1][1] - pt[1])**2) assert numpy.allclose(dist_sq, expectedDistSq) # pt nearest end point pt = [0., -3.] seg = [[0., 0.], [1., 2.]] dist_sq = su.compute_squared_distance_to_segment(pt, seg) assert numpy.allclose(dist_sq, 9.) # Should fail because seg has 2 points which are identical pt = [0., -3.] seg = [[0., 0.], [0., 0.]] def should_fail(): dist_sq = su.compute_squared_distance_to_segment(pt, seg) return self.assertRaises(Exception, lambda: should_fail()) # This one actually uses the perpendicular distance feature pt = [1.0, 1.0] seg = [[0., -2.], [10., 8.]] # y=x-2 dist_sq = su.compute_squared_distance_to_segment(pt, seg) assert numpy.allclose(dist_sq, 2.) return
def test_compute_square_distance_to_segment(self): # Check that this is correct for a bunch of lines # pt = endpoint pt=[0., 0.] seg=[ [0., 0.], [1., 2.]] dist_sq=su.compute_squared_distance_to_segment(pt,seg) assert numpy.allclose(dist_sq, 0.) pt=[1., 2.] seg=[ [0., 0.], [1., 2.]] dist_sq=su.compute_squared_distance_to_segment(pt,seg) assert numpy.allclose(dist_sq, 0.) # pt on line pt=[0.25, 0.5] seg=[ [0., 0.], [1., 2.]] dist_sq=su.compute_squared_distance_to_segment(pt,seg) assert numpy.allclose(dist_sq, 0.) # pt nearest end point pt=[1., 3.] seg=[ [0., 0.], [1., 2.]] dist_sq=su.compute_squared_distance_to_segment(pt,seg) assert numpy.allclose(dist_sq, 1.) # pt nearest end point pt=[1.01, 30.] seg=[ [0., 0.], [1., 2.]] dist_sq=su.compute_squared_distance_to_segment(pt,seg) expectedDistSq=( (seg[1][0]-pt[0])**2 + (seg[1][1]-pt[1])**2) assert numpy.allclose(dist_sq, expectedDistSq) # pt nearest end point pt=[0., -3.] seg=[ [0., 0.], [1., 2.]] dist_sq=su.compute_squared_distance_to_segment(pt,seg) assert numpy.allclose(dist_sq, 9.) # Should fail because seg has 2 points which are identical pt=[0., -3.] seg=[ [0., 0.], [0., 0.]] def should_fail(): dist_sq=su.compute_squared_distance_to_segment(pt,seg) return self.assertRaises(Exception, lambda: should_fail()) # This one actually uses the perpendicular distance feature pt=[1.0, 1.0] seg=[ [0., -2.], [10., 8.]] # y=x-2 dist_sq=su.compute_squared_distance_to_segment(pt,seg) assert numpy.allclose(dist_sq, 2.) return
def should_fail(): dist_sq = su.compute_squared_distance_to_segment(pt, seg) return
def should_fail(): dist_sq=su.compute_squared_distance_to_segment(pt,seg) return