| [997784] | 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 | 
 | 
|---|
| [c5186e] | 11 | #include <vector>
 | 
|---|
 | 12 | 
 | 
|---|
| [997784] | 13 | #include "Shapes/Shape.hpp"
 | 
|---|
| [6c438f] | 14 | #include "LinearAlgebra/Line.hpp"
 | 
|---|
 | 15 | #include "LinearAlgebra/LineSegment.hpp"
 | 
|---|
 | 16 | #include "LinearAlgebra/LineSegmentSet.hpp"
 | 
|---|
 | 17 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
| [c6f395] | 18 | 
 | 
|---|
| [997784] | 19 | 
 | 
|---|
 | 20 | class Shape_impl {
 | 
|---|
 | 21 | public:
 | 
|---|
| [e09b70] | 22 |   Shape_impl(){};
 | 
|---|
 | 23 |   virtual ~Shape_impl(){};
 | 
|---|
| [997784] | 24 |   virtual bool isInside(const Vector &point)=0;
 | 
|---|
| [5de9da] | 25 |   virtual bool isOnSurface(const Vector &point)=0;
 | 
|---|
 | 26 |   virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException)=0;
 | 
|---|
| [c6f395] | 27 |   virtual LineSegmentSet getLineIntersections(const Line&)=0;
 | 
|---|
| [cfda65] | 28 |   virtual std::string toString()=0;
 | 
|---|
| [9c1c89] | 29 |   virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const=0;
 | 
|---|
| [997784] | 30 | };
 | 
|---|
 | 31 | 
 | 
|---|
 | 32 | class Everywhere_impl : public Shape_impl {
 | 
|---|
 | 33 | public:
 | 
|---|
 | 34 |   virtual bool isInside(const Vector &point){
 | 
|---|
 | 35 |     return true;
 | 
|---|
 | 36 |   }
 | 
|---|
| [5de9da] | 37 |   virtual bool isOnSurface(const Vector &point){
 | 
|---|
 | 38 |     return false;
 | 
|---|
 | 39 |   }
 | 
|---|
 | 40 |   virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException){
 | 
|---|
 | 41 |     throw NotOnSurfaceException(__FILE__,__LINE__);
 | 
|---|
 | 42 |   }
 | 
|---|
| [c6f395] | 43 |   virtual LineSegmentSet getLineIntersections(const Line &line){
 | 
|---|
 | 44 |     LineSegmentSet res(line);
 | 
|---|
 | 45 |     res.insert(LineSegment(line.negEndpoint(),line.posEndpoint()));
 | 
|---|
 | 46 |     return res;
 | 
|---|
 | 47 |   }
 | 
|---|
| [cfda65] | 48 |   virtual std::string toString(){
 | 
|---|
 | 49 |     return "Everywhere()";
 | 
|---|
 | 50 |   }
 | 
|---|
| [9c1c89] | 51 |   virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const {
 | 
|---|
| [c5186e] | 52 |     std::vector<Vector> PointsOnSurface;
 | 
|---|
 | 53 |     return PointsOnSurface;
 | 
|---|
 | 54 |   }
 | 
|---|
| [997784] | 55 | };
 | 
|---|
 | 56 | 
 | 
|---|
 | 57 | class Nowhere_impl : public Shape_impl {
 | 
|---|
 | 58 |   virtual bool isInside(const Vector &point){
 | 
|---|
 | 59 |     return false;
 | 
|---|
 | 60 |   }
 | 
|---|
| [5de9da] | 61 |   virtual bool isOnSurface(const Vector &point){
 | 
|---|
 | 62 |     return false;
 | 
|---|
 | 63 |   }
 | 
|---|
 | 64 |   virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException){
 | 
|---|
 | 65 |     throw NotOnSurfaceException(__FILE__,__LINE__);
 | 
|---|
 | 66 |   }
 | 
|---|
| [c6f395] | 67 |   virtual LineSegmentSet getLineIntersections(const Line &line){
 | 
|---|
 | 68 |     return LineSegmentSet(line);
 | 
|---|
 | 69 |   }
 | 
|---|
| [cfda65] | 70 |   virtual std::string toString(){
 | 
|---|
 | 71 |     return "Nowhere()";
 | 
|---|
 | 72 |   }
 | 
|---|
| [9c1c89] | 73 |   virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const {
 | 
|---|
| [c5186e] | 74 |     std::vector<Vector> PointsOnSurface;
 | 
|---|
 | 75 |     return PointsOnSurface;
 | 
|---|
 | 76 |   }
 | 
|---|
| [997784] | 77 | };
 | 
|---|
 | 78 | 
 | 
|---|
 | 79 | class AndShape_impl : public Shape_impl {
 | 
|---|
 | 80 | public:
 | 
|---|
 | 81 |   AndShape_impl(const Shape::impl_ptr&, const Shape::impl_ptr&);
 | 
|---|
 | 82 |   virtual ~AndShape_impl();
 | 
|---|
 | 83 |   virtual bool isInside(const Vector &point);
 | 
|---|
| [5de9da] | 84 |   virtual bool isOnSurface(const Vector &point);
 | 
|---|
 | 85 |   virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
 | 
|---|
| [c6f395] | 86 |   virtual LineSegmentSet getLineIntersections(const Line&);
 | 
|---|
| [cfda65] | 87 |   virtual std::string toString();
 | 
|---|
| [9c1c89] | 88 |   virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
 | 
|---|
| [997784] | 89 | private:
 | 
|---|
 | 90 |   Shape::impl_ptr lhs;
 | 
|---|
 | 91 |   Shape::impl_ptr rhs;
 | 
|---|
 | 92 | };
 | 
|---|
 | 93 | 
 | 
|---|
 | 94 | class OrShape_impl : public Shape_impl {
 | 
|---|
 | 95 | public:
 | 
|---|
 | 96 |   OrShape_impl(const Shape::impl_ptr&, const Shape::impl_ptr&);
 | 
|---|
 | 97 |   virtual ~OrShape_impl();
 | 
|---|
 | 98 |   virtual bool isInside(const Vector &point);
 | 
|---|
| [5de9da] | 99 |   virtual bool isOnSurface(const Vector &point);
 | 
|---|
 | 100 |   virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
 | 
|---|
| [c6f395] | 101 |   virtual LineSegmentSet getLineIntersections(const Line&);
 | 
|---|
| [cfda65] | 102 |   virtual std::string toString();
 | 
|---|
| [9c1c89] | 103 |   virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
 | 
|---|
| [997784] | 104 | private:
 | 
|---|
 | 105 |   Shape::impl_ptr lhs;
 | 
|---|
 | 106 |   Shape::impl_ptr rhs;
 | 
|---|
 | 107 | };
 | 
|---|
 | 108 | 
 | 
|---|
 | 109 | class NotShape_impl : public Shape_impl {
 | 
|---|
 | 110 | public:
 | 
|---|
 | 111 |   NotShape_impl(const Shape::impl_ptr&);
 | 
|---|
 | 112 |   virtual ~NotShape_impl();
 | 
|---|
 | 113 |   virtual bool isInside(const Vector &point);
 | 
|---|
| [5de9da] | 114 |   virtual bool isOnSurface(const Vector &point);
 | 
|---|
 | 115 |   virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
 | 
|---|
| [c6f395] | 116 |   virtual LineSegmentSet getLineIntersections(const Line&);
 | 
|---|
| [cfda65] | 117 |   virtual std::string toString();
 | 
|---|
| [9c1c89] | 118 |   virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
 | 
|---|
| [997784] | 119 | private:
 | 
|---|
 | 120 |   Shape::impl_ptr arg;
 | 
|---|
 | 121 | };
 | 
|---|
 | 122 | 
 | 
|---|
| [e09b70] | 123 | Shape::impl_ptr getShapeImpl(const Shape&);
 | 
|---|
 | 124 | 
 | 
|---|
| [997784] | 125 | #endif /* SHAPE_IMPL_HPP_ */
 | 
|---|