LibreCAD
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
intersect.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "cad/primitive/arc.h"
4 #include "cad/primitive/circle.h"
10 #include "cad/primitive/ellipse.h"
11 #include "cad/primitive/line.h"
13 #include "cad/primitive/point.h"
14 #include "cad/primitive/spline.h"
15 #include "cad/primitive/text.h"
16 #include "cad/primitive/image.h"
17 
18 #include "cad/base/cadentity.h"
19 #include "cad/geometry/geoarc.h"
20 #include "cad/geometry/geoarea.h"
21 #include "cad/geometry/geobase.h"
22 #include "cad/geometry/geocircle.h"
25 #include "cad/geometry/geospline.h"
26 #include "cad/geometry/geovector.h"
27 #include <vector>
28 
29 namespace lc {
30 
35  struct Intersect {
36  public:
37  enum Method {
38  OnEntity = 0, // Means that the location must be on both entities
39  OnPath = 1 // means that the paths may intersect outside of the real path.
40  // For example two lines in a slight angle might intersect outside of line's Area
41  // When method == Any is selected, the system will return that coordinate, otherwise
42  // the point must be on both
43 
44  // Test = 2 // I am considering to add a 'Test' option, this would allow to set a boolean if
45  // a intersection would have happened. This would potentially speed up line/line intersections
46  // during area selection where usually CAD drawings do contain a lot of lines.
47  // THis would also help during selection of LWPolylines where we can stop testing if
48  // any point would have been found.
49 
50  };
51 
52  Intersect(Method method, double tolerance);
53 
54  bool operator()(const lc::geo::Vector &, const lc::geo::Vector &);
55  bool operator()(const lc::geo::Vector &, const lc::entity::Point &);
56  bool operator()(const lc::geo::Vector &, const lc::entity::Line &);
57  bool operator()(const lc::geo::Vector &, const lc::geo::Circle &);
58  bool operator()(const lc::geo::Vector &, const lc::entity::Arc &);
59  bool operator()(const lc::geo::Vector &, const lc::entity::Ellipse &);
60  bool operator()(const lc::geo::Vector &, const lc::entity::Spline &);
61  bool operator()(const lc::geo::Vector &, const lc::entity::LWPolyline &);
62  bool operator()(const lc::geo::Vector &, const lc::entity::Image &){return false;};
63 
64 
65  bool operator()(const lc::entity::Line &, const lc::geo::Vector &);
66  bool operator()(const lc::entity::Line &, const lc::entity::Point &);
67  bool operator()(const lc::entity::Line &, const lc::entity::Line &);
68  bool operator()(const lc::entity::Line &, const lc::geo::Circle &);
69  bool operator()(const lc::entity::Line &, const lc::entity::Arc &);
70  bool operator()(const lc::entity::Line &, const lc::entity::Ellipse &);
71  bool operator()(const lc::entity::Line &, const lc::entity::Spline &);
72  bool operator()(const lc::entity::Line &, const lc::entity::LWPolyline &);
73  bool operator()(const lc::entity::Line &, const lc::entity::Image &){return false;};
74 
75 
76  bool operator()(const lc::entity::Point &, const lc::geo::Vector &);
77  bool operator()(const lc::entity::Point &, const lc::entity::Point &);
78  bool operator()(const lc::entity::Point &, const lc::entity::Line &);
79  bool operator()(const lc::entity::Point &, const lc::geo::Circle &);
80  bool operator()(const lc::entity::Point &, const lc::entity::Arc &);
81  bool operator()(const lc::entity::Point &, const lc::entity::Ellipse &);
82  bool operator()(const lc::entity::Point &, const lc::entity::Spline &);
84  bool operator()(const lc::entity::Point &, const lc::entity::Image &){return false;};
85 
86 
87  bool operator()(const lc::geo::Circle &, const lc::geo::Vector &);
88  bool operator()(const lc::geo::Circle &, const lc::entity::Point &);
89  bool operator()(const lc::geo::Circle &, const lc::entity::Line &);
90  bool operator()(const lc::geo::Circle &, const lc::geo::Circle &);
91  bool operator()(const lc::geo::Circle &, const lc::entity::Arc &);
92  bool operator()(const lc::geo::Circle &, const lc::entity::Ellipse &);
93  bool operator()(const lc::geo::Circle &, const lc::entity::Spline &);
94  bool operator()(const lc::geo::Circle &, const lc::entity::LWPolyline &);
95  bool operator()(const lc::geo::Circle &, const lc::entity::Image &){return false;};
96 
97 
98  bool operator()(const lc::entity::Arc &, const lc::geo::Vector &);
99  bool operator()(const lc::entity::Arc &, const lc::entity::Point &);
100  bool operator()(const lc::entity::Arc &, const lc::entity::Line &);
101  bool operator()(const lc::entity::Arc &, const lc::geo::Circle &);
102  bool operator()(const lc::entity::Arc &, const lc::entity::Arc &);
103  bool operator()(const lc::entity::Arc &, const lc::entity::Ellipse &);
104  bool operator()(const lc::entity::Arc &, const lc::entity::Spline &);
105  bool operator()(const lc::entity::Arc &, const lc::entity::LWPolyline &);
106  bool operator()(const lc::entity::Arc &, const lc::entity::Image &){return false;};
107 
108 
109  bool operator()(const lc::entity::Ellipse &, const lc::geo::Vector &);
110  bool operator()(const lc::entity::Ellipse &, const lc::entity::Point &);
111  bool operator()(const lc::entity::Ellipse &, const lc::entity::Line &);
112  bool operator()(const lc::entity::Ellipse &, const lc::geo::Circle &);
113  bool operator()(const lc::entity::Ellipse &, const lc::entity::Arc &);
114  bool operator()(const lc::entity::Ellipse &, const lc::entity::Ellipse &);
115  bool operator()(const lc::entity::Ellipse &, const lc::entity::Spline &);
117  bool operator()(const lc::entity::Ellipse &, const lc::entity::Image &){return false;};
118 
119 
120  bool operator()(const lc::entity::Spline &, const lc::geo::Vector &);
121  bool operator()(const lc::entity::Spline &, const lc::entity::Point &);
122  bool operator()(const lc::entity::Spline &, const lc::entity::Line &);
123  bool operator()(const lc::entity::Spline &, const lc::geo::Circle &);
124  bool operator()(const lc::entity::Spline &, const lc::entity::Arc &);
125  bool operator()(const lc::entity::Spline &, const lc::entity::Ellipse &);
126  bool operator()(const lc::entity::Spline &, const lc::entity::Spline &);
128  bool operator()(const lc::entity::Spline &, const lc::entity::Image &){return false;};
129 
130 
131  bool operator()(const lc::entity::LWPolyline &, const lc::geo::Vector &);
132  bool operator()(const lc::entity::LWPolyline &, const lc::entity::Point &);
133  bool operator()(const lc::entity::LWPolyline &, const lc::entity::Line &);
134  bool operator()(const lc::entity::LWPolyline &, const lc::geo::Circle &);
135  bool operator()(const lc::entity::LWPolyline &, const lc::entity::Arc &);
139  bool operator()(const lc::entity::LWPolyline &, const lc::entity::Image &){return false;};
140 
141 
142  bool operator()(const lc::entity::Image &, const lc::geo::Vector &){return false;};
143  bool operator()(const lc::entity::Image &, const lc::entity::Point &){return false;};
144  bool operator()(const lc::entity::Image &, const lc::entity::Line &){return false;};
145  bool operator()(const lc::entity::Image &, const lc::geo::Circle &){return false;};
146  bool operator()(const lc::entity::Image &, const lc::entity::Arc &){return false;};
147  bool operator()(const lc::entity::Image &, const lc::entity::Ellipse &){return false;};
148  bool operator()(const lc::entity::Image &, const lc::entity::Spline &){return false;};
149  bool operator()(const lc::entity::Image &, const lc::entity::LWPolyline &){return false;};
150  bool operator()(const lc::entity::Image &, const lc::entity::Image &){return false;};
151 
152  bool operator()(const lc::Visitable &s1, const lc::Visitable &s2) {
153  // If we end up here we found a un-supported intersection
154  // std::cout<<typeid(s1).name()<<"\t"<< quote(s1) <<" - ";
155  // std::cout<<typeid(s2).name()<<"\t"<< quote(s2) <<"\n";
156  return false;
157  }
158 
159  template<typename S>
160  bool operator()(const S& s1, const S& s2) {
161 // s1.accept(printer);
162  std::cout << " No operator found for this Intersection. \n";
163 // s2.accept(printer);
164  std::cout << std::endl;
165  return true;
166  }
167 
168  std::vector<geo::Coordinate> result() const;
169 
170  private:
171  void geovisit(const geo::Vector &, const geo::Vector &);
172  void geovisit(const geo::Vector &, const geo::Arc &);
173  void geovisit(const geo::Arc &, const geo::Arc &);
174  private:
175  std::vector<geo::Coordinate> _intersectionPoints;
177  const double _tolerance;
178  };
179 
186  public:
187  IntersectMany(std::vector<entity::CADEntity_CSPtr>, Intersect::Method = Intersect::OnEntity, double tolerance = LCTOLERANCE);
188 
189  std::vector<geo::Coordinate> result() const;
190 
191  private:
192  std::vector<entity::CADEntity_CSPtr> _entities;
194  const double _tolerance;
195  };
196 
203  public:
204  IntersectAgainstOthers(std::vector<entity::CADEntity_CSPtr>, std::vector<entity::CADEntity_CSPtr>,
205  Intersect::Method, double tolerance);
206 
207  std::vector<geo::Coordinate> result() const;
208 
209  private:
210  std::vector<entity::CADEntity_CSPtr> _entities;
211  std::vector<entity::CADEntity_CSPtr> _others;
213  const double _tolerance;
214  };
215 
222  public:
223  HasIntersectAgainstOthers(std::vector<entity::CADEntity_CSPtr>, std::vector<entity::CADEntity_CSPtr>,
224  Intersect::Method, double tolerance);
225 
226  bool result() const;
227 
228  private:
229  std::vector<entity::CADEntity_CSPtr> _entities;
230  std::vector<entity::CADEntity_CSPtr> _others;
232  const double _tolerance;
233  };
234 
235 }
calculate intersection points of many entities
Definition: intersect.h:185
calculate intersection points of many entities
Definition: intersect.h:202
std::vector< geo::Coordinate > _intersectionPoints
Definition: intersect.h:175
std::vector< entity::CADEntity_CSPtr > _others
Definition: intersect.h:230
bool operator()(const lc::entity::LWPolyline &, const lc::entity::Image &)
Definition: intersect.h:139
bool operator()(const lc::entity::Image &, const lc::entity::Ellipse &)
Definition: intersect.h:147
IntersectAgainstOthers(std::vector< entity::CADEntity_CSPtr >, std::vector< entity::CADEntity_CSPtr >, Intersect::Method, double tolerance)
Definition: intersect.cpp:623
bool operator()(const lc::entity::Ellipse &, const lc::entity::Image &)
Definition: intersect.h:117
bool operator()(const lc::geo::Circle &, const lc::entity::Image &)
Definition: intersect.h:95
bool operator()(const lc::entity::Spline &, const lc::entity::Image &)
Definition: intersect.h:128
bool operator()(const lc::entity::Line &, const lc::entity::Image &)
Definition: intersect.h:73
bool operator()(const lc::entity::Image &, const lc::entity::Image &)
Definition: intersect.h:150
bool operator()(const lc::entity::Image &, const lc::geo::Vector &)
Definition: intersect.h:142
const double _tolerance
Definition: intersect.h:177
calculate the intersection pojnts of 2 entities
Definition: intersect.h:35
std::vector< entity::CADEntity_CSPtr > _entities
Definition: intersect.h:229
The Spline class.
Definition: spline.h:27
void geovisit(const geo::Vector &, const geo::Vector &)
Definition: intersect.cpp:523
std::vector< entity::CADEntity_CSPtr > _others
Definition: intersect.h:211
bool operator()(const lc::entity::Point &, const lc::entity::Image &)
Definition: intersect.h:84
std::vector< geo::Coordinate > result() const
Definition: intersect.cpp:630
bool operator()(const lc::Visitable &s1, const lc::Visitable &s2)
Definition: intersect.h:152
bool operator()(const lc::entity::Image &, const lc::entity::LWPolyline &)
Definition: intersect.h:149
std::vector< geo::Coordinate > result() const
Definition: intersect.cpp:606
Definition: cadentity.h:12
bool operator()(const S &s1, const S &s2)
Definition: intersect.h:160
calculate intersection points of many entities but beal out asap when a intersection point was found ...
Definition: intersect.h:221
const double _tolerance
Definition: intersect.h:194
const Intersect::Method _method
Definition: intersect.h:212
bool operator()(const lc::entity::Image &, const lc::geo::Circle &)
Definition: intersect.h:145
bool operator()(const lc::entity::Image &, const lc::entity::Arc &)
Definition: intersect.h:146
std::vector< entity::CADEntity_CSPtr > _entities
Definition: intersect.h:210
A ellipse that can be put in a drawing.
Definition: ellipse.h:27
const Intersect::Method _method
Definition: intersect.h:193
bool operator()(const lc::entity::Arc &, const lc::entity::Image &)
Definition: intersect.h:106
#define LCTOLERANCE
Definition: const.h:6
A line that can be put in a drawing.
Definition: line.h:28
const Intersect::Method _method
Definition: intersect.h:231
bool operator()(const lc::geo::Vector &, const lc::geo::Vector &)
Definition: intersect.cpp:25
std::vector< geo::Coordinate > result() const
Definition: intersect.cpp:20
bool operator()(const lc::geo::Vector &, const lc::entity::Image &)
Definition: intersect.h:62
IntersectMany(std::vector< entity::CADEntity_CSPtr >, Intersect::Method=Intersect::OnEntity, double tolerance=LCTOLERANCE)
Definition: intersect.cpp:601
bool operator()(const lc::entity::Image &, const lc::entity::Line &)
Definition: intersect.h:144
bool operator()(const lc::entity::Image &, const lc::entity::Point &)
Definition: intersect.h:143
const Method _method
Definition: intersect.h:176
bool operator()(const lc::entity::Image &, const lc::entity::Spline &)
Definition: intersect.h:148
Intersect(Method method, double tolerance)
Definition: intersect.cpp:17
std::vector< entity::CADEntity_CSPtr > _entities
Definition: intersect.h:192
A Image that can be put in a drawing.
Definition: image.h:23
HasIntersectAgainstOthers(std::vector< entity::CADEntity_CSPtr >, std::vector< entity::CADEntity_CSPtr >, Intersect::Method, double tolerance)