示例#1
0
def test_repr():
    p = point.Point(2, 3)
    assert repr(p) == "Point(2, 3)"
示例#2
0
 def test_equality_2(self):
     pt1 = point.Point(0.1, 2.3)
     pt2 = point.Point(4.5, 6.7)
     self.assertFalse(pt1 == pt2)
示例#3
0
 def are_in_first_quadrant_2(self):
     p1 = point.Point(10, 10)
     p2 = point.Point(-10, -10)
     l1 = filter.are_in_first_quadrant([p1, p2])
     l2 = [p1]
     self.assertListAlmostEqual(l1, l2)
示例#4
0
"""Exercise the Point class."""


import point

origin = point.Point()
p1 = point.Point(2, 3)
p2 = point.Point(-2, -3)

print(origin)
print(p1)
print(p2)
print()
print(origin.__repr__())
print(p1.__repr__())
print(p2.__repr__())
print()
print(origin.euclidian_distance(p1))
print(origin.manhattan_distance(p1))
print()
print(origin.add(p1))
print(p1.add(p2))
print()
print(origin + p1)
print(p1 + p2)
print(origin + p1 + p2)
示例#5
0
 def test_point_two(self):
     pt = point.Point(-4.7, 19.2)
     self.assertAlmostEqual(pt.x, -4.7)
     self.assertAlmostEqual(pt.y, 19.2)
示例#6
0
    def test_distance_to_non_numeric(self):
        pt0 = point.Point(coords=['A', 10, 10])
        pt1 = point.Point(coords=[10, 10, 10])

        with self.assertRaises(TypeError):
            pt0.distance_to(pt1)
示例#7
0
 def get_random_velocity(self):
     theta = random.random() * 2 * math.pi
     return point.Point(math.cos(theta), math.sin(theta))
示例#8
0
 def test_distance_all(self):
    list = [point.Point(6, 0), point.Point(3,0), point.Point(4, 0)]
    origin = point.Point(0, 0)
    expected = [6, 3, 4]
    self.assertEqual(map.distance_all(list, origin), expected)
示例#9
0
 def test_distance_all_2(self):
    list = [point.Point(6, 8), point.Point(3, 4), point.Point(0, 8)]
    origin = point.Point(0, 0)
    expected = [10, 5, 8]
    self.assertEqual(map.distance_all(list, origin), expected)
示例#10
0
#!/usr/bin/python3
import point
p1 = point.Point()
示例#11
0
def get_point(x, y):
    return point.Point(x, y)
 def test_equality(self):
     pt = point.Point(5, 10)
     self.assertEqual(pt.x, 5)
     self.assertEqual(pt.y, 10)
     pass
示例#13
0
def motionToNextPoint(currentPoint):
    """Движение от текущей точки до следующей"""
    # Находим вектор, на который нам необходимо переместить робота
    deltaX = currentPoint.previousPoint.x - currentPoint.x
    deltaY = currentPoint.previousPoint.y - currentPoint.y
    # Направление к точке
    motionDirection = findDirection(currentPoint, currentPoint.previousPoint)
    # Проверяем, является ли следующая точка соседней по диагонали
    if motionDirection["direction"] == 1:
        if motionDirection["turnDirection"] == -1:
            obstacleDistance = distanceSensor(
                1, 90 + motionDirection["turnAngle"])
            if deltaX != 0 and deltaY != 0:
                if obstacleDistance <= settings.cell_lenght * math.sqrt(2):
                    addObstacles(currentPoint.previousPoint)
                    return False
            else:
                if obstacleDistance <= settings.cell_lenght:
                    addObstacles(currentPoint.previousPoint)
                    return False
        else:
            obstacleDistance = distanceSensor(
                1, 90 - motionDirection["turnAngle"])
            if deltaX != 0 and deltaY != 0:
                if obstacleDistance <= settings.cell_lenght * math.sqrt(2):
                    addObstacles(currentPoint.previousPoint)
                    return False
            else:
                if obstacleDistance <= settings.cell_lenght:
                    addObstacles(currentPoint.previousPoint)
                    return False
    else:
        obstacleDistance = distanceSensor(-1)
        if obstacleDistance <= settings.cell_lenght:
            addObstacles(currentPoint.previousPoint)
            return False

    if deltaX != 0 and deltaY != 0:
        # Следующая точка - на диагонали, значит необходима проверка соседних к ней точек на препятствие
        if checkObstacles(currentPoint.x,
                          currentPoint.y + deltaY) != True and checkObstacles(
                              currentPoint.x + deltaX, currentPoint.y) != True:
            simpleMotion(currentPoint)
            currentPoint.previousPoint.x_direction = deltaX * findDirection(
                currentPoint, currentPoint.previousPoint)["direction"]
            currentPoint.previousPoint.y_direction = deltaY * findDirection(
                currentPoint, currentPoint.previousPoint)["direction"]
        else:
            tempPoint = currentPoint.previousPoint
            if checkObstacles(currentPoint.x, currentPoint.y + deltaY) != True:
                middlePoint = point.Point(currentPoint.x,
                                          currentPoint.y + deltaY, False,
                                          tempPoint, 0)
            elif checkObstacles(currentPoint.x + deltaX,
                                currentPoint.y) != True:
                middlePoint = point.Point(currentPoint.x + deltaX,
                                          currentPoint.y, False, tempPoint, 0)
            else:
                pass
            middlePoint.x_direction = (
                middlePoint.x - currentPoint.x) * findDirection(
                    currentPoint, middlePoint)["direction"]
            middlePoint.y_direction = (
                middlePoint.y - currentPoint.y) * findDirection(
                    currentPoint, middlePoint)["direction"]
            tempPoint.x_direction = (tempPoint.x -
                                     middlePoint.x) * findDirection(
                                         middlePoint, tempPoint)["direction"]
            tempPoint.y_direction = (tempPoint.y -
                                     middlePoint.y) * findDirection(
                                         middlePoint, tempPoint)["direction"]
            currentPoint.previousPoint = middlePoint
            simpleMotion(currentPoint)
            print(currentPoint.previousPoint.x, currentPoint.previousPoint.y)
            simpleMotion(middlePoint)
            print(middlePoint.previousPoint.x, middlePoint.previousPoint.y)
            currentPoint.previousPoint = tempPoint
    else:
        simpleMotion(currentPoint)
        currentPoint.previousPoint.x_direction = deltaX * findDirection(
            currentPoint, currentPoint.previousPoint)["direction"]
        currentPoint.previousPoint.y_direction = deltaY * findDirection(
            currentPoint, currentPoint.previousPoint)["direction"]
    return True
示例#14
0
def test_str():
    p = point.Point(2, 3)
    assert str(p) == "(2, 3)"
示例#15
0
    def test_attributes(self):
        pt = point.Point()

        self.assertEqual(0, pt.x)
示例#16
0
def viewport_to_world(viewport, pt):
    return point.Point(pt.x + viewport.left, pt.y + viewport.top)
示例#17
0
    def test_distance_to_mismatched_dimensions(self):
        pt0 = point.Point(coords=[10, 10, 10])
        pt1 = point.Point(coords=[10, 10])

        with self.assertRaises(point.DimensionMismatch):
            pt0.distance_to(pt1)
示例#18
0
def world_to_viewport(viewport, pt):
    return point.Point(pt.x - viewport.left, pt.y - viewport.top)
示例#19
0
 def vel_to_center(self, node_pos):
     return (point.Point(self.x_dim / 2, self.y_dim / 2) - node_pos)\
         .to_unit_vector()
示例#20
0
import gps
import time
import point

if '__main__' == __name__:
    count = 0
    targ_point = point.Point(33.658520, 73.029851)
    # targ_point.lat=round(targ_point.lat,4)
    #targ_point.lon=round(targ_point.lon,4)
    G = gps.gps(mode=gps.WATCH_ENABLE)
    lat = 0.0
    lon = 0.0
    while (lat == 0.0 and lon == 0.0):
        G.next()
        #print(G)
        lat = G.fix.latitude
        lon = G.fix.longitude
        #curr_point=point.Point(latitude, longitude)
        #curr_point.lat=round(curr_point.lat,4)
        #curr_point.lon=round(curr_point.lon,4)
        #print(" Current point is %s,%s" % (str(curr_point.lat ), str(curr_point.lon )))
        #targ_point.lat=round(targ_point.lat,4)
        #targ_point.lon=round(targ_point.lon,4)
        #print(" Target point is %s,%s" % (str(targ_point.lat ), str(targ_point.lon )))
        #distance, direction=currcd _point.guides_towards(targ_point)
        #print ( '%d km %s ' % (distance,direction))
        #if (lat==0.0 and lon==0.0):
        #time.sleep(0)
        #else:
        if (lat != 0.0 and lon != 0.0):
            curr_point = point.Point(lat, lon)
示例#21
0
def mouse_to_tile(pos, tile_width, tile_height):
    return point.Point(pos[0] // tile_width, pos[1] // tile_height)
import triangle
import point

if __name__ == '__main__':
    triangle1 = triangle.Triangle(point.Point(1, 1), \
                point.Point(3, 1), point.Point(2, 3))
    # b
    print(triangle1.is_triangle())
    # c
    print(triangle1.perimeter())
    # d
    print(triangle1.area())
def pointGeneration(a, b, c):
    i = 0
    while(i <= dataset):
        tempGen = point.Point(a, b, c)
        points.append(point.Point(a, b, c))
        i = i + 1
示例#24
0
import vehicle
import point

p = point.Point(10, 12)


def averageMilage(a):
    city = a.cty
    hwy = a.hwy
    return (city + hwy) / 2


v = vehicle.Vehicle("audi", 1.8, 1999, 4, "auto(15)", "f", 18, 29, "p",
                    "compact")
w = vehicle.Vehicle("audi", 1.8, 1999, 4, "auto(15)", "f", 21, 29, "p",
                    "compact")
u = vehicle.Vehicle("chevy", 4.8, 1999, 4, "man(15)", "f", 18, 29, "p",
                    "compact")

L = [v, w, u]
print(v)

cmv = combinedMileage(v)
print(cmv)

# K = []
# for pos in range(len(L))
#     x = L[pos]
#     if x.displ < 3:
#         K.append(x)
示例#25
0
 def test_equality(self):
     pt1 = point.Point(0.1, 2.3)
     pt2 = point.Point(0.1, 2.3)
     self.assertTrue(pt1 == pt2)
示例#26
0
def main():
    global score, max_score, max_speed, run, replay, start_menu

    pygame.init()
    clock = pygame.time.Clock()

    pygame.font.init()
    myfont = pygame.font.SysFont('ubuntu', 15)

    size = (320, 320)
    black = (0, 0, 0)
    white = (255, 255, 255)
    red = (255, 0, 0)

    screen = pygame.display.set_mode(size)
    pygame.display.set_caption('Giochino')

    p = player.Player(screen, 10, 40, 10, 10, (255, 0, 0), 2)
    max_speed = p.vel
    po = point.Point(screen, 5, 5, 5, 5, (255, 255, 255))
    po.recollocate()

    while start_menu:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit(0)

        screen.fill(black)

        start_myfont = pygame.font.SysFont('ubuntu', 30)
        game_start = start_myfont.render('Giochino', False, white)
        screen.blit(game_start, (10, 10))

        text_myfont = pygame.font.SysFont('ubuntu', 20)
        game_text = text_myfont.render('Press <SPACE> and play!', False, white)
        screen.blit(game_text, (10, 40))

        keys=pygame.key.get_pressed()

        if keys[pygame.K_SPACE]:
            start_menu = 0
            run = 1
            main()

        pygame.display.update()
        clock.tick(60)

    while run:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit(0)

        screen.fill(black)
        po.draw()

        p.draw()
        p.move()

        if p.wall_collision():
            if score <= 0:
                run = 0
            else:
                score = 0
                screen.fill((255, 0, 0))

        collision_check(p, po)

        score_text = myfont.render(('score: %(score)s Highscore: %(max_score)s' % {"score": score, "max_score": max_score}), False, white)
        speed_text = myfont.render(('Speed: %(speed)s Max speed: %(max_speed)s' % {"speed": p.vel, "max_speed": max_speed}), False, white)
        screen.blit(score_text, (10, 10))
        screen.blit(speed_text, (10, 20))

        pygame.display.update()

        clock.tick(60)

    while replay:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit(0)

        screen.fill(black)

        over_myfont = pygame.font.SysFont('ubuntu', 30)
        game_over = over_myfont.render('Game Over!', False, red)
        screen.blit(game_over, (10, 10))

        text_myfont = pygame.font.SysFont('ubuntu', 20)
        game_text = text_myfont.render('Reload with <SPACE>', False, white)
        screen.blit(game_text, (10, 40))

        score_text = text_myfont.render(('Highscore: %(max_score)s' % {"max_score": max_score}), False, white)
        speed_text = text_myfont.render(('Max speed: %(max_speed)s' % {"max_speed": max_speed}), False, white)
        screen.blit(score_text, (10, 60))
        screen.blit(speed_text, (10, 80))

        keys=pygame.key.get_pressed()

        if keys[pygame.K_SPACE]:
            run = 1
            main()

        pygame.display.update()
        clock.tick(60)
示例#27
0
 def test_point_one(self):
     pt = point.Point(1, 2)
     self.assertAlmostEqual(pt.x, 1)
     self.assertAlmostEqual(pt.y, 2)
示例#28
0
    def test_dimension(self):
        pt = point.Point(x=3)

        self.assertEqual(
            3, pt.dimension,
            "Should return the proper dimension of the point (minimum: 3")
    def process_keyed_in_coordinates_records(self,
                                             keyed_in_coordinate_records,
                                             stations,
                                             records_separator):
        """
        processes a list of records contained in '[Keyed In Coordinates]' section of Trimble file

        arguments:
        
            keyed_in_coordinate_records -- list of 'Keyed In Coordinates' records split by an equal sign,
            the result is each record is split into a record type (e.g. 'GridCoord' or 'LLCoord') and the
            record information (e.g. '1:?:DESERT VIEW:36.040770868N:111.830256442W:2263.363:?:C:C:U:E:W')

        There are two types of 'Keyed in Coordinate' records in a Trimble file:

            example one: GridCoord
         
             - 'GridCoord=1:?:CSC007437L:640995.033:237293.750:940.848:940.848:C:C:C:E'

            example two: LLCoord

             - 'LLCoord=1:?:DESERT VIEW:36.040770868N:111.830256442W:2263.363:?:C:C:U:E:W'
         
        """

        keyed_in_coordinates = {}
        
        for record in keyed_in_coordinate_records:
            record_type = record[0]
            record_information = get_record_information(record)

            if record_type == 'GridCoord':
                point_name = record_information.split(records_separator)[2]
                local_northing = functions.get_sign_digits_and_decimal(record_information.split(records_separator)[3])
                local_easting = functions.get_sign_digits_and_decimal(record_information.split(records_separator)[4])
                local_elevation = functions.get_sign_digits_and_decimal(record_information.split(records_separator)[5])
                feature_code = 'GridCoord'

                #todo: these values need to be retreived from the list of stations
                #longitude, latitude, elevation = pyproj.transform(template_spatial_reference,
                #                                                  lat_lon_spatial_ref,
                #                                                  local_easting,
                #                                                  local_northing,
                #                                                  local_elevation)

                if point_name in stations.keys():
                    latitude = stations[point_name].latitude
                    longitude = stations[point_name].longitude
                    elevation = stations[point_name].elevation

                    grid_coord = point.Point(point_name,
                                             local_easting,
                                             local_northing,                                         
                                             local_elevation,
                                             feature_code,
                                             longitude,
                                             latitude,
                                             elevation)

                    keyed_in_coordinates[point_name] = grid_coord

                else:
                    logging.warning('module:%s -- message: Point name: %s could not be found in stations' % (__name__, 
                                                                                                             self.point_name))
                    
            if record_type == 'LLCoord':
                point_name = record_information.split(records_separator)[2]
                latitude = (determine_wgs_84_sign(functions.get_alpha_characters(record_information.split(records_separator)[3])) * \
                            functions.get_sign_digits_and_decimal(record_information.split(records_separator)[3]))
                longitude = (determine_wgs_84_sign(functions.get_alpha_characters(record_information.split(records_separator)[4])) * \
                                functions.get_sign_digits_and_decimal(record_information.split(records_separator)[4]))
                elevation = functions.get_sign_digits_and_decimal(record_information.split(records_separator)[5])
                feature_code = 'LLCoord'
                
                #todo: these values need to be retreived from the list of stations
                #local_easting, local_northing, local_elevation = pyproj.transform(lat_lon_spatial_ref,
                #                                                                  template_spatial_reference,
                #                                                                  longitude,
                #                                                                  latitude,
                #                                                                  elevation)

                if point_name in stations.keys():
                    local_easting = stations[point_name].local_easting
                    local_northing = stations[point_name].local_northing
                    local_elevation = stations[point_name].local_elevation

                    ll_coord = point.Point(point_name,
                                            local_easting,
                                            local_northing,
                                            local_elevation,
                                            feature_code,
                                            longitude,
                                            latitude,                                        
                                            elevation)

                    keyed_in_coordinates[point_name] = ll_coord
                else:
                    logging.warning('module:%s -- message: Point name: %s could not be found in stations' % (__name__, 
                                                                                                             self.point_name))

        return keyed_in_coordinates
示例#30
0
def test_hash():
    p = point.Point(2, 3)
    d = {p: 1}
    assert d[p] == 1