def create_cart2_point(x, y, id): point = Cartesian2dTrajectoryPoint() point.object_id = id point[0] = x point[1] = y return point
def test_cartesian2d_distance(): error_count = 0 point00 = Cartesian2dTrajectoryPoint(0, 0) point01 = Cartesian2dTrajectoryPoint(0, 1) point11 = Cartesian2dTrajectoryPoint(1, 1) point22 = Cartesian2dTrajectoryPoint(2, 2) traj1 = Cartesian2dTrajectory.from_position_list([point00, point01]) traj2 = Cartesian2dTrajectory.from_position_list([point11, point22]) print("Testing Cartesian 2D Distance") expected = 1.0 actual = geomath.distance(point00, point01) error_count += verify_result( actual, expected, "Cartesian2dTrajectoryPoint to Cartesian2dTrajectoryPoint 1") expected = 1.414 actual = geomath.distance(point00, point11) error_count += verify_result( actual, expected, "Cartesian2dTrajectoryPoint to Cartesian2dTrajectoryPoint 2") expected = 1.0 actual = geomath.distance(traj1, traj2) error_count += verify_result( actual, expected, "Cartesian2dTrajectory to Cartesian2dTrajectory") expected = 1.414 actual = geomath.distance(point00, traj2) error_count += verify_result( actual, expected, "Cartesian2dTrajectoryPoint to Cartesian2dTrajectory") actual = geomath.distance(traj2, point00) error_count += verify_result( actual, expected, "Cartesian2dTrajectory to Cartesian2dTrajectoryPoint") return error_count
def test_compute_bounding_box(): error_count = 0 bbox_type = TerrestrialTrajectoryPoint.domain_classes['BoundingBox'] expected_min_corner = TerrestrialTrajectoryPoint.domain_classes[ 'BasePoint']() expected_max_corner = TerrestrialTrajectoryPoint.domain_classes[ 'BasePoint']() albuquerque = TerrestrialTrajectoryPoint(-106.6504, 35.0844) san_francisco = TerrestrialTrajectoryPoint(-122.4194, 37.7749) tokyo = TerrestrialTrajectoryPoint(-221.6917, 35.6895) small_traj = TrajectoryPointSource() small_traj.start_point = albuquerque small_traj.end_point = san_francisco small_traj.num_points = 2 long_traj = TrajectoryPointSource() long_traj.start_point = tokyo long_traj.end_point = san_francisco long_traj.num_points = 2 #Test smallish basic bounding box expected_min_corner[0] = san_francisco[0] expected_min_corner[1] = albuquerque[1] expected_max_corner[0] = albuquerque[0] expected_max_corner[1] = san_francisco[1] expected = bbox_type(expected_min_corner, expected_max_corner) map_bbox = geomath.compute_bounding_box(small_traj.points()) error_count += verify_result(expected, map_bbox, "Basic small box") #Test larger basic bounding box expected_min_corner[0] = tokyo[0] expected_min_corner[1] = tokyo[1] expected_max_corner[0] = san_francisco[0] expected_max_corner[1] = san_francisco[1] expected = bbox_type(expected_min_corner, expected_max_corner) map_bbox = geomath.compute_bounding_box(long_traj.points()) error_count += verify_result(expected, map_bbox, "Basic large box") #Test smallish bounding box with buffer lon_buffer = .2 lat_buffer = .5 expected_min_corner[0] = san_francisco[0] - ( (albuquerque[0] - san_francisco[0]) * lon_buffer) expected_min_corner[1] = albuquerque[1] - ( (san_francisco[1] - albuquerque[1]) * lat_buffer) expected_max_corner[0] = albuquerque[0] + ( (albuquerque[0] - san_francisco[0]) * lon_buffer) expected_max_corner[1] = san_francisco[1] + ( (san_francisco[1] - albuquerque[1]) * lat_buffer) expected = bbox_type(expected_min_corner, expected_max_corner) map_bbox = geomath.compute_bounding_box(small_traj.points(), (lon_buffer, lat_buffer)) error_count += verify_result(expected, map_bbox, "Buffered small box") #Test larger basic bounding box with buffer lon_buffer = .2 lat_buffer = .1 expected_min_corner[0] = tokyo[0] - ( (san_francisco[0] - tokyo[0]) * lon_buffer) expected_min_corner[1] = tokyo[1] - ( (san_francisco[1] - tokyo[1]) * lat_buffer) expected_max_corner[0] = san_francisco[0] + ( (san_francisco[0] - tokyo[0]) * lon_buffer) expected_max_corner[1] = san_francisco[1] + ( (san_francisco[1] - tokyo[1]) * lat_buffer) expected = bbox_type(expected_min_corner, expected_max_corner) map_bbox = geomath.compute_bounding_box(long_traj.points(), (lon_buffer, lat_buffer)) error_count += verify_result(expected, map_bbox, "Buffered large box") #Test cartesian based boxes c_bbox_type = Cartesian2dTrajectoryPoint.domain_classes['BoundingBox'] c_expected_min_corner = Cartesian2dTrajectoryPoint.domain_classes[ 'BasePoint']() c_expected_max_corner = Cartesian2dTrajectoryPoint.domain_classes[ 'BasePoint']() point0 = Cartesian2dTrajectoryPoint(0, 0) point1 = Cartesian2dTrajectoryPoint(1, 1) point2 = Cartesian2dTrajectoryPoint(2, 2) c_expected_min_corner = Cartesian2dTrajectoryPoint(0, 0) c_expected_max_corner = Cartesian2dTrajectoryPoint(2, 2) expected = c_bbox_type(c_expected_min_corner, c_expected_max_corner) map_bbox = geomath.compute_bounding_box([point0, point1, point2]) error_count += verify_result(expected, map_bbox, "Basic cartesian box") #Test cartesian box with buffer x_buffer = .5 y_buffer = 1. c_expected_min_corner[0] = point0[0] - ((point2[0] - point0[0]) * x_buffer) c_expected_min_corner[1] = point0[1] - ((point2[1] - point0[1]) * y_buffer) c_expected_max_corner[0] = point2[0] + ((point2[0] - point0[0]) * x_buffer) c_expected_max_corner[1] = point2[1] + ((point2[1] - point0[1]) * y_buffer) expected = c_bbox_type(c_expected_min_corner, c_expected_max_corner) map_bbox = geomath.compute_bounding_box([point0, point1, point2], (x_buffer, y_buffer)) error_count += verify_result(expected, map_bbox, "Buffered cartesian box") # Test error conditions map_bbox = geomath.compute_bounding_box([]) if (map_bbox != None): sys.stderr.write('ERROR: Empty point sequence did not return None') error_count += 1 map_bbox = geomath.compute_bounding_box(long_traj.points(), (1.0, )) if (map_bbox != None): sys.stderr.write('ERROR: Buffer tuple length of 1 did not return None') error_count += 1 map_bbox = geomath.compute_bounding_box(long_traj.points(), (1.0, 2.0, 3.0)) if (map_bbox != None): sys.stderr.write('ERROR: Buffer tuple length of 3 did not return None') error_count += 1 return error_count