shape_2d.cpp
1 #include "shape_2d.hpp"
2 #include <cmath>
3 
5 
6 Circle::Circle(Vector2D const& center,
7  double radius):
8  center_(center),
9  radius_(radius) {}
10 
11 const Vector2D& Circle::getCenter(void) const
12 {
13  return center_;
14 }
15 
16 double Circle::getRadius(void) const
17 {
18  return radius_;
19 }
20 
21 void Circle::setCenter(Vector2D const & center)
22 {
23  center_ = center;
24 }
25 
26 bool Circle::operator()(Vector2D const& r) const
27 {
28  return ScalarProd(r-center_,r-center_)<pow(radius_,2);
29 }
30 
31 Outside::Outside(Shape2D const& shape):
32  shape_(shape) {}
33 
34 Circle::~Circle(void) {}
35 
36 Circle::Circle(const Circle& origin):
37  center_(origin.getCenter()), radius_(origin.getRadius()) {}
38 
39 bool Outside::operator()(Vector2D const& r) const
40 {
41  return !shape_(r);
42 }
bool operator()(const Vector2D &r) const
Returns true is a point is inside the shape, false otherwise.
Definition: shape_2d.cpp:39
void setCenter(Vector2D const &center)
Sets a new center to the circle.
Definition: shape_2d.cpp:21
Outside(Shape2D const &shape)
Class constructor.
Definition: shape_2d.cpp:31
Two dimensional shapes.
double ScalarProd(Vector3D const &v1, Vector3D const &v2)
Scalar product of two vectors.
Definition: Vector3D.cpp:185
A circle.
Definition: shape_2d.hpp:27
double getRadius(void) const
Returns the radius of the circle.
Definition: shape_2d.cpp:16
bool operator()(const Vector2D &r) const
Returns true is a point is inside the shape, false otherwise.
Definition: shape_2d.cpp:26
virtual ~Shape2D(void)
virtual destructor
Definition: shape_2d.cpp:4
2D Mathematical vector
Definition: geometry.hpp:15
Abstract type for a two dimensional shape.
Definition: shape_2d.hpp:12
Circle(Vector2D const &center, double radius)
Class constructor.
Definition: shape_2d.cpp:6
const Vector2D & getCenter(void) const
Returns the center of the circle.
Definition: shape_2d.cpp:11