| 1 | /*
|
|---|
| 2 | * Shape_impl.hpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: Jun 18, 2010
|
|---|
| 5 | * Author: crueger
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #ifndef SHAPE_IMPL_HPP_
|
|---|
| 9 | #define SHAPE_IMPL_HPP_
|
|---|
| 10 |
|
|---|
| 11 | #include "Shapes/Shape.hpp"
|
|---|
| 12 | #include "vector.hpp"
|
|---|
| 13 |
|
|---|
| 14 | class Shape_impl {
|
|---|
| 15 | public:
|
|---|
| 16 | Shape_impl(){};
|
|---|
| 17 | virtual ~Shape_impl(){};
|
|---|
| 18 | virtual bool isInside(const Vector &point)=0;
|
|---|
| 19 | virtual bool isOnSurface(const Vector &point)=0;
|
|---|
| 20 | virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException)=0;
|
|---|
| 21 | };
|
|---|
| 22 |
|
|---|
| 23 | class Everywhere_impl : public Shape_impl {
|
|---|
| 24 | public:
|
|---|
| 25 | virtual bool isInside(const Vector &point){
|
|---|
| 26 | return true;
|
|---|
| 27 | }
|
|---|
| 28 | virtual bool isOnSurface(const Vector &point){
|
|---|
| 29 | return false;
|
|---|
| 30 | }
|
|---|
| 31 | virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException){
|
|---|
| 32 | throw NotOnSurfaceException(__FILE__,__LINE__);
|
|---|
| 33 | }
|
|---|
| 34 | };
|
|---|
| 35 |
|
|---|
| 36 | class Nowhere_impl : public Shape_impl {
|
|---|
| 37 | virtual bool isInside(const Vector &point){
|
|---|
| 38 | return false;
|
|---|
| 39 | }
|
|---|
| 40 | virtual bool isOnSurface(const Vector &point){
|
|---|
| 41 | return false;
|
|---|
| 42 | }
|
|---|
| 43 | virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException){
|
|---|
| 44 | throw NotOnSurfaceException(__FILE__,__LINE__);
|
|---|
| 45 | }
|
|---|
| 46 | };
|
|---|
| 47 |
|
|---|
| 48 | class AndShape_impl : public Shape_impl {
|
|---|
| 49 | public:
|
|---|
| 50 | AndShape_impl(const Shape::impl_ptr&, const Shape::impl_ptr&);
|
|---|
| 51 | virtual ~AndShape_impl();
|
|---|
| 52 | virtual bool isInside(const Vector &point);
|
|---|
| 53 | virtual bool isOnSurface(const Vector &point);
|
|---|
| 54 | virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
|
|---|
| 55 | private:
|
|---|
| 56 | Shape::impl_ptr lhs;
|
|---|
| 57 | Shape::impl_ptr rhs;
|
|---|
| 58 | };
|
|---|
| 59 |
|
|---|
| 60 | class OrShape_impl : public Shape_impl {
|
|---|
| 61 | public:
|
|---|
| 62 | OrShape_impl(const Shape::impl_ptr&, const Shape::impl_ptr&);
|
|---|
| 63 | virtual ~OrShape_impl();
|
|---|
| 64 | virtual bool isInside(const Vector &point);
|
|---|
| 65 | virtual bool isOnSurface(const Vector &point);
|
|---|
| 66 | virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
|
|---|
| 67 | private:
|
|---|
| 68 | Shape::impl_ptr lhs;
|
|---|
| 69 | Shape::impl_ptr rhs;
|
|---|
| 70 | };
|
|---|
| 71 |
|
|---|
| 72 | class NotShape_impl : public Shape_impl {
|
|---|
| 73 | public:
|
|---|
| 74 | NotShape_impl(const Shape::impl_ptr&);
|
|---|
| 75 | virtual ~NotShape_impl();
|
|---|
| 76 | virtual bool isInside(const Vector &point);
|
|---|
| 77 | virtual bool isOnSurface(const Vector &point);
|
|---|
| 78 | virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
|
|---|
| 79 | private:
|
|---|
| 80 | Shape::impl_ptr arg;
|
|---|
| 81 | };
|
|---|
| 82 |
|
|---|
| 83 | Shape::impl_ptr getShapeImpl(const Shape&);
|
|---|
| 84 |
|
|---|
| 85 | #endif /* SHAPE_IMPL_HPP_ */
|
|---|