Okay so I have to make two classes (in two different scripts), both called Block, which store information about the position and size of a rectangular block. Version 1 should have attributes to store the coordinates of the center of the block (either as separate x- and y-coordinates or as a pair* of numbers) and for the width and height of the block. Version 2 should have attributes to store the coordinates of the bottom-left corner (the "SW" corner) and the coordinates of the upper-right corner (the "NE" corner).
So I know how I would set up the constructor for each one separately, but for this assignment both versions should have a constructor that will take either a pair of coordinates for the center along with the width and height (as floating point numbers), or two pairs of coordinates representing any two opposite corners of the block. This is what I tried so far:
class Block:
"""Stores information about the position and size of a rectangular block.
Attributes: x-coordinate (int), y-coordinate (int), width (int), height (int) OR northeast corner (int) and southwest corner (int)"""
def __init__(self, center = '', width = '', height = '', SW = '', NE = ''):
"""A constructor that assigns attributes to the proper variables
Block, tuple, tuple -> None"""
self.center = center
self.width = width
self.height = height
self.SW = SW
self.NE = NE
but I'm pretty sure that doesn't actually work the way I want it to. Basically I need to be able to input either a set of variables as the center, width and height, OR I need to input the two corners. Is there a way to do this?
b = Block(SW=3, width=1)..... works well .... which is the problem?