Пример #1
0
    def min_line_cover_greedy_worker(centers, lines, cover, segments):

        # Compute the centers the closest centers

        max_min_center, max_min_radius = find_tightest_enclosing_circle(
            centers, cover, lines)

        # Check if this circle is already in our cover.

        found = [(i, c) for (i, c) in enumerate(
            [k for k in cover if max_min_center == k.get_center()])]

        if len(found) != 0:
            c = found[0][1]
            index = found[0][0]
            assert c.get_radius() <= max_min_radius
            newRadius = max(max_min_radius, c.get_radius())
            c.set_radius(newRadius)
            newlines, included_lines = c.intersects_lines(lines)
            segments[index] = segments[index] + included_lines
        else:
            c = ccle.Circle(max_min_center, max_min_radius)
            cover.append(c)
            newlines, included_lines = c.intersects_lines(lines)
            segments.append(included_lines)

        if len(newlines) == 0:
            # no more line segments left to cover -- we are done.
            return cover, segments
        else:
            # Remove all the centers within our distance constraint so our constraint
            # is satisfied.
            if max_min_center in centers:
                centers.remove(max_min_center)

        # eliminate all centers that are closer than the desired threshold
        centers_to_remove = [
            cntr for cntr in centers if cntr != max_min_center
            and distance(cntr, max_min_center) < min_center_distance
        ]
        for c in centers_to_remove:
            centers.remove(c)
        return min_line_cover_greedy_worker(centers, newlines, cover, segments)
Пример #2
0
    def test_math(self):
        c1 = MOc.Circle(2)
        c2 = MOc.Circle(4)

        # add 2 classes
        self.assertEqual((c1 + c2).radius, MOc.Circle(6).radius)
        # add class + int
        self.assertEqual((c1 + 4).radius, MOc.Circle(6).radius)
        # add int + class
        self.assertEqual((2 + c2).radius, MOc.Circle(6).radius)

        # mult 2 classes
        self.assertEqual((c1 * c2).radius, MOc.Circle(8).radius)
        # mult class + int
        self.assertEqual((c1 * 4).radius, MOc.Circle(8).radius)
        # mult int + class
        self.assertEqual((2 * c2).radius, MOc.Circle(8).radius)

        # doing math with anything other than int should error out
        with self.assertRaises(TypeError):
            c1 + "try me"
    def test_Circle_sort(self):
        c_list = []
        # for i in range(1, 1000000):      # comment out print statements before activating this line ;))
        for i in range(1, 100):
            circle = ci.Circle(ra.randint(5, 3000000))
            c_list.append(circle)
        # for c in c_list:
        #     print('item in c_list: {}'.format(c))

        s_list = sorted(c_list)

        for i, j in enumerate(s_list[:-1]):
            # print('index in s_list: {}, content object: {}'.format(i, j))
            # print('next index in s_list: {}, next content object: {}'.format(i+1, s_list[i+1]))
            c1 = j
            c2 = s_list[i + 1]
            # self.assertLess(c1.radius, c2.radius)
            self.assertLessEqual(
                c1.radius,
                c2.radius)  # this has to be LessEqual instead of Less,
Пример #4
0
def main():
    circles = [
        circle.Circle(WIN, (200, i * 110), ratios[i - 1],
                      pygame.mixer.Sound(f'./audio/{9 - i}.wav'))
        for i in range(1, 9)
    ]
    counter = 0
    clock = pygame.time.Clock()
    run = True
    while run:
        clock.tick(FPS)
        time_since_start = counter
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False

        draw_window(circles, time_since_start)
        counter += 1

    pygame.quit()
Пример #5
0
 def compute_excess_area_for_circle_cover_from_file(fileName):
     with open(fileName) as f:
         result = json.load(f)
         ic_x = result["ic_x"]
         ic_y = result["ic_y"]
         interference_contour = [(ic_x[i], ic_y[i])
                                 for i in range(0, len(ic_x))]
         esc_loc_x = result["esc_loc_x"]
         esc_loc_y = result["esc_loc_y"]
         possible_centers = [(esc_loc_x[i], esc_loc_y[i])
                             for i in range(0, len(esc_loc_x))]
         sensor_loc_x = result["sensor_loc_x"]
         sensor_loc_y = result["sensor_loc_y"]
         radii = result["sensor_detection_radius"]
         cover = [
             circle.Circle(center=(sensor_loc_x[i], sensor_loc_y[i]),
                           radius=radii[i])
             for i in range(0, len(sensor_loc_x))
         ]
         return compute_excess_area_for_circle_cover(
             cover, possible_centers, interference_contour)
Пример #6
0
def run_movie(cfg: configuration.Configuration, runner: run.Runner, only_plot=False,
              only_save=False):
    """Create the video."""
    movie = Movie()
    movie.background([(cfg, "black")])  # draws the cubes
    cheerios, result = run.Run(runner).run()  # runs the algorithm/analysis specified by runner
    # returns a list of points (class p) specifying the location of the load over time and a
    # boolean variable describing whether the run was successful
    print(result)
    if only_plot or only_save:
        movie.background([(MotionPath(cheerios), "green")])  # draws the simulated load path
        if only_save:
            movie.save_figure(cfg.file_name + "_image")
        else:
            movie.just_draw()  # plotting without saving
    else:
        # Creating a video of the simulated load moving through the cube maze
        to_draw = []
        # create list of tuples(Circle,str), one for each frame to be drawn in the animation
        for cheerio in cheerios:
            to_draw.append([(circle.Circle(cheerio, cfg.cheerio_radius), "green")])
        movie.run_animation(to_draw, 0)  # drawing the load
Пример #7
0
def generate_diagram():
    global scanline, screen, width, height, events, points
    v.ly = scanline
    #    point = (250,300)
    screen.fill((0, 0, 0))
    vertices = []
    #draw the line
    pygame.draw.line(screen, (128, 0, 0), (0, scanline), (width, scanline))
    circles = []
    currentPoint = 0
    prev = None
    prevPrev = None
    for point in points:
        py, px, pColour = point
        if py == scanline:
            pygame.draw.line(screen, pColour, (px, scanline), (px, 0))
        elif py < scanline:
            arc = []
            for x in range(width):
                arcy = v._getY((px, py), x)
                arc.append((x, arcy))
            pygame.draw.lines(screen, pColour, False, arc, 1)
        if py <= scanline:
            if prev and prevPrev:
                c = circle.Circle(prev, prevPrev, (px, py))
                circles.append(c)
            prevPrev = prev
            prev = (px, py)

    for c in circles:
        calculated = c.CalcCircle()
        if calculated:
            cx, cy, r = calculated
            pygame.draw.circle(screen, (200, 200, 200), (int(cx), int(cy)),
                               int(r), 1)
    for point in points:
        py, px, pColour = point
        pygame.draw.circle(screen, pColour, (px, py), 3)
Пример #8
0
def test_1():
    """Create a circle with a radius attribute."""

    c = circle.Circle(4)
    assert c.radius == 4
    c.radius = 5
    assert c.radius == 5

    # Non integer values used to initialize radius
    c1 = circle.Circle("3.14")
    c2 = circle.Circle(4.21)
    c3 = circle.Circle(2.3e6)

    # Verify that the circle only accepts radius inputs that can be
    # converted to floats
    with pt.raises((TypeError, ValueError)):
        c4 = circle.Circle("bologna")
    with pt.raises((TypeError, ValueError)):
        c5 = circle.Circle(2 + 4j)
Пример #9
0
 def test_rmul(self):
     ci = c.Circle(4)
     self.assertEqual(ci * 3, c.Circle(12))
Пример #10
0
 def test_Circle_init(self):
     ci = c.Circle(6)
     self.assertEqual(ci.radius, 6)
Пример #11
0
 def test_repr(self):
     ci = c.Circle(4)
     self.assertEqual(repr(ci), 'Circle(4)')
Пример #12
0
 def test_area_setter(self):
     ci = c.Circle(4)
     with pytest.raises(AttributeError):
         ci.area = 4
Пример #13
0
 def test_diameter_setter(self):
     ci = c.Circle(6)
     ci.diameter = 6
     self.assertEqual(ci.radius, 3)
     self.assertEqual(ci.diameter, 6)
Пример #14
0
import circle
# список для хранения данных
list_of_circles = []
# цикл для создания переменных с данными
for a_circle in ['a_circle_1', 'a_circle_2']:
    a_circle = circle.Circle(int(input('Введите координату Х: ')),
                             int(input('Введите координату У: ')),
                             int(input('Введите радиу окружности: ')))
    list_of_circles.append(a_circle)
    # вывод периметра и площади
    print('Площадь окружности равена: ', a_circle.square())
    print('Периметр окружности равен: ', a_circle.perimeter())
    # запрос и вывод умеличения радиуса
    request_for_an_increase = input(
        '\nХотите ли учеличить радиус окружности? да\нет ')
    a_circle.increase(request_for_an_increase)
# вычисление растояние между центрами и сравниваем их пересечения
distance = (list_of_circles[0].x - list_of_circles[1].x)**2
+(list_of_circles[0].y - list_of_circles[1].y)**2
print('\nОкружность пересекаются.' if (list_of_circles[0].r -
                                       list_of_circles[1].r)**2 <= distance <=
      (list_of_circles[0].r +
       list_of_circles[1].r)**2 else 'Окружность не пересекается')
import Figures.quadrangles.square as square, circle, triangle

sq = square.Square(5)
print("Field: ", sq.getField(), " Perimeter: ", sq.getCircunference())

tr = triangle.EquilateralTriangle(5)
print("Field: ", tr.getField(), " Perimeter: ", tr.getCircunference())

ci = circle.Circle(5)
print("Field: ", ci.getField(), " Perimeter: ", ci.getCircunference())
Пример #16
0
def test_area_property():
    cir = c.Circle(10)
    assert cir.area == 314.159265, ('Step 4: Area Property')
Пример #17
0
def test_str_repr():
    cir = c.Circle(4)
    assert str(cir) == 'Circle with radius: 4', ('Step 6: str')
    assert repr(cir) == '\'Circle(4)\'', ('Step 6: repr')
    assert eval(repr(cir)) == 'Circle(4)', ('Step 6: eval repr')
import circle
from math import pi
import pytest

test = circle.Circle(5)


def test_radius():
    assert (test.radius == 5)


def test_diameter():
    assert (test.diameter == 10)


def test_set_diameter():
    test.diameter = 20
    assert (test.diameter == 20)
    assert (test.radius == 10)


def test_from_diameter():
    diam_test = circle.Circle.from_diameter(30)
    assert (diam_test.radius == 15)


def test_add_():
    circle1 = circle.Circle(1)
    circle2 = circle.Circle(2)
    assert (circle1 + circle2 == 3)
Пример #19
0
 def test_diameter_property(self):
     ci = c.Circle(3)
     self.assertEqual(ci.diameter, 6)
def test_add_():
    circle1 = circle.Circle(1)
    circle2 = circle.Circle(2)
    assert (circle1 + circle2 == 3)
Пример #21
0
 def test_area_property(self):
     ci = c.Circle(4)
     self.assertEqual(ci.area, 16 * m.pi)
def test_mult_():
    circle1 = circle.Circle(1)
    circle2 = circle.Circle(2)
    assert (circle1 * circle2 == 2)
Пример #23
0
 def test_str(self):
     ci = c.Circle(4)
     self.assertEqual(str(ci), 'Circle with radius: 4')
def test_comparison():
    circle1 = circle.Circle(1)
    circle2 = circle.Circle(2)
    assert (circle1 != circle2)
    assert (circle1 < circle2)
    assert (circle1 <= circle2)
Пример #25
0
 def test_add(self):
     ci = c.Circle(4)
     cl = c.Circle(2)
     self.assertEqual(ci + cl, c.Circle(6))
Пример #26
0
def test_radius():
    cir = c.Circle(10)
    assert cir.radius == 10, ('Step 1: Radius')
Пример #27
0
 def test_mul(self):
     ci = c.Circle(4)
     self.assertEqual(3 * ci, c.Circle(12))
Пример #28
0
def test_diameter():
    cir = c.Circle(20)
    assert cir.diameter == 40, ('Step 2: Diameter')
Пример #29
0
 def test_check_for_positives(self):
     c1 = circle.Circle(1)
     self.assertEqual(c1.area, pi)
Пример #30
0
def test_diameter_property():
    cir = c.Circle(10)
    cir.diameter = 10
    assert cir.diameter == 10, ('Step 3: Diameter Property (diameter)')
    assert cir.radius == 5, ('Step 3: Diameter Property (radius)')