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
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)
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'])
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)
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)
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))
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
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
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()
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)
def manage(self, points): if not self.waiting_update: self.waiting_update = True self.points = {id: Point() for id in points}