/* * Copyright ©2020 Hal Perkins. All rights reserved. Permission is * hereby granted to students registered for University of Washington * CSE 333 for use solely during Spring Quarter 2020 for purposes of * the course. No other use, copying, distribution, or modification * is permitted without prior written consent. Copyrights for * third-party components of this work must be honored. Instructors * interested in reusing these course materials should contact the * author. */ #include "./Rectangle.h" Rectangle::Rectangle(const Point &ul, const Point &lr) : ul_(ul.get_x(), ul.get_y()), lr_(lr.get_x(), lr.get_y()) { } Point Rectangle::getul() const { return this->ul_; } Point Rectangle::getlr() const { return this->lr_; } int Rectangle::area() const { int horizontal = this->lr_.get_x() - this->ul_.get_x(); int vertical = this->ul_.get_y() - this->lr_.get_y(); return horizontal * vertical; } bool Rectangle::contains(const Point &p) const { bool x_in = (p.get_x() <= lr_.get_x()) && (p.get_x() >= ul_.get_x()); bool y_in = (p.get_y() <= ul_.get_y()) && (p.get_y() >= lr_.get_y()); return x_in && y_in; }