Exemple #1
0
    def test_point_and_vector_addition(self):
        p = Point(3, 5)
        v = Vector(0, 1)

        p2 = p + v
        self.assertEqual(3, p2.x)
        self.assertEqual(6, p2.y)
Exemple #2
0
def parse(model: str) -> {}:
    with open(
            str(get_project_root()) + '/configs/' + model + '_input.json',
            'r') as input_file:
        data = input_file.read()

    configs = json.loads(data)
    return {
        'start_laser_location':
        Point3d(configs['laser_loc'][0], configs['laser_loc'][1],
                configs['laser_loc'][2]),
        'start_laser_direction':
        Vector(
            Point3d(configs['laser_dir'][0], configs['laser_dir'][1],
                    configs['laser_dir'][2])),
        'down_triangle': [
            Point3d(configs['down_tr'][0][0], configs['down_tr'][0][1],
                    configs['down_tr'][0][2]),
            Point3d(configs['down_tr'][1][0], configs['down_tr'][1][1],
                    configs['down_tr'][1][2]),
            Point3d(configs['down_tr'][2][0], configs['down_tr'][2][1],
                    configs['down_tr'][2][2]),
        ],
        'up_triangle': [
            Point3d(configs['up_triangle'][0][0], configs['up_triangle'][0][1],
                    configs['up_triangle'][0][2]),
            Point3d(configs['up_triangle'][1][0], configs['up_triangle'][1][1],
                    configs['up_triangle'][1][2]),
            Point3d(configs['up_triangle'][2][0], configs['up_triangle'][2][1],
                    configs['up_triangle'][2][2]),
        ],
        "target_radius":
        configs["target_radius"]
    }
Exemple #3
0
class WindRose:
    NORTH = Vector(0, 1)
    NORTH_INDEX = 0

    EAST = Vector(1, 0)
    EAST_INDEX = 1

    SOUTH = Vector(0, -1)
    SOUTH_INDEX = 2

    WEST = Vector(-1, 0)
    WEST_INDEX = 3

    ORIENTATIONS = [NORTH, EAST, SOUTH, WEST]

    @staticmethod
    def clockwise_rotate(index):
        next = (index + 1) % 4
        return WindRose.ORIENTATIONS[next], next

    @staticmethod
    def anti_clockwise_rotate(index):
        next = (index - 1) % 4
        return WindRose.ORIENTATIONS[next], next
Exemple #4
0
 def test_angle_between_vectors(self):
     self.assertEqual(angle_between_vectors(Vector(1, 0), Vector(1, 0)), 0)
     self.assertEqual(angle_between_vectors(Vector(1, 0), Vector(0, 1)),
                      np.pi / 2)
     self.assertEqual(angle_between_vectors(Vector(-1, 1), Vector(-1, -1)),
                      np.pi / 2)
Exemple #5
0
 def test_scalar_product(self):
     self.assertEqual(scalar_product(Vector(1, 0), Vector(0, 1)), 0)
     self.assertEqual(scalar_product(Vector(1, 0), Vector(1, 0)), 1)
     self.assertEqual(scalar_product(Vector(1, 0), Vector(-1, 0)), -1)
Exemple #6
0
 def test_normalize(self):
     d = Vector(1, 2)
     d = d.normalize()
     self.assertAlmostEqual(d.length(), 1)
Exemple #7
0
 def test_action(self):
     self.assertEqual(Vector(1, 1).to_direction(), Action.TopRight)
     self.assertEqual(Vector(1, -1).to_direction(), Action.BottomRight)
Exemple #8
0
 def test_reverse(self):
     d1 = Vector(1, 1)
     d1 = d1.reverse()
     d2 = Vector(-1, -1)
     self.assertAlmostEqual(d1.x, d2.x)
     self.assertAlmostEqual(d1.y, d2.y)
Exemple #9
0
 def test_turn(self):
     d1 = Vector(1, 1)
     d1 = d1.turn(np.pi / 4)
     self.assertAlmostEqual(d1.x, 0)
     self.assertAlmostEqual(d1.y, np.sqrt(2))
Exemple #10
0
 def test_distance(self):
     self.assertEqual(Vector(1, 0).length(), 1)
     self.assertEqual(Vector(1, 1).length(), np.sqrt(2))
Exemple #11
0
 def test_angle(self):
     self.assertEqual(Vector(1, 0).angle(), 0)
     self.assertEqual(Vector(0, 1).angle(), np.pi / 2)
     self.assertEqual(Vector(-1, 0).angle(), np.pi)
     self.assertEqual(Vector(0, -1).angle(), -np.pi / 2)
     self.assertEqual(Vector(1, 1).angle(), np.pi / 4)