// ========================================================================== // $Id: circle.cpp,v 1.1 2011/10/19 03:24:40 jlang Exp $ // CSI2372 example Code for lecture 7 // ========================================================================== // (C)opyright: // // Jochen Lang // EECS, University of Ottawa // 800 King Edward Ave. // Ottawa, On., K1N 6N5 // Canada. // http://www.eecs.uottawa.ca // // Creator: jlang (Jochen Lang) // Email: jlang@eecs.uottawa.ca // ========================================================================== // $Log: circle.cpp,v $ // Revision 1.1 2011/10/19 03:24:40 jlang // Added code for lecture 7 // // // ========================================================================== #include #include "circle.h" #include "aa_box.h" #include "vector2d.h" using std::cout; using std::endl; Circle::Circle( Point2D _center, double _radius ) : d_center(_center), d_radius(_radius) {} bool Circle::enclose( Point2D _extrema[], int _size ) { AABox tmp; if ( tmp.enclose( _extrema, _size )) { Vector2D upperRight(tmp.getUpperRight()); Vector2D lowerLeft(tmp.getLowerLeft()); d_center = upperRight.subtract(lowerLeft).scale(0.5).add(lowerLeft); d_radius = upperRight.subtract(Vector2D(d_center)).getLength(); return true; } return false; } bool Circle::isInside( const Point2D& _pt ) const { if (Vector2D(_pt).subtract(d_center).getLength()-d_radius <= 0.0 ) return true; else return false; } void Circle::print() const { cout << "Circle at: "; d_center.print(); cout << " with radius " << d_radius; return; }