def loadSettings(self): self.settings = self.getSettings(self._appName) if self.settings['workPosition'] != "": workPositionPts = list( map(int, self.settings['workPosition'].split(','))) self.workPosition = Rectangle.Rectangle( Point.Point(workPositionPts[0], workPositionPts[1]), Point.Point(workPositionPts[2], workPositionPts[3])) self.workPositionThreshold = self.settings['workPositionThreshold']
def __init__(self, radius: float, point: Point): super(Circle, self) self.radius = radius self.point = point if radius is None or point is None: raise Exception(Messages.C_MS02) x = radius error = 1 - x y = 0 while y <= x: self.points.append(Point(x=x + point.x, y=y + point.y)) self.points.append(Point(x=y + point.x, y=x + point.y)) self.points.append(Point(x=-x + point.x, y=y + point.y)) self.points.append(Point(x=-y + point.x, y=x + point.y)) self.points.append(Point(x=-x + point.x, y=-y + point.y)) self.points.append(Point(x=-y + point.x, y=-x + point.y)) self.points.append(Point(x=x + point.x, y=-y + point.y)) self.points.append(Point(x=y + point.x, y=-x + point.y)) y = y + 1 if error < 0: error += 2 * y + 1 else: x = x - 1 error += 2 * (y - x + 1)
def __to_point(self, lua_table): if not lua_table: return None # assumption that this is a lua table type p = dict(zip('xyz', lua_table.values())) return Point(**p)
def createGameRectangle(self, minSize, xRange, yRange): widthPt = random.randint(xRange[0], xRange[1]) heightPt = random.randint(yRange[0], yRange[1]) if widthPt + minSize > xRange[1]: xRight = widthPt xLeft = widthPt - minSize else: xLeft = widthPt xRight = widthPt + minSize if heightPt + minSize > yRange[1]: yBottom = heightPt yTop = heightPt - minSize else: yTop = heightPt yBottom = heightPt + minSize rect = Rectangle.Rectangle(Point.Point(xLeft, yTop), Point.Point(xRight, yBottom)) return rect
def test_find_most_suitable_station() -> None: stations = [ Station(Point(0, 0), 10), Station(Point(20, 20), 5), Station(Point(10, 0), 12) ] assert find_most_suitable_station(stations, Device(Point(0, 0))) == \ StationPower(Station(Point(0, 0), 10), 100.0) assert find_most_suitable_station(stations, Device(Point(100, 100))) is None station, power = find_most_suitable_station(stations, Device(Point(15, 10))) assert station.point == Point(x=10, y=0) assert station.reach == 12 assert round(power, 2) == 0.67 station, power = find_most_suitable_station(stations, Device(Point(18, 18))) assert station.point == Point(x=20, y=20) assert station.reach == 5 assert round(power, 2) == 4.72
def main(): apoint = Point(x=100, y=80) bpoint = Point(x=160, y=200) cpoint = Point(x=220, y=80) circle = Circle(radius=10, point=apoint) triangle = Triangle(lines=[StraightLine(a=apoint, b=bpoint), StraightLine(a=apoint, b=cpoint), StraightLine(a=bpoint, b=cpoint)]) canvas1 = Canvas(250, 250, Point(x=200, y=200), "canvas1", [triangle, circle], show_cp=True) canvas2 = Canvas(260, 260, Point(x=450, y=450), "canvas2", [circle], show_cp=True) canvas3 = Canvas(270, 270, Point(x=710, y=710), "canvas3", [circle], show_cp=True) canvas_list = [canvas1, canvas2, canvas3] screen = TkinterScreen() screen.configure(canvas_list) board = Board(screen) board.draw_at()
def stations_from_json(stations: str) -> List[Station]: return [Station(Point(station[0], station[1]), station[2]) for station in json.loads(stations)]
def device_from_json(point: str) -> Device: return Device(Point(*json.loads(point)))
vertices = mesh.vertices triangles = mesh.triangles normals = mesh.normals print 'Num vertices:', len(vertices) print 'Num triangles:', len(triangles) print 'Num normals:', len(normals) # 1. Generate candidate pairs of contact points # 2. Check for force closure # 3. Convert each grasp to a hand pose contact1 = vertices[500] contact2 = vertices[2000] T_obj_gripper = contacts_to_baxter_hand_pose(contact1, contact2) print 'Translation', T_obj_gripper.translation print 'Rotation', T_obj_gripper.quaternion pose_msg = T_obj_gripper.pose_msg # 3d visualization to help debug vis.figure() vis.mesh(mesh) vis.points(Point(contact1, frame='test')) vis.points(Point(contact2, frame='test')) vis.pose(T_obj_gripper, alpha=0.05) vis.show() # 4. Execute on the actual robot
def test_point_from_json(): assert device_from_json('[0, 0]') == Device(Point(0, 0))
def test_stations_from_json(): assert stations_from_json("[[0, 0, 10]]") == [Station(Point(0, 0), 10)]
#!/usr/bin/env python import sys; sys.path.append("..") from core import Point, Sequence from core import OFFSET_64, MIDI_PITCH, DURATION_64 ## points p1 = Point({ OFFSET_64: 16, MIDI_PITCH: 50, DURATION_64: 16, }) assert p1.tuple(OFFSET_64, DURATION_64) == (16, 16) ## sequences p2 = Point({ OFFSET_64: 32, MIDI_PITCH: 52, DURATION_64: 16, }) s1 = Sequence([p1, p2]) assert s1 == [ {DURATION_64: 16, OFFSET_64: 16, MIDI_PITCH: 50},
def test_enrich_stations_with_power() -> None: stations = [Station(Point(0, 0), 10)] device = Device(Point(0, 0)) assert list(enrich_stations_with_power( stations, device)) == [StationPower(Station(Point(0, 0), 10), 100.0)]
def test_distance_to_station() -> None: assert distance_to_station(Point(0, 0), Point(0, 0)) == 0 assert distance_to_station(Point(0, 0), Point(10, 0)) == 10.0 assert distance_to_station(Point(10, 0), Point(0, 0)) == 10.0