Exemple #1
0
def find_shortest_intersection(path_vectors_a, path_vectors_b):
    path_a = make_path_from_vectors(path_vectors_a)[1:]
    path_b = make_path_from_vectors(path_vectors_b)[1:]

    def key(point):
        return point.get_point()

    groups = unsorted_matched_groups(path_a, path_b, key=key)

    result = None

    if len(groups) > 0:

        def path_len_sort(point):
            return point.path_len

        results = []

        for group in groups:
            intersects_a = group[0]
            intersects_b = group[1]

            intersects_a.sort(key=path_len_sort)
            intersects_b.sort(key=path_len_sort)

            results.append(intersects_a[0].path_len + intersects_b[0].path_len)

        results.sort()
        result = results[0]

    return result
Exemple #2
0
def find_nearest_intersection(path_vectors_a, path_vectors_b):
    path_a = make_path_from_vectors(path_vectors_a)[1:]
    path_b = make_path_from_vectors(path_vectors_b)[1:]

    def key(point):
        return point.get_point()

    intersects = non_sorted_intersection(path_a, path_b, key=key)
    result = None

    if len(intersects) > 0:
        intersects.sort(key=lambda p: p.get_point().manhattan_distance())
        result = intersects[0]

    return result
Exemple #3
0
 def test_DL(self):
     vectors = ["D2", "L3"]
     expected = [
         PathPoint(0, 0, 0),
         PathPoint(0, -1, 1),
         PathPoint(0, -2, 2),
         PathPoint(-1, -2, 3),
         PathPoint(-2, -2, 4),
         PathPoint(-3, -2, 5)
     ]
     path = make_path_from_vectors(vectors)
     self.assertListEqual(path, expected)
Exemple #4
0
 def test_UR(self):
     vectors = ["U2", "R3"]
     expected = [
         PathPoint(0, 0, 0),
         PathPoint(0, 1, 1),
         PathPoint(0, 2, 2),
         PathPoint(1, 2, 3),
         PathPoint(2, 2, 4),
         PathPoint(3, 2, 5)
     ]
     path = make_path_from_vectors(vectors)
     self.assertListEqual(path, expected)
Exemple #5
0
 def test_south_then_east(self):
     vectors = ["F2", "A90", "F3"]
     expected = [
         PathPoint(0, 0, 0),
         PathPoint(0, -1, 1),
         PathPoint(0, -2, 2),
         PathPoint(1, -2, 3),
         PathPoint(2, -2, 4),
         PathPoint(3, -2, 5)
     ]
     cardinal = CardinalPoint.SOUTH
     path = make_path_from_vectors(vectors, cardinal)
     self.assertListEqual(path, expected)
Exemple #6
0
 def test_north_then_east(self):
     vectors = ["F2", "C90", "F3"]
     expected = [
         PathPoint(0, 0, 0),
         PathPoint(0, 1, 1),
         PathPoint(0, 2, 2),
         PathPoint(1, 2, 3),
         PathPoint(2, 2, 4),
         PathPoint(3, 2, 5)
     ]
     cardinal = CardinalPoint.NORTH
     path = make_path_from_vectors(vectors, cardinal)
     self.assertListEqual(path, expected)
Exemple #7
0
def make_ship_path(directions):
    return make_path_from_vectors(directions, CardinalPoint.EAST)