Example #1
0
def test_polar_coord_to():
    apoint = Point(50, 50)
    bpoint = Point(87, 78)
    angle = apoint._angle_with(bpoint)
    distance = apoint._distance_to(bpoint)
    assert apoint.polar_coord_of(bpoint)['angle'] == angle
    assert apoint.polar_coord_of(bpoint)['distance'] == distance
Example #2
0
def test_init_raw():
    raw = init_raw_4()
    assert len(raw.actuators) == 4
    assert raw.orientation == 0
    assert raw.position == Point(0, 0)
    raw = init_raw_8()
    assert len(raw.actuators) == 8
    assert raw.orientation == 0
    assert raw.position == Point(0, 0)
Example #3
0
 def update_orientation(self):
     triangle = get_triangle(list(self.points.values()))
     if triangle is None:
         lc.log.debug("Triangle not found")
     else:
         middle = Point(
             (triangle['right'].x + triangle['left'].x) / 2,
             (triangle['right'].y + triangle['left'].y) / 2,
         )
         self.device.orientation = middle.angle_with(triangle['top'])
Example #4
0
def test_point_angle():
    apoint = Point(50, 50)
    data = [
        (Point(60, 50), 0),
        (Point(50, 60), 270),
        (Point(50, 40), 90),
        (Point(40, 50), 180)
    ]
    for pt, angle in data:
        angle_m = apoint._angle_with(pt)
        assert abs(angle_m - angle) <= angle * 0.01,\
            "failed for {}, {}".format(str(pt), angle)
Example #5
0
def test_polar_coord_to():
    apoint = Point(50, 50)
    bpoint = Point(87, 78)
    angle = apoint._angle_with(bpoint)
    distance = apoint._distance_to(bpoint)
    assert apoint.polar_coord_of(bpoint)['angle'] == angle
    assert apoint.polar_coord_of(bpoint)['distance'] == distance
Example #6
0
def test_point_angle():
    apoint = Point(50, 50)
    data = [(Point(60, 50), 0), (Point(50, 60), 270), (Point(50, 40), 90),
            (Point(40, 50), 180)]
    for pt, angle in data:
        angle_m = apoint._angle_with(pt)
        assert abs(angle_m - angle) <= angle * 0.01,\
            "failed for {}, {}".format(str(pt), angle)
Example #7
0
 def update_position(self):
     n_pts = len(self.points)
     if n_pts < 1:
         return
     x, y = 0, 0
     for pt in self.points.values():
         x += pt.x
         y += pt.y
     if x != 0 and y != 0:
         self.device.position = Point(int(x / n_pts * self.width),
                                      int(y / n_pts * self.height))
Example #8
0
    def open(self):
        super().open()

        self.state = 'Idle'
        self.on_graph_elem = None
        self.last_position = Point(0, 0)

        try:
            self.current_process = subprocess.Popen(
                ['say', '-v', 'Thomas', '"Initialization"'])
        except Exception as e:
            lc.log.warning("Cannot use 'say' command, (not on OSX?): ", e)
            return False
        return True
Example #9
0
def test_point_distance():
    apoint = Point(50, 50)
    bpoint = Point(50, 50)
    assert apoint == bpoint
    bpoint.x = 10
    assert apoint != bpoint
    apoint = Point(50.197, 50.197)
    data = [
        Point(60.197, 50.197),
        Point(40.197, 50.197),
        Point(50.197, 60.197),
        Point(50.197, 40.197)
    ]
    for pt in data:
        assert apoint._distance_to(pt) == 10, "failed for {}".format(str(pt))
        assert pt._distance_to(apoint) == 10
    assert apoint._distance_to(Point(50, 50)) != 0
Example #10
0
def interpret_2Dcur(*args):  # noqa
    """
        0: '/tui/2Dcur'
        1: <handler object>
        2: {set, alive, ...}
        3: <2Dcur id>
        4: x pos
        5: y pos
        6: X direction
        7 : Y direction
    """
    handler = args[1][0]
    if args[2] == 'alive':
        points = []
        i = 3
        while i < len(args):
            points.append(args[i])
            i += 1
        handler.manage(points)
    elif args[2] == 'set':
        handler.points[args[3]] = Point(args[4], args[5])
    elif args[2] == 'fseq':
        handler.update_device()
Example #11
0
def test_setters():
    raw = init_raw_8()
    raw.orientation = 30
    raw.position = Point(10, 50)
    assert raw.orientation == 30
    assert raw.position == Point(10, 50)
Example #12
0
def test_point_distance():
    apoint = Point(50, 50)
    bpoint = Point(50, 50)
    assert apoint == bpoint
    bpoint.x = 10
    assert apoint != bpoint
    apoint = Point(50.197, 50.197)
    data = [
        Point(60.197, 50.197),
        Point(40.197, 50.197),
        Point(50.197, 60.197),
        Point(50.197, 40.197)
    ]
    for pt in data:
        assert apoint._distance_to(pt) == 10, "failed for {}".format(str(pt))
        assert pt._distance_to(apoint) == 10
    assert apoint._distance_to(Point(50, 50)) != 0
Example #13
0
 def manage(self, points):
     if not self.waiting_update:
         self.waiting_update = True
         self.points = {id: Point() for id in points}