#include "Rectangle.h" Rectangle::Rectangle() { xPosition = 0; yPosition = 0; width = 0; height = 0; } Rectangle::Rectangle(int xPositionArg, int yPositionArg, int heightArg, int widthArg) { xPosition = xPositionArg; yPosition = yPositionArg; width = widthArg; height = heightArg; } Rectangle::~Rectangle() { // nothing to do here in destructor } int Rectangle::getHeight() { return height; } void Rectangle::setHeight(int heightArg) { height = heightArg; } int Rectangle::getWidth() { return width; } void Rectangle::setWidth(int widthArg) { width = widthArg; } int Rectangle::getXPosition() { return xPosition; } void Rectangle::setXPosition(int xPositionArg) { xPosition = xPositionArg; } int Rectangle::getYPosition() { return yPosition; } void Rectangle::setYPosition(int yPositionArg) { yPosition = yPositionArg; } int Rectangle::getArea() { return width * height; } int Rectangle::getPerimeter() { return (2 * width) + (2 * height); } bool Rectangle::overlaps(const Rectangle & r) { if (pointInside(r.xPosition, r.yPosition) == true) return true; else if (pointInside(r.xPosition + r.width, r.yPosition) == true) return true; else if (pointInside(r.xPosition, r.yPosition+r.height) == true) return true; else if (pointInside(r.xPosition + r.width, r.yPosition + r.height) == true) return true; else return false; } bool Rectangle::pointInside(int xArg, int yArg) { if ((xArg >= xPosition) && (xArg <= (xPosition + width)) && (yArg >= yPosition) && (yArg <= (yPosition+height))) return true; else return false; } bool Rectangle::operator!=(const Rectangle & r) { // return (!(*this == r)); return (!(operator==(r))); } bool Rectangle::operator==(const Rectangle & r) { if (this == &r) return true; if ((xPosition == r.xPosition) && (yPosition == r.yPosition) && (width == r.width) && (height = r.height)) { return true; } else { return false; } } Rectangle& Rectangle::operator=(const Rectangle & r) { if (this != &r) { xPosition = r.xPosition; yPosition = r.yPosition; width = r.width; height = r.height; } return *this; } ostream& operator<<(ostream & out, const Rectangle & r) { out << r.xPosition << ", " << r.yPosition << ", " << r.width << ", " << r.height; return out; } Rectangle Rectangle::operator*(double scaleFactor) { Rectangle toReturn(xPosition, yPosition, height*scaleFactor, width*scaleFactor); return toReturn; } Rectangle operator*(double scaleFactor, const Rectangle & r) { Rectangle toReturn(r.xPosition, r.yPosition, r.height*scaleFactor, r.width*scaleFactor); return toReturn; }