class Test_Shapes(unittest.TestCase): """docstring for Test_Roadgen""" #Setup the test instance of the class def setUp(self): self.test0 = Shapes() def tearDown(self): pass def test_unit_vector(self): npt.assert_almost_equal(self.test0.unit_vector([345.345, 0]), np.array([1., 0.]), decimal=7) npt.assert_almost_equal(self.test0.unit_vector([0, 345.345]), np.array([0., 1.]), decimal=7) npt.assert_almost_equal(self.test0.unit_vector([-345.345, 0]), np.array([-1., 0.]), decimal=7) npt.assert_almost_equal(self.test0.unit_vector([0, -345.345]), np.array([0., -1.]), decimal=7) npt.assert_almost_equal(self.test0.unit_vector([-3, -4]), np.array([-.6, -.8]), decimal=7)
def middle_points(self, y_train, y_noise, orientation=1): #Assign the central control point: y_train[1, 0, 1] = np.random.randint(0, self.view_res[0]) + self.cropsize[0] y_train[1, 1, 1] = np.random.randint(0, self.view_res[1]) + self.cropsize[1] '''Calculate the control point axis: control point axis is defined by a unit vector parallel to a line originating at the midpoint of the line's start and end and terminating at the curves second control point''' u_delta = Shapes.unit_vector(y_train[1, :, 1] - ( y_train[1, :, 0] + (y_train[1, :, 2] - y_train[1, :, 0]) / 2)) #print(u_delta) #scales the sideways road outputs to account for pitch vertical_excursion = np.absolute(u_delta[1]) * self.max_road_width #rotational correction: u_rot = Shapes.rot_by_vector(y_train[1, :, 2] - y_train[1, :, 0], u_delta) #Checks to see which side of the line between start and end the midpoint falls on if u_rot[1] > 0: #If u_delta has a negative y component then it falls south of the line and need to be inverted u_delta *= -1 #Set the left side no.1 control point y_train[0, :, 1] = (y_train[1, :, 1] + u_delta * np.multiply( (self.max_road_width - y_noise[0, 1]), (1 - self.lane_convergence + self.lane_convergence * np.maximum( .2, (y_train[1, 1, 1] + vertical_excursion)) / self.gen_res[1]))) #Set the right side no.1 control point y_train[2, :, 1] = (y_train[1, :, 1] - u_delta * np.multiply( (self.max_road_width - y_noise[1, 1]), (1 - self.lane_convergence + self.lane_convergence * np.maximum( .2, (y_train[1, 1, 1] - vertical_excursion)) / self.gen_res[1]))) return y_train