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 <vector>
|
---|
12 |
|
---|
13 | #include "Shapes/Shape.hpp"
|
---|
14 | #include "LinearAlgebra/Line.hpp"
|
---|
15 | #include "LinearAlgebra/LineSegment.hpp"
|
---|
16 | #include "LinearAlgebra/LineSegmentSet.hpp"
|
---|
17 | #include "LinearAlgebra/Vector.hpp"
|
---|
18 |
|
---|
19 |
|
---|
20 | class Shape_impl {
|
---|
21 | public:
|
---|
22 | Shape_impl(){};
|
---|
23 | virtual ~Shape_impl(){};
|
---|
24 | virtual bool isInside(const Vector &point)=0;
|
---|
25 | virtual bool isOnSurface(const Vector &point)=0;
|
---|
26 | virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException)=0;
|
---|
27 | virtual LineSegmentSet getLineIntersections(const Line&)=0;
|
---|
28 | virtual std::string toString()=0;
|
---|
29 | virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const=0;
|
---|
30 | };
|
---|
31 |
|
---|
32 | class Everywhere_impl : public Shape_impl {
|
---|
33 | public:
|
---|
34 | virtual bool isInside(const Vector &point){
|
---|
35 | return true;
|
---|
36 | }
|
---|
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 | }
|
---|
43 | virtual LineSegmentSet getLineIntersections(const Line &line){
|
---|
44 | LineSegmentSet res(line);
|
---|
45 | res.insert(LineSegment(line.negEndpoint(),line.posEndpoint()));
|
---|
46 | return res;
|
---|
47 | }
|
---|
48 | virtual std::string toString(){
|
---|
49 | return "Everywhere()";
|
---|
50 | }
|
---|
51 | virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const {
|
---|
52 | std::vector<Vector> PointsOnSurface;
|
---|
53 | return PointsOnSurface;
|
---|
54 | }
|
---|
55 | };
|
---|
56 |
|
---|
57 | class Nowhere_impl : public Shape_impl {
|
---|
58 | virtual bool isInside(const Vector &point){
|
---|
59 | return false;
|
---|
60 | }
|
---|
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 | }
|
---|
67 | virtual LineSegmentSet getLineIntersections(const Line &line){
|
---|
68 | return LineSegmentSet(line);
|
---|
69 | }
|
---|
70 | virtual std::string toString(){
|
---|
71 | return "Nowhere()";
|
---|
72 | }
|
---|
73 | virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const {
|
---|
74 | std::vector<Vector> PointsOnSurface;
|
---|
75 | return PointsOnSurface;
|
---|
76 | }
|
---|
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);
|
---|
84 | virtual bool isOnSurface(const Vector &point);
|
---|
85 | virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
|
---|
86 | virtual LineSegmentSet getLineIntersections(const Line&);
|
---|
87 | virtual std::string toString();
|
---|
88 | virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
|
---|
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);
|
---|
99 | virtual bool isOnSurface(const Vector &point);
|
---|
100 | virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
|
---|
101 | virtual LineSegmentSet getLineIntersections(const Line&);
|
---|
102 | virtual std::string toString();
|
---|
103 | virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
|
---|
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);
|
---|
114 | virtual bool isOnSurface(const Vector &point);
|
---|
115 | virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
|
---|
116 | virtual LineSegmentSet getLineIntersections(const Line&);
|
---|
117 | virtual std::string toString();
|
---|
118 | virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
|
---|
119 | private:
|
---|
120 | Shape::impl_ptr arg;
|
---|
121 | };
|
---|
122 |
|
---|
123 | Shape::impl_ptr getShapeImpl(const Shape&);
|
---|
124 |
|
---|
125 | #endif /* SHAPE_IMPL_HPP_ */
|
---|