Esempio n. 1
0
def test_str():
    c = Circle(1)
    assert str(c) == 'Circle, r=1.0'
    c.radius = 3.5
    assert str(c) == 'Circle, r=3.5'
    c.radius = 5.69793829485950684
    assert str(c) == 'Circle, r=5.7'
Esempio n. 2
0
 def __init__(self, name, x, y, radius, theta):
     Circle.__init__(self, name, radius, (250, 250, 0), x, y)
     self.theta = theta
     self.speed = 20.
     self.vX = self.speed * cos(self.theta)
     self.vY = self.speed * sin(self.theta)
     self.theta = theta
 def test_multiplication(self):
     """"Tests multiplication"""
     c1 = Circle(2)
     c2 = Circle(4)
     c3 = Circle(8)
     c4 = c1 * c2
     self.assertEqual(c3, c4)
 def test_addition(self):
     """Tests addition."""
     c1 = Circle(2)
     c2 = Circle(4)
     c3 = Circle(6)
     c4 = c1 + c2
     self.assertEqual(c3, c4)
Esempio n. 5
0
    def test_FitSmallestCircleExternalImpl(self):
        generator = Random2DPointsSetGenerator(nPointsMin=25,
                                               nPointsMax=60,
                                               xmin=-15,
                                               xmax=15,
                                               ymin=-15,
                                               ymax=15,
                                               stub=False)
        euclideanDist = lambda p1, p2: pow(
            pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2), 0.5)

        for testIter in range(MaxTestIter):
            randomPoints = generator.Generate()
            radius, center = FitCircleTo2DPoints(randomPoints,
                                                 useExternalImpl=True)
            circle = Circle(radius, center)

            nRandomPointsOnPerimeter = 0
            #all random points must be inside the circle or on its perimeter
            for point in randomPoints:
                self.assertTrue(circle.ContainsPoint(point))
                if abs(euclideanDist(point, center) -
                       radius) <= Point2D.COMPARISONTOLERANCE:
                    nRandomPointsOnPerimeter += 1
            #at least 2 points must be on the perimeter of the circle
            self.assertTrue(nRandomPointsOnPerimeter >= 2)
Esempio n. 6
0
def test_radius_property():
    c = Circle(5)
    assert c.radius == 5
    with pytest.raises(ValueError):
        c.radius = 0
    with pytest.raises(ValueError):
        c.radius = -2
 def test_less_than(self):
     for i in range(100):
         c1 = Circle(i)
         c2 = Circle(i + 1)
         self.assertTrue(c1 < c2)
         self.assertFalse(c2 < c1)
         self.assertFalse(c1 < c1)
 def test_ing_add(self):
     i = 0
     while i < 10:
         i = random.randint(0,50)
         j = random.randint(51,100)
         self.assertEqual(Circle(i) + Circle(j), Circle(i+j))
         i += 1
Esempio n. 9
0
def test_reflected():
    c1 = Circle(3)
    c1 = c1 * 3
    assert c1.radius == 3 * 3
    c2 = Circle(4)
    c2 = 4 * c2
    assert c2.radius == 4 * 4
Esempio n. 10
0
 def __init__(self, name, x, y, radius, theta):
     Circle.__init__(self, name, radius, (250, 250, 0), x, y) 
     self.theta = theta
     self.speed = 20.
     self.vX = self.speed * cos(self.theta)
     self.vY = self.speed * sin(self.theta)
     self.theta = theta
def main():
    radius = int(input())
    width = int(input())
    height = int(input())
    color1 = input()
    filled1 = input()
    color2 = input()
    filled2 = input()

    circle = Circle(radius)
    circle.setColor(color1)
    circle.setFilled(filled1)
    print("Circle:")
    print("Radius is", circle.getRadius())
    print("Diameter is", circle.getDiameter())
    print("Area is", circle.getArea())
    print("Perimeter is", circle.getPerimeter())
    print(circle)
    print()
    rectangle = Rectangle(width, height)
    rectangle.setColor(color2)
    rectangle.setFilled(filled2)
    print("Rectangle:")
    print("Width is", rectangle.getWidth())
    print("Height is", rectangle.getHeight())
    print("Area is", rectangle.getArea())
    print("Perimeter is", rectangle.getPerimeter())
    print(rectangle)
 def test_equal(self):
     for i in range(100):
         c1 = Circle(i)
         c2 = Circle(i)
         c3 = Circle(i + 1)
         self.assertEqual(c1, c2)
         self.assertNotEqual(c1, c3)
Esempio n. 13
0
    def test_FitSmallestCircleCustomImpl(self):
        generator = Random2DPointsSetGenerator(nPointsMin=25,
                                               nPointsMax=60,
                                               xmin=-15,
                                               xmax=15,
                                               ymin=-15,
                                               ymax=15,
                                               stub=False)
        for testIter in range(MaxTestIter):
            randomPoints = generator.Generate()
            radius, center = FitCircleTo2DPoints(randomPoints,
                                                 useExternalImpl=False)
            circle = Circle(radius, center)

            radiusExt, centerExt = FitCircleTo2DPoints(randomPoints,
                                                       useExternalImpl=True)

            #all random points must be inside the circle or on its perimeter
            for point in randomPoints:
                self.assertTrue(circle.ContainsPoint(point))

            #radius from custom impl. is often slightly larger than one from external impl.,
            #but sometimes, they are nearly identical
            if not radiusExt <= radius:
                print("\nFor a random set of " + str(len(randomPoints)) +
                      " points :")
                print("radius, center from external impl. " +
                      str(round(radiusExt, 4)) + ", " + str(centerExt))
                print("radius, center from custom impl. " +
                      str(round(radius, 4)) + ", " + str(center))
            self.assertTrue(radiusExt < radius + Point2D.COMPARISONTOLERANCE)
Esempio n. 14
0
    def findType(self, position, radius, typeR):
        correctServices = []
        minRadius = radius
        nearest = 0

        position.mercator()
        region = Circle(position, radius)
        regionRect = Rectangle(Point(position.x - radius, position.y + radius),
                               Point(position.x + radius, position.y - radius))
        if radius < 250:
            servicesInRect = self._find(self.root, regionRect)
            for service in servicesInRect:
                distance = region.isInside(service)
                if service.type == typeR and distance < radius:
                    correctServices.append(service)
                    if distance < minRadius:
                        nearest = service
                        minRadius = distance
        else:
            for r in range(250, radius, 250):
                servicesInRect = self._find(self.root, regionRect)
                for service in servicesInRect:
                    distance = region.isInside(service)
                    if service.type == typeR and distance < r:
                        correctServices.append(service)
                        if distance < minRadius:
                            nearest = service
                            minRadius = distance
                if len(correctServices) > 0:
                    break
        return nearest, minRadius
Esempio n. 15
0
def main():
    # Use this to test the constructor
    
    c1 = Circle(0, 0, -3)

    # Use these to test the getters
    
    print ("c1 center =", c1.getCenter())
    print ("c1 radius =", c1.getRadius())

    # Use these to test the setters
    
    c1.setCenter(1, 2)
    c1.setRadius(5)
    print ()
    print ("Modified c1 center =", c1.getCenter())
    print ("Modified c1 radius =", c1.getRadius())

    # Use this to test the area method
    
    print ("c1 area =", c1.area())

    # Use this to test the __str__
    
    print ()
    print ("Modified Circle c1:")
    print (c1)
 def test_addition(self):
     for i in range(100):
         # Addition
         c1 = Circle(i)
         c2 = Circle(i * 2)
         self.assertEqual(c2, c1 + c1)
         c1 += c1 
         self.assertEqual(c2, c1)
Esempio n. 17
0
 def __init__(self):
     self.canvas = Canvas(self)
     self.p1 = Circle(pos=[0, 0.8, 0], radius=0.2, color=[1, 0, 0])
     self.p2 = Circle(pos=[0, -0.8, 0], radius=0.2, color=[0, 0, 1])
     self.ball = Circle(pos=[0, 0, 0], radius=0.1, color=[0, 1, 1])
     # self.canvas = canvas
     self.movePuck = False
     self.deg = 0
Esempio n. 18
0
 def __init__(self):
     (x,y) = random.randint(0, config.SCREEN_X), random.randint(0, config.SCREEN_Y)
     position = Point(x,y)
     rand = random.randint(0,255)
     color = (rand,rand,rand)
     radius = config.STAR_RADIUS
     rotation = 0.0
     Circle.__init__(self, position, radius, rotation, color)
Esempio n. 19
0
 def test_comparisons(self):
     c1 = Circle(2)
     c2 = Circle(3)
     c3 = Circle(2)
     self.assertEqual((c1>c2),False)
     self.assertEqual((c1<c2), True)
     self.assertEqual((c1==c2), False)
     self.assertEqual((c1==c3), True)
Esempio n. 20
0
 def test_rd_setters(self):
     """Tests the ability to set radius and diameter."""
     c = Circle(4)
     c.radius = 3
     self.assertEqual(c.radius, 3)
     self.assertEqual(c.diameter, 6)
     c.diameter = 10
     self.assertEqual(c.radius, 5)
     self.assertEqual(c.diameter, 10)
 def test_multiply(self):
     for i in range(100):
         # Addition
         c1 = Circle(i)
         c2 = Circle(i * 2)
         self.assertEqual(c2, c1 * 2)
         self.assertEqual(c2, 2 * c1)
         c1 *= 2
         self.assertEqual(c2, c1)
Esempio n. 22
0
 def test_strings(self):
     """Tests the printing behavior. Task 6."""
     c1 = Circle(2)
     c1_repr=  c1.__repr__()
     c1_str = c1.__str__()
     correct_str = 'A circle with radius 2.00.'
     correct_repr = 'Circle (2.00)'
     self.assertEqual(c1_repr, correct_repr)
     self.assertEqual(c1_str, correct_str)
Esempio n. 23
0
 def test_ing_imul(self):
     i = 0
     while i < 10:
         i = random.randint(0,50)
         j = random.randint(51,100)
         c1 = Circle(i)
         c1*=j
         self.assertEqual(eval(repr(c1)), Circle(i*j))
         i+=1
Esempio n. 24
0
 def __init__(self):
     (x, y) = random.randint(0, config.SCREEN_X), random.randint(
         0, config.SCREEN_Y)
     position = Point(x, y)
     rand = random.randint(0, 255)
     color = (rand, rand, rand)
     radius = config.STAR_RADIUS
     rotation = 0.0
     Circle.__init__(self, position, radius, rotation, color)
Esempio n. 25
0
def main():
    # Use this to test the constructor

    c1 = Circle(0, 0, 3)

    # Use these to test the getters

    print("c1 center =", c1.getCenter())
    print("c1 radius =", c1.getRadius())
    def test_comp(self):
        c1 = Circle(2)
        c2 = Circle(4)
        c3 = Circle(4)

        self.assertFalse(c1 > c2)
        self.assertTrue(c1 < c2)
        self.assertFalse(c1 == c2)
        self.assertTrue(c2 == c3)
Esempio n. 27
0
 def __init__(self, pos=None):
     Circle.__init__(self, C.HOIK_RADIUS, C.HOIK_COLOR, 2)
     self.velocity = C.HOIK_VELOCITY
     self.dir = Vector(random.randint(-10, 10),random.randint(-10, 10)).normalized() * self.velocity
    
     if pos == None:
         self.pos = Vector(random.randint(0, C.SCREEN_SIZE.x), random.randint(0, C.SCREEN_SIZE.y))
     else:
         self.pos = pos
Esempio n. 28
0
def test_subtract():
    c1 = Circle(10)
    c2 = Circle(8)
    c3 = c1 - c2
    assert c3.radius == 2
    c1 -= 4
    assert c1.radius == 6
    with pytest.raises(ValueError):
        6 - c2
def test_add():
    """
    Testing that adding two Circle classes together yields a
    Circle class with sums of their radius
    """
    c1 = Circle(2)
    c2 = Circle(4)
    print(c1 + c2)
    assert(c1+c2) == 6
Esempio n. 30
0
 def test_ing_iadd(self):
     i = 0
     while i < 10:
         i = random.randint(0,50)
         j = random.randint(51,100)
         c1 = Circle(i)
         c2 = Circle(j)
         c1+=c2
         self.assertEqual(eval(repr(c1)), Circle(i+j))
         i += 1
Esempio n. 31
0
 def test_sorting(self):
     c1 = Circle(1)
     c2 = Circle(2)
     c3 = Circle(3)
     c4 = Circle(4)
     c5 = Circle(5)
     presorted = [c1,c2,c3,c4,c5]
     unsorted = [c3,c5,c1,c2,c4]
     unsorted.sort(reverse=False)
     self.assertEqual(presorted, unsorted)
Esempio n. 32
0
 def test_step_7(self):
     c1 = Circle(2)
     c2 = Circle(4)
     c3 = Circle(4)
     self.assertEqual(c1 + c2, 6)
     self.assertEqual(c2 * 3, 12)
     self.assertEqual(c1 > c2, False)
     self.assertEqual(c1 < c2, True)
     self.assertEqual(c1 == c2, False)
     self.assertEqual(c2 == c3, True)
Esempio n. 33
0
 def main(cls, args):
     width = 2
     length = 3
     rectangle = Rectangle(width, length)
     print "Rectangle width:", width, "and length:", length, "Area:", rectangle.area(
     ), "Perimeter:", rectangle.perimeter()
     radius = 10
     circle = Circle(radius)
     print "Circle radius:", radius, "Area:", circle.area(
     ), "Perimeter:", circle.perimeter()
Esempio n. 34
0
 def __init__(self, displaySurf: pygame.Surface, ballsCount, speed):
     self.displaySurf = displaySurf
     self.ballsCount = ballsCount
     self.speed = speed
     self.targetCircle = Circle(self.displaySurf, color=randint(0, len(Circle.COLORS)-1), pos=(self.displaySurf.get_width() // 2, self.displaySurf.get_height() // 2), radius=30)
     self.pontFelirat = Pont(self.displaySurf, "Elért pont", (300, 10))
     self.ballsList = []
     self.ballsCreate()
     self.pont = 10
     self.startTimeBalls = pygame.time.get_ticks()
Esempio n. 35
0
def main():
    """Start of program for shapes and inheritance"""

    print("\nShapes and inheritance practice in Python (v3.3.5)")

    circ = Circle(3)
    tri = Triangle(4, 5, 7, 5.7)
    sq = Square(11)

    #To print out pydocs: print(help(circ))
    print("Circle area: " + str(circ.area()))
    print("Square area: " + str(sq.area()))
    print("Triangle area: " + str(tri.area()))
    print("Circle perimeter: " + str(circ.perimeter()))
    print("Square perimeter: " + str(sq.perimeter()))
    print("Triangle perimeter: " + str(tri.perimeter()))
Esempio n. 36
0
    def initWithFrame_(self, frame):
        circleRadius = 100
        colors = [
            ( 0.5, 0.0, 0.5, 1 ),
            ( 1.0, 0.7, 0.0, 1 ),
            ( 0.0, 0.5, 0.0, 1 ),
        ]

        self = super(TLayerView, self).initWithFrame_(frame)
        if self is None:
            return None

        self.useTLayer = False;
        self.circles = []
    
        for c in  colors:
            color = NSColor.colorWithCalibratedRed_green_blue_alpha_(*c)
            circle = Circle.alloc().init()
            circle.color = color
            circle.radius = circleRadius
            circle.center = makeRandomPointInRect(self.bounds())
            self.circles.append(circle)

        self.registerForDraggedTypes_([NSColorPboardType])
        self.setNeedsDisplay_(True)
        return self
Esempio n. 37
0
 def startObservingGraphics_(self, graphics):
     if not graphics: return
     # Register to observe each of the new graphics, and
     # each of their observable properties -- we need old and new
     # values for drawingBounds to figure out what our dirty rect
     for newGraphic in graphics:
         # Register as observer for all the drawing-related properties
         newGraphic.addObserver_forKeyPath_options_context_(
             self, u"drawingBounds", (NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld),
             PropertyObservationContext)
         keys = Circle.keysForNonBoundsProperties()
         for key in keys:
             newGraphic.addObserver_forKeyPath_options_context_(
                 self, key, 0, PropertyObservationContext)
Esempio n. 38
0
def main():
    # Create a circle with radius 1
    circle1 = Circle()
    print("The area of the circle of radius", circle1.radius, "is", circle1.getArea())

    # Create a circle with radius 25
    circle2 = Circle(25)
    print("The area of the circle of radius", circle2.radius, "is", circle2.getArea())

    # Create a circle with radius 125
    circle3 = Circle(125)
    print("The area of the circle of radius", circle3.radius, "is", circle3.getArea())

    # Modify circle radius
    circle2.radius = 100
    print("The area of the circle of radius", circle2.radius, "is", circle2.getArea())
Esempio n. 39
0
def main():
    circle1 = Circle()
    print("The area of the circle of radius",
          circle1.radius, "is", circle1.getArea())

    circle2 = Circle(25)
    print("The area of the circle of radius",
          circle2.radius, "is", circle2.getArea())
    
    circle3 = Circle(125)
    print("The area of the circle of radius",
          circle3.radius, "is", circle3.getArea())

    circle2.radius = 100
    print("The area of the circle of radius",
          circle2.radius, "is", circle2.getArea())
Esempio n. 40
0
import sys
sys.path.append(r'/home/irene/Documents/python/Class')
from Circle import Circle
import time
print(time.strftime('%H:%M:%S',time.localtime(time.time())))
c = Circle(5)
print("Radius:",c.radius)
print("Perimeter:",c.getPerimeter())
print("Area:",c.getArea())
Esempio n. 41
0
 def __init__(self):
     Circle.__init__(self, C.BOID_RADIUS, C.BOID_COLOR, None)
     self.pos = Vector(random.randint(0, C.SCREEN.get_width()), random.randint(0, C.SCREEN.get_height()))
     self.velocity = C.BOID_VELOCITY
     self.dir = Vector(random.randint(-10, 10),random.randint(-10, 10)).normalized() * self.velocity
Esempio n. 42
0
File: Tire.py Progetto: oboff/python
 def perimeter(self):
     return Circle.perimeter(self) * 1.25
Esempio n. 43
0
def test_diameter2():
    c = Circle(4)
    c.radius = 2
    assert c.diameter == 4
Esempio n. 44
0
def test_set_diameter():
    c = Circle(4)
    c.diameter = 2
    assert c.diameter == 2
    assert c.radius == 1
Esempio n. 45
0
 def get_circumcircle(self):
     Circle.get_circumcircle_from_rect(self.bbox)
Esempio n. 46
0
def test_alt_constr():
    c = Circle.from_diameter(8)
    assert c.diameter == 8
    assert c.radius == 4
Esempio n. 47
0
 def __init__(self):
     Circle.__init__(self, C.FOOD_RADIUS, C.FOOD_COLOR, None)
     self.pos = Vector(random.randint(0, C.SCREEN_SIZE.x), random.randint(0, C.SCREEN_SIZE.y))
Esempio n. 48
0
    def do_the_work(self):
        #initialize the cirlces
        c0 = Circle(1, 0,0, self.width/2, self.height/2)
        c1 = Circle(4, self.width/4, self.height/4, self.width/2, self.height/2)
        c2 = Circle(8, self.width/2, self.height/2, self.width/2, self.height/2)

        if len(self.lst) > MAGIC: #yes magic number 13
            self.lst = self.lst[0:MAGIC]
        #puts all the individual items into their 'circle'
        for i in range(0, len(self.lst)):
            self.lst[i]['id'] = i
            if c0.is_full() == False:
                c0.add_entry(self.lst[i])
            elif c1.is_full() == False:
                c1.add_entry(self.lst[i])
            elif c2.is_full() == False:
                c2.add_entry(self.lst[i])

        c0.compute()
        c1.compute()
        c2.compute()

        self.complete = c0.to_list()
        self.complete = self.complete + (c1.to_list())
        self.complete = self.complete + (c2.to_list())
Esempio n. 49
0
 def __init__(self, position, radius, rotation, color): 
     Circle.__init__(self, position, radius, rotation, color)
     self.set_inactive()
Esempio n. 50
0
    #y = _y[8:]

    # find the period
    h0 = h[0]
    period = -1
    for i in range(1,len(x)):
        if (abs(h[i]-h0) < 0.1):
            period = i
    assert period!=-1, "No periodicity found!\n"
    periods = math.floor(len(x) / period)
    print("Period: {0}/{1}".format(period,len(x)))

    i_q = int(period / 3)
    c_points = [ Point(x[i],y[i]) for i in (0,i_q,i_q*2) ]
    print(' '.join(map(str,c_points)))
    circle = Circle.from3(*c_points)
    print("(Est) 3P circle: ({0:.02f},{1:.02f}) {2:.02f}\n".format(
        circle.c.x,circle.c.y,circle.r));

    # calculate r and c
    diameter = np.max(x)-np.min(x)

    center_x = np.mean(x)
    center_y = np.mean(y)
    print("(Est) circle: ({0:.02f},{1:.02f}) {2:.02f}\n".format(
        center_x,center_y,diameter/2));
    #center_y += 26

#    d_circle = plt.Circle([287.24,405.11],114.7,color='r',alpha=.2)
#    d_circle = plt.Circle([circle.c.x,circle.c.y],circle.r,color='r',alpha=.2)
    d_circle = plt.Circle([center_x,center_y],diameter/2,color='r',alpha=.2)
Esempio n. 51
0
def test_change_radius():
    c = Circle(5)
    c.radius = 2
    assert c.diameter == 4
Esempio n. 52
0
#!/usr/bin/env python
from Triangle import Triangle    # include Triangle.py
from Rectangle import Rectangle  # include Rectangle.py
from Circle import Circle        # include Circle.py

# create new objects and initialize data
triangleObject  = Triangle(4, 5)
rectangleObject = Rectangle(4, 5)
cirleObject     = Circle(4)

print('Triangle (base=%d, height=%d) area is: %6.1f'   % (4, 5, triangleObject.get_area()))
print('Rectangle (width=%d, height=%d) area is: %4.1f' % (4, 5, rectangleObject.get_area()))
print('Circle (radius=%d) area is: %16.1f'             % (4, cirleObject.get_area()))
Esempio n. 53
0
 def get_incircle(self):
     # get_rect used as incircle doesnt depend upon theta, same for rot and
     # non-rot rect
     Circle.get_incircle_from_rect(self.get_rect())
Esempio n. 54
0
def test_change_diameter():
    c = Circle(5)
    c.diameter = 12
    assert c.diameter == 12
    assert c.radius == 6
Esempio n. 55
0
 def __init__(self):
     radius = random.randint(C.OBSTACLE_RADIUS_MIN, C.OBSTACLE_RADIUS_MAX)
     Circle.__init__(self, radius, C.OBSTACLE_COLOR, None)
     self.pos = Vector(random.randint(0, C.SCREEN_SIZE.x), random.randint(0, C.SCREEN_SIZE.y))