def test_circle_modify_center_from_tuple(self): """C-23. Test circle modify with center_from_tuple method.""" expected = ((3, 4), 2) circle = Circle(center=Point(1, 2), radius=2) t = (3, 4) circle.center_from_tuple(t) self.assertEqual(circle_data(circle), expected)
class DifferentObjectsTests(unittest.TestCase): def setUp(self): self.p = Cartesian(0, 0) self.p1 = Cartesian(1, 1) self.p2 = Cartesian(10, 20) self.circ = Circle(self.p, 5) self.circ1 = Circle(self.p1, 1) self.circ2 = Circle(self.p2, 1) self.p5 = Cartesian(1, 3) self.p6 = Cartesian(2, 4) self.p7 = Cartesian(4, 2) self.p8 = Cartesian(3, 1) self.poly2 = Polygon(self.p5, self.p6, self.p7, self.p8) self.p9 = Cartesian(-1, 1) self.p10 = Cartesian(2, 1) self.p11 = Cartesian(2, -1) self.p12 = Cartesian(-1, -1) self.poly3 = Polygon(self.p9, self.p10, self.p11, self.p12) def test_circle_overlapping_polygon_intersect(self): self.assertTrue(self.poly2.intersect(self.circ1)) self.assertTrue(self.circ1.intersect(self.poly2)) def test_circle_not_overlapping_polygon_dont_intersect(self): self.assertFalse(self.poly2.intersect(self.circ2)) self.assertFalse(self.circ2.intersect(self.poly2))
def test_change_center(self): """C-9. Verify center attribute change works.""" expected = ((3, 4), 3) circle = Circle(Point(1, 2), 3) point1 = Point(3, 4) circle.center = point1 self.assertEqual(circle_data(circle), expected)
def test_circle_modify_center_from_tuple(self): """C-23. Test circle modify with center_from_tuple method.""" expected = ((3, 4), 5) circle = Circle(Point(1, 2), 5) new_center = 3, 4 circle.center_from_tuple(new_center) self.assertEqual(circle_data(circle), expected)
def test_circle_modification_center_from_tuple(self): """C-23. Verify Circle modification with center_from_tuple method.""" circle = Circle() new_center = 2, 3 circle.center_from_tuple(new_center) expected = ((2, 3), 1) self.assertEqual(circle_data(circle), expected)
def get_bubble_from_signal(sig_x, sig_y, sig_z, calib_radius_func, sigma=1, flip_signal=False, verbose=False): if flip_signal: sig_z = np.flip(sig_z, axis=0) sig_z = smooth(sig_z, sigma=sigma) first_peak_arg, second_peak_arg = get_salient_peaks(sig_z) radius = calib_radius_func(np.abs(second_peak_arg - first_peak_arg) / 2) max_peak_x = sig_x[first_peak_arg] if verbose: print("first_peak_arg:", first_peak_arg) print("second_peak_arg", second_peak_arg) if np.isnan(second_peak_arg): return Circle(0, 0, 1) else: second_peak_x = sig_x[second_peak_arg] if verbose: print("max_peak_x", max_peak_x) print("second_peak_x", second_peak_x) cent_x = (max_peak_x + second_peak_x) / 2 cent_y = sig_y[0] return Circle(cent_x, cent_y, radius)
def setUp(self): self.p = Cartesian(0, 0) self.p1 = Cartesian(1, 1) self.p2 = Cartesian(10, 20) self.circ = Circle(self.p, 5) self.circ1 = Circle(self.p1, 1) self.circ2 = Circle(self.p2, 1)
def test_circle_point_objects_different(self): """C-0. Make sure Circle centers are different objects for default.""" # In other words, they should have the same VALUES, # But NOT be the same objects. circle1 = Circle() circle2 = Circle() self.assertIsNot(circle1.center, circle2.center) self.assertEqual(circle_data(circle1), circle_data(circle2))
def test_c03_create_only_radius_input(self): """C-03. Create Circle with radius but no Point.""" expected = ((0, 0), 2.5) circle = Circle(radius=2.5) self.assertEqual(circle_data(circle), expected) # Make sure radius=0 works (edge case of Circles) expected = ((0, 0), 0) circle = Circle(radius=0) self.assertEqual(circle_data(circle), expected)
def test_c02_create_only_point_input(self): """C-02. Create Circle with Point but no radius.""" expected = ((2, 3), 1) circle = Circle(center=Point(2, 3)) self.assertEqual(circle_data(circle), expected) # Also make sure the circle's center is the same as the point input. point = Point(2, 3) point_id = id(point) circle = Circle(center=point) self.assertEqual(circle_data(circle), expected) self.assertEqual(point_id, id(circle.center))
def test_circle_addition(self): """C-17. Verify Circle addition.""" expected1 = ((2, 3), 1) expected2 = ((1, 2), 2) expected3 = ((3, 5), 3) circle1 = Circle(center=Point(2, 3)) circle2 = Circle(center=Point(1, 2), radius=2) circle3 = circle1 + circle2 # Ensure original circles unchanged self.assertEqual(circle_data(circle1), expected1) self.assertEqual(circle_data(circle2), expected2) self.assertEqual(circle_data(circle3), expected3)
def test_circle_addition(self): """C-17. Verify Circle addition.""" expected1 = ((1, 1), 2) expected2 = ((2, 2), 3) expected3 = ((3, 3), 5) circle1 = Circle(Point(1, 1), 2) circle2 = Circle(Point(2, 2), 3) circle3 = circle1 + circle2 # Ensure original circles unchanged self.assertEqual(circle_data(circle1), expected1) self.assertEqual(circle_data(circle2), expected2) # Verify new circle is correct self.assertEqual(circle_data(circle3), expected3)
def test_circle_addition(self): """C-17. Verify Circle addition.""" expected1 = ((1, 1), 2.5) expected2 = ((2, 3), 1) expected3 = ((3, 4), 3.5) circle1 = Circle(radius=2.5, center=Point(1, 1)) circle2 = Circle(center=Point(2, 3), radius=1) circle3 = circle1 + circle2 self.assertEqual(circle_data(circle1), expected1) self.assertEqual(circle_data(circle2), expected2) self.assertEqual(circle_data(circle3), expected3)
def test_circle_plus_equals(self): """C-17a. Verify Circle += mutating addition.""" expected1 = ((3, 4), 3.5) expected2 = ((2, 3), 1) circle1 = Circle(radius=2.5, center=Point(1, 1)) circle2 = Circle(center=Point(2, 3), radius=1) id1 = id(circle1) circle1 += circle2 self.assertEqual(circle_data(circle2), expected2) self.assertEqual(circle_data(circle1), expected1) self.assertEqual(id(circle1), id1)
def test_circle_plus_equal_addition(self): """C-17a. Verify Circle += mutating addition.""" expected1 = ((3, 5), 3) expected2 = ((1, 2), 2) circle1 = Circle(center=Point(2, 3)) # Save id of circle1 for checking later id1 = id(circle1) circle2 = Circle(center=Point(1, 2), radius=2) circle1 += circle2 # Check circle1 is still same object self.assertEqual(id(circle1), id1) # Verify addition worked self.assertEqual(circle_data(circle1), expected1) # Ensure original circle2 unchanged self.assertEqual(circle_data(circle2), expected2)
def test_circle_plus_equal_addition(self): """C-17a. Verify Circle += mutating addition.""" expected = ((3, 5), 8) circle1 = Circle(Point(2, 3), 4) # Save the id to make sure it doesn't change. id1 = id(circle1) circle2 = Circle(Point(1, 2), 4) # Add using += circle1 += circle2 self.assertEqual(circle_data(circle1), expected) # Verify circle2 has not changed expected = ((1, 2), 4) self.assertEqual(circle_data(circle2), expected) # Verify that point1 is the same object self.assertEqual(id(circle1), id1)
def mousePressEvent(self, event): # отслеживание кликов по мыши и добавление фигуры в список if self.instrument == 'brush': self.objects.append([]) self.objects[-1].append(BrushPoint(event.x(), event.y(), self.thickness, self.color)) self.update() elif self.instrument == 'line': self.objects.append(Line(event.x(), event.y(), event.x(), event.y(), self.thickness, self.color)) self.update() elif self.instrument == 'circle': self.objects.append(Circle(event.x(), event.y(), event.x(), event.y(), self.thickness, self.color)) self.update() elif self.instrument == 'rubber': self.objects.append([]) self.objects[-1].append(BrushPoint(event.x(), event.y(), self.thickness, QColor(240, 240, 240))) self.update() elif self.instrument == 'rect': self.objects.append(Rect(event.x(), event.y(), 0, 0, self.thickness, self.color)) self.update() elif self.instrument == 'square': self.objects.append(Rect(event.x(), event.y(), 0, 0, self.thickness, self.color)) self.update() elif self.instrument == 'triangle': self.objects.append(Triangle(event.x(), event.y(), event.x(), event.y(), self.thickness, self.color)) self.update() elif self.instrument == 'sqtriangle': self.objects.append(SqTriangle(event.x(), event.y(), event.x(), event.y(), self.thickness, self.color)) self.update()
def test_move_center(self): """C-5A. Verify moving center Point of Circle works.""" expected = ((6, 2), 1.5) point = Point(2, 3) circle = Circle(point, 1.5) point.x = 6 point.y = 2 self.assertEqual(circle_data(circle), expected)
def setUp(self): self.init_kwargs = {} self.init_kwargs["xCoord"] = 50 self.init_kwargs["yCoord"] = 50 measurements = {"radius": 50} self.init_kwargs["measurements"] = measurements self.area = 3.14 * measurements["radius"]**2 self.shape = Circle(**self.init_kwargs)
class TestUnitCircle(TestCircle): circle = Circle(1) def test_area(self): assert self.circle.get_area() == math.pi def test_perimeter(self): assert self.circle.perimeter == 2 * math.pi
class CirclesTestCases(unittest.TestCase): """Test cases with only circles""" def setUp(self): self.p = Cartesian(0, 0) self.p1 = Cartesian(1, 1) self.p2 = Cartesian(10, 20) self.circ = Circle(self.p, 5) self.circ1 = Circle(self.p1, 1) self.circ2 = Circle(self.p2, 1) def test_perimeter(self): self.assertAlmostEqual(self.circ1.perimeter(), 2*pi) def test_edge_of_circle_in_circle(self): test_point = Cartesian(5, 0) self.assertTrue(self.circ.point_in_circle(test_point)) def test_point_outside_of_circle(self): test_point = Cartesian(10, 10) self.assertFalse(self.circ.point_in_circle(test_point)) def test_two_intersecting_circles_intersect(self): self.assertTrue(self.circ.intersect(self.circ1)) # Make sure it's reflexive self.assertTrue(self.circ1.intersect(self.circ)) def test_two_nonintersecting_circles_not_intersect(self): self.assertFalse(self.circ.intersect(self.circ2)) # make sure it's relfexive self.assertFalse(self.circ2.intersect(self.circ))
def test_properties(self): """Test circle properties""" c = Circle(d=12.0) self.assertAlmostEqual(c.A(), 113.097, places=2) self.assertAlmostEqual(c.I(), 1017.875, places=2) self.assertAlmostEqual(c.S(), 169.646, places=2) self.assertAlmostEqual(c.Z(), 288.000, places=2) self.assertAlmostEqual(c.r(), 3.0, places=2)
def add_wafer_outline(self): """ Create Wafer Outline """ outline=Cell('WAF_OLINE') for l in self.cell_layers: circ=Circle((0, 0), self.wafer_r, 100, layer=l) outline.add(circ) # outline.add(Disk(l, (0,0), self.wafer_r, self.wafer_r-10)) self.add(outline)
class TestCircle(object): radius = 10 circle = Circle(radius) def test_area(self): expected = math.pi * self.__class__.radius**2 assert self.circle.get_area() == expected def test_perimeter(self): expected = 2 * math.pi * self.__class__.radius assert self.circle.perimeter == expected
def main(): shapes: list = [ Circle(5), Rectangle(3, 3), Rectangle(4, 4), Triangle(3, 4), ] for shape in shapes: logging.debug( "type: {0}, circumference = {1:.2f}, area = {2:.2f}".format( type(shape), shape.circumference(), shape.area()))
def __init__(self, master): self.temp_clicked_values = [] self.lines_of_poly_widgets = [] # for clicked poly # holds the labels that update to show user clicked input self.angle_vertices_labels = [] self.poly_vertices_labels = [] self.web_vertices_labels = [] # holds the user input boxes for typed input self.angle_vertices_entries = [] self.poly_vertices_entries = [] self.web_vertices_entries = [] self.poly_each_vertex_labels = [] self.web_msgs = ["Top of y-axis: ", "Bottom of y-axis: ", "Left of x-axis: ", "Right of x-axis: "] self.circle_ids = Circle.get_all_circles() self.label_ids = Circle.get_all_labels() # GUI elements self.master = master self.master.title("Parabolic Curves") self.base_frame1 = tk.Frame(self.master) self.base_frame2 = tk.Frame(self.master) self.canvas = tk.Canvas(self.base_frame1, width=CANVAS_SIZE, height=CANVAS_SIZE, bg="white") self.base_frame1.grid(row=0, column=0) self.base_frame2.grid(row=0, column=1) self.canvas.grid(row=0, column=0) self.instantiate_circles() self.create_shape_controls() self.create_input_controls() self.create_toggled_frames() self.create_buttons() self.create_status_bar() self.mouse_click_counter = 0 self.color = 'black' # default color
class TestCircle(unittest.TestCase): @classmethod def setUpClass(cls): # do setup operations here for all tests once print("setUpClass") def setUp(self): # do setup operations here for each test print("setUp") self.c1 = Circle(3, "red") self.c2 = Circle(5, "green") def test_colors(self): print("test_colors") self.assertEqual(self.c1.color, "red") self.assertEqual(self.c2.color, "green") self.c1.change_color("blue") self.c2.change_color("blue") self.assertEqual(self.c1.color, "blue") self.assertEqual(self.c2.color, "blue") def test_area(self): print("test_area") self.assertAlmostEqual(self.c1.compute_area(), math.pi * 3**2) self.assertAlmostEqual(self.c2.compute_area(), math.pi * 5**2) def tearDown(self): # do teardown operations here for each test print("tearDown\n") @classmethod def tearDownClass(cls): # do teardown operations here for all tests once print("teardownClass")
def main() -> None: shape1 = Rectangle(100, 200) shape2 = Square(100) shape3 = Circle(100) print('Shape1 surface: {}'.format(shape1.surface)) print('Shape1 perimiter: {}'.format(shape1.perimeter)) print('Shape2 surface: {}'.format(shape2.surface)) print('Shape2 perimiter: {}'.format(shape2.perimeter)) print('Shape3 surface: {}'.format(shape3.surface)) print('Shape3 perimiter: {}'.format(shape3.perimeter))
def setUp(self): self.p = Cartesian(0, 0) self.p1 = Cartesian(1, 1) self.p2 = Cartesian(10, 20) self.circ = Circle(self.p, 5) self.circ1 = Circle(self.p1, 1) self.circ2 = Circle(self.p2, 1) self.p5 = Cartesian(1, 3) self.p6 = Cartesian(2, 4) self.p7 = Cartesian(4, 2) self.p8 = Cartesian(3, 1) self.poly2 = Polygon(self.p5, self.p6, self.p7, self.p8) self.p9 = Cartesian(-1, 1) self.p10 = Cartesian(2, 1) self.p11 = Cartesian(2, -1) self.p12 = Cartesian(-1, -1) self.poly3 = Polygon(self.p9, self.p10, self.p11, self.p12)
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 __init__(self, x, y, radius, degree=150, scanning_max=360, scanning_min=0, scanning_mode="CIRCLE", origin="PERIMETER"): #TODO origin = CENTER is broken for rebroadcasting self.uuid = str(uuid.uuid4()) self.x = x self.y = y self.radius = radius # for drawing self.colorDict = dict() self.lastColor = colour.Color("Blue") self.shape = Shape(center=(self.x, self.y)) self.circle = Circle(self.radius * 2) # end drawing section self.rays = [] self.vertex_list = None r_b = [ color for color in colour.Color("Red").range_to( colour.Color("Green"), 120) ] b_g = [ color for color in colour.Color("Green").range_to( colour.Color("Blue"), 120) ] g_r = [ color for color in colour.Color("Blue").range_to( colour.Color("Red"), 120) ] self.colors = r_b + b_g + g_r self.energy = 0 self.energy_color = None self.scanning_max = scanning_max self.scanning_min = scanning_min if degree > self.scanning_max: degree = self.scanning_max elif degree < self.scanning_min: degree = self.scanning_min self.degree = degree self.scanning_mode = scanning_mode #self.scanning_mode_options = ["CIRCLE", "RANDOM"] self.origin = origin
def draw(self, shape): # Method drawing a shape on the canvas. self.__canvas.delete(self.__tmp_rendered) rendered_shape = None if shape['type'] == 'rectangle' and shape['mode'] == 'normal': rendered_shape = Rectangle(shape) elif shape['type'] == 'rectangle' and shape['mode'] == 'straight': rendered_shape = Square(shape) elif shape['type'] == 'oval' and shape['mode'] == 'normal': rendered_shape = Oval(shape) elif shape['type'] == 'oval' and shape['mode'] == 'straight': rendered_shape = Circle(shape) elif shape['type'] == 'line' and shape['mode'] == 'normal': rendered_shape = Line(shape) elif shape['type'] == 'line' and shape['mode'] == 'straight': rendered_shape = Diagonal(shape) shape_id = rendered_shape.draw_on(self.__canvas) return shape_id
def addCircle(self, xy=(0, 0), diameter=None, radius=None, label="", fc='none', color='k', lw=2, mplprops={}): if diameter != None: diameter = self.cust_float(diameter) if radius != None: radius = self.cust_float(radius) circle = Circle.Circle(self.cust_float(xy), diameter, radius, label, fc, color, lw, mplprops, self) self.drawOrder.append(circle) return circle
def revolution_animate(self, ring='n'): """Function that makes the animation of moviment""" if ring == 'y': self.draw_ring() if self.__revolution_loop == self.__number_revolution: self.__revolution_loop = 0 x = self.orbit_list[self.__revolution_loop].x y = self.orbit_list[self.__revolution_loop].y z = self.orbit_list[self.__revolution_loop].z if self.__mode == "2D": Circle(x, y, self.radius, self.__total).draw() else: Sphere(x, y, z, self.radius, self.__total, self.color).draw() self.__revolution_loop += 1