rectangle

// (C) 2013-2014, Sergei Zaychenko, KNURE, Kharkiv, Ukraine #include "rectangle.hpp" #include "utils.hpp" Rectangle::Rectangle(Point _p1, Point _p2) : p1(_p1), p2(_p2) { if (_p1.m_x>_p2.m_x||_p1.m_y<_p2.m_y) throw "Invalid rectangle coordinates";/* else throw "";*/ } Rectangle::Rectangle(Point p, double _height, double _width) : p1(p), p2(p.m_x + _height, p.m_y - _width) { if ((p.m_x > p2.m_x + _height) || p.m_y < p2.m_y - _width) throw "Invalid rectangle coordinates"; } bool Rectangle::operator == (const Rectangle& _r) const { return p1 == _r.p1 && p2 == _r.p2; } bool Rectangle::operator != (const Rectangle& _r) const { return !(*this == _r); } bool Rectangle::contains(const Point & _p) const { return p1.m_x >= _p.m_x && _p.m_x >= p2.m_x && p1.m_y >= _p.m_y && _p.m_y >= p2.m_y; } bool Rectangle::contains(const Point & _p1, const Point & _p2) const { return contains(_p1) && contains(_p2); } bool Rectangle::intersects(const Rectangle & _r) const { return contains(p1) || contains(getBottomLeft()) || contains(p2) || contains(getTopRight()); } bool Rectangle::covers(const Rectangle & _r) const { return contains(p1) && contains(getBottomLeft()) && contains(p2) && contains(getTopRight()); }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.