# p1review_fns_for_objects.py
"""Example functions for instances of class Rect.  In Prelim 1 practice/review
session we implemented function move.  Two extra functions are shown below."""

from p1review_class import Rect

def move(r,xc,yc):
    """Set the attributes of Rect `r` such that its center lies on the x- and y-
    coordinates `xc` and `yc`, respectively.
    Precondition:  r is a Rect object.
    Precondition:  xc, yc are each a float."""
    r.x = xc - r.width/2
    r.y = yc - r.height/2

def attributes_as_str(r):
    """Returns: the attributes of Rect `r` in a string
    Precondition:  r is a Rect object"""
    s = 'Lower left corner at ('+str(r.x)+','+str(r.y)+'), '
    s += 'width '+str(r.width)+', height '+str(r.height)
    return s

def whichQuadrant(r):
    """Returns: the quadrant (1, 2, 3, or 4) on which the center of Rect `r`
    lies.  Top left quadrant is 1; the remaining quadrants are labelled
    counter-clockwise.
    Precondition:  r is a Rect object.
    Precondition:  center of Rect r is NOT on the x-axis or y-axis """
    xc= r.x + r.width/2
    yc= r.y + r.height/2
    if xc>0:
        if yc>0:
            return 1
        else:
            return 4
    else:
        if yc>0:
            return 2
        else:
            return 3


print('Instantiate a Rect object and move it so that its center is at (20,50)')
r= Rect(0,0,8,6) #Rect with lower left corner at (0,0), width 8, height 6
print('Original: '+attributes_as_str(r))
move(r,20,50)
print('After move: '+attributes_as_str(r))
print()
rList= [Rect(0,0,8,6), Rect(-10,0,8,6), Rect(-10,-10,8,6), Rect(10,-10,8,6)]
for r in rList:
    print('Rectangle with '+attributes_as_str(r))
    print('  Center of this rectangle is in Quadrant '+str(whichQuadrant(r)))
print()
