LibreCAD
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lc::Intersect Struct Reference

calculate the intersection pojnts of 2 entities More...

#include <intersect.h>

Public Types

enum  Method { OnEntity = 0, OnPath = 1 }
 

Public Member Functions

 Intersect (Method method, double tolerance)
 
bool operator() (const lc::geo::Vector &, const lc::geo::Vector &)
 
bool operator() (const lc::geo::Vector &, const lc::entity::Point &)
 
bool operator() (const lc::geo::Vector &, const lc::entity::Line &)
 
bool operator() (const lc::geo::Vector &, const lc::geo::Circle &)
 
bool operator() (const lc::geo::Vector &, const lc::entity::Arc &)
 
bool operator() (const lc::geo::Vector &, const lc::entity::Ellipse &)
 
bool operator() (const lc::geo::Vector &, const lc::entity::Spline &)
 
bool operator() (const lc::geo::Vector &, const lc::entity::LWPolyline &)
 
bool operator() (const lc::geo::Vector &, const lc::entity::Image &)
 
bool operator() (const lc::entity::Line &, const lc::geo::Vector &)
 
bool operator() (const lc::entity::Line &, const lc::entity::Point &)
 
bool operator() (const lc::entity::Line &, const lc::entity::Line &)
 
bool operator() (const lc::entity::Line &, const lc::geo::Circle &)
 
bool operator() (const lc::entity::Line &, const lc::entity::Arc &)
 
bool operator() (const lc::entity::Line &, const lc::entity::Ellipse &)
 
bool operator() (const lc::entity::Line &, const lc::entity::Spline &)
 
bool operator() (const lc::entity::Line &, const lc::entity::LWPolyline &)
 
bool operator() (const lc::entity::Line &, const lc::entity::Image &)
 
bool operator() (const lc::entity::Point &, const lc::geo::Vector &)
 
bool operator() (const lc::entity::Point &, const lc::entity::Point &)
 
bool operator() (const lc::entity::Point &, const lc::entity::Line &)
 
bool operator() (const lc::entity::Point &, const lc::geo::Circle &)
 
bool operator() (const lc::entity::Point &, const lc::entity::Arc &)
 
bool operator() (const lc::entity::Point &, const lc::entity::Ellipse &)
 
bool operator() (const lc::entity::Point &, const lc::entity::Spline &)
 
bool operator() (const lc::entity::Point &, const lc::entity::LWPolyline &)
 
bool operator() (const lc::entity::Point &, const lc::entity::Image &)
 
bool operator() (const lc::geo::Circle &, const lc::geo::Vector &)
 
bool operator() (const lc::geo::Circle &, const lc::entity::Point &)
 
bool operator() (const lc::geo::Circle &, const lc::entity::Line &)
 
bool operator() (const lc::geo::Circle &, const lc::geo::Circle &)
 
bool operator() (const lc::geo::Circle &, const lc::entity::Arc &)
 
bool operator() (const lc::geo::Circle &, const lc::entity::Ellipse &)
 
bool operator() (const lc::geo::Circle &, const lc::entity::Spline &)
 
bool operator() (const lc::geo::Circle &, const lc::entity::LWPolyline &)
 
bool operator() (const lc::geo::Circle &, const lc::entity::Image &)
 
bool operator() (const lc::entity::Arc &, const lc::geo::Vector &)
 
bool operator() (const lc::entity::Arc &, const lc::entity::Point &)
 
bool operator() (const lc::entity::Arc &, const lc::entity::Line &)
 
bool operator() (const lc::entity::Arc &, const lc::geo::Circle &)
 
bool operator() (const lc::entity::Arc &, const lc::entity::Arc &)
 
bool operator() (const lc::entity::Arc &, const lc::entity::Ellipse &)
 
bool operator() (const lc::entity::Arc &, const lc::entity::Spline &)
 
bool operator() (const lc::entity::Arc &, const lc::entity::LWPolyline &)
 
bool operator() (const lc::entity::Arc &, const lc::entity::Image &)
 
bool operator() (const lc::entity::Ellipse &, const lc::geo::Vector &)
 
bool operator() (const lc::entity::Ellipse &, const lc::entity::Point &)
 
bool operator() (const lc::entity::Ellipse &, const lc::entity::Line &)
 
bool operator() (const lc::entity::Ellipse &, const lc::geo::Circle &)
 
bool operator() (const lc::entity::Ellipse &, const lc::entity::Arc &)
 
bool operator() (const lc::entity::Ellipse &, const lc::entity::Ellipse &)
 
bool operator() (const lc::entity::Ellipse &, const lc::entity::Spline &)
 
bool operator() (const lc::entity::Ellipse &, const lc::entity::LWPolyline &)
 
bool operator() (const lc::entity::Ellipse &, const lc::entity::Image &)
 
bool operator() (const lc::entity::Spline &, const lc::geo::Vector &)
 
bool operator() (const lc::entity::Spline &, const lc::entity::Point &)
 
bool operator() (const lc::entity::Spline &, const lc::entity::Line &)
 
bool operator() (const lc::entity::Spline &, const lc::geo::Circle &)
 
bool operator() (const lc::entity::Spline &, const lc::entity::Arc &)
 
bool operator() (const lc::entity::Spline &, const lc::entity::Ellipse &)
 
bool operator() (const lc::entity::Spline &, const lc::entity::Spline &)
 
bool operator() (const lc::entity::Spline &, const lc::entity::LWPolyline &)
 
bool operator() (const lc::entity::Spline &, const lc::entity::Image &)
 
bool operator() (const lc::entity::LWPolyline &, const lc::geo::Vector &)
 
bool operator() (const lc::entity::LWPolyline &, const lc::entity::Point &)
 
bool operator() (const lc::entity::LWPolyline &, const lc::entity::Line &)
 
bool operator() (const lc::entity::LWPolyline &, const lc::geo::Circle &)
 
bool operator() (const lc::entity::LWPolyline &, const lc::entity::Arc &)
 
bool operator() (const lc::entity::LWPolyline &, const lc::entity::Ellipse &)
 
bool operator() (const lc::entity::LWPolyline &, const lc::entity::Spline &)
 
bool operator() (const lc::entity::LWPolyline &, const lc::entity::LWPolyline &)
 
bool operator() (const lc::entity::LWPolyline &, const lc::entity::Image &)
 
bool operator() (const lc::entity::Image &, const lc::geo::Vector &)
 
bool operator() (const lc::entity::Image &, const lc::entity::Point &)
 
bool operator() (const lc::entity::Image &, const lc::entity::Line &)
 
bool operator() (const lc::entity::Image &, const lc::geo::Circle &)
 
bool operator() (const lc::entity::Image &, const lc::entity::Arc &)
 
bool operator() (const lc::entity::Image &, const lc::entity::Ellipse &)
 
bool operator() (const lc::entity::Image &, const lc::entity::Spline &)
 
bool operator() (const lc::entity::Image &, const lc::entity::LWPolyline &)
 
bool operator() (const lc::entity::Image &, const lc::entity::Image &)
 
bool operator() (const lc::Visitable &s1, const lc::Visitable &s2)
 
template<typename S >
bool operator() (const S &s1, const S &s2)
 
std::vector< geo::Coordinateresult () const
 

Private Member Functions

void geovisit (const geo::Vector &, const geo::Vector &)
 
void geovisit (const geo::Vector &, const geo::Arc &)
 
void geovisit (const geo::Arc &, const geo::Arc &)
 

Private Attributes

std::vector< geo::Coordinate_intersectionPoints
 
const Method _method
 
const double _tolerance
 

Detailed Description

calculate the intersection pojnts of 2 entities

See also
IntersectMany

Definition at line 35 of file intersect.h.

Member Enumeration Documentation

Enumerator
OnEntity 
OnPath 

Definition at line 37 of file intersect.h.

37  {
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  };

Constructor & Destructor Documentation

Intersect::Intersect ( Method  method,
double  tolerance 
)

Definition at line 17 of file intersect.cpp.

17  : _method(method), _tolerance(tolerance) {
18 }
const double _tolerance
Definition: intersect.h:177
const Method _method
Definition: intersect.h:176

Member Function Documentation

void Intersect::geovisit ( const geo::Vector v1,
const geo::Vector v2 
)
private

Definition at line 523 of file intersect.cpp.

523  {
524  const geo::Coordinate p1 = v1.start();
525  const geo::Coordinate p2 = v1.end();
526  const geo::Coordinate p3 = v2.start();
527  const geo::Coordinate p4 = v2.end();
528 
529  const double num = ((p4.x() - p3.x()) * (p1.y() - p3.y()) - (p4.y() - p3.y()) * (p1.x() - p3.x()));
530  const double div = ((p4.y() - p3.y()) * (p2.x() - p1.x()) - (p4.x() - p3.x()) * (p2.y() - p1.y()));
531 
532  // TODO: We properly should add a tolorance here ??
533  if (std::abs(div) > _tolerance) {
534  double u = num / div;
535  double xs = p1.x() + u * (p2.x() - p1.x());
536  double ys = p1.y() + u * (p2.y() - p1.y());
537  const geo::Coordinate coord(xs, ys);
538 
539  const geo::Area a1(p1, p2);
540  const geo::Area a2(p3, p4);
541 
542  const bool a1b = a1.inArea(coord);
543  const bool a2b = a2.inArea(coord);
544 
545  if (_method == Method::OnPath) {
546  _intersectionPoints.push_back(coord);
547  } else if (a1b && a2b) { // Test if it positivly fit's within a area
548  _intersectionPoints.push_back(coord);
549  } else if (
550  (p1.x() == p2.x() && ys >= a1.minP().y() && ys <= a1.maxP().y() && a2b) ||
551  // when we deal with horizontal or vertical lines, inArea might not
552  (p3.x() == p4.x() && ys >= a2.minP().y() && ys <= a2.maxP().y() && a1b) ||
553  // give a positive result, this conditions will confirm without using tolerance
554  (p1.y() == p2.y() && xs >= a1.minP().x() && xs <= a1.maxP().x() && a2b) ||
555  (p3.y() == p4.y() && xs >= a2.minP().x() && xs <= a2.maxP().x() && a1b)
556  ) {
557  _intersectionPoints.push_back(coord);
558  }
559  }
560 }
std::vector< geo::Coordinate > _intersectionPoints
Definition: intersect.h:175
const Coordinate end() const
Definition: geovector.h:23
double x() const
Returns x of Coordinate.
Definition: geocoordinate.h:26
const double _tolerance
Definition: intersect.h:177
double y() const
Returns y of Coordinate.
Definition: geocoordinate.h:34
const Method _method
Definition: intersect.h:176
const Coordinate start() const
Definition: geovector.h:20
void Intersect::geovisit ( const geo::Vector line,
const geo::Arc arc 
)
private

Definition at line 562 of file intersect.cpp.

562  {
563 
564  auto &&coords = maths::Intersection::LineQuad(line.equation(), arc.equation());
565  if (_method == Method::OnPath) {
566  _intersectionPoints.reserve(_intersectionPoints.size() + coords.size());
567  _intersectionPoints.insert(coords.end(), coords.begin(), coords.end());
568  } else {
569  for (auto &point : coords) {
570  double a = (point - arc.center()).angle();
571  if (arc.isAngleBetween(a) &&
572  line.nearestPointOnEntity(point).distanceTo(point) < LCTOLERANCE) {
573  _intersectionPoints.push_back(point);
574  }
575  }
576  }
577 }
std::vector< geo::Coordinate > _intersectionPoints
Definition: intersect.h:175
const Coordinate nearestPointOnEntity(const Coordinate &coord) const
Definition: geovector.h:49
static std::vector< lc::geo::Coordinate > LineQuad(const Equation &l1, const Equation &q1)
#define LCTOLERANCE
Definition: const.h:6
const maths::Equation equation() const
Definition: geoarc.h:112
const Method _method
Definition: intersect.h:176
double distanceTo(const geo::Coordinate &c) const
bool isAngleBetween(double angle) const
Definition: geoarc.cpp:163
const maths::Equation equation() const
Definition: geovector.h:115
const Coordinate center() const
Returns center of Arc.
Definition: geoarc.cpp:91
void Intersect::geovisit ( const geo::Arc arc1,
const geo::Arc arc2 
)
private

Definition at line 579 of file intersect.cpp.

579  {
580  auto &&coords = maths::Intersection::QuadQuad(arc1.equation(), arc2.equation());
581  if (_method == Method::OnPath) {
582  _intersectionPoints.reserve(_intersectionPoints.size() + coords.size());
583  _intersectionPoints.insert(coords.end(), coords.begin(), coords.end());
584  } else {
585  for (auto &point : coords) {
586  double a1 = (point - arc1.center()).angle();
587  double a2 = (point - arc2.center()).angle();
588  if (Math::isAngleBetween(a1, arc1.startAngle(), arc1.endAngle(), arc1.CCW()) &&
589  Math::isAngleBetween(a2, arc2.startAngle(), arc2.endAngle(), arc2.CCW())) {
590  _intersectionPoints.push_back(point);
591  }
592  }
593  }
594 }
std::vector< geo::Coordinate > _intersectionPoints
Definition: intersect.h:175
bool CCW() const
Returns of the arc is in reversed direction.
Definition: geoarc.cpp:126
double endAngle() const
Returns the EndAngle.
Definition: geoarc.cpp:87
const maths::Equation equation() const
Definition: geoarc.h:112
static bool isAngleBetween(double a, double start, double end, bool CCW)
isAngleBetween, checks if angle is between
Definition: lcmath.cpp:21
const Method _method
Definition: intersect.h:176
static std::vector< geo::Coordinate > QuadQuad(const Equation &l1, const Equation &l2)
double startAngle() const
Returns the startAngle.
Definition: geoarc.cpp:83
const Coordinate center() const
Returns center of Arc.
Definition: geoarc.cpp:91
bool Intersect::operator() ( const lc::geo::Vector v1,
const lc::geo::Vector v2 
)

Definition at line 25 of file intersect.cpp.

25  {
26  geovisit(v1, v2);
27  return false;
28 }
void geovisit(const geo::Vector &, const geo::Vector &)
Definition: intersect.cpp:523
bool Intersect::operator() ( const lc::geo::Vector ,
const lc::entity::Point  
)

Definition at line 30 of file intersect.cpp.

30  {
31  std::cerr << __PRETTY_FUNCTION__ << " requires implementation" << std::endl;
32  return false;
33 }
bool Intersect::operator() ( const lc::geo::Vector v,
const lc::entity::Line l 
)

Definition at line 35 of file intersect.cpp.

35  {
36  geovisit(v, lc::geo::Vector(l.start(), l.end()));
37  return false;
38 }
const Coordinate end() const
Definition: geovector.h:23
void geovisit(const geo::Vector &, const geo::Vector &)
Definition: intersect.cpp:523
const Coordinate start() const
Definition: geovector.h:20
bool Intersect::operator() ( const lc::geo::Vector v,
const lc::geo::Circle circle 
)

Definition at line 40 of file intersect.cpp.

40  {
41  geovisit(v, lc::geo::Arc(circle.center(), circle.radius(), -M_PI, M_PI));
42  return false;
43 }
void geovisit(const geo::Vector &, const geo::Vector &)
Definition: intersect.cpp:523
double radius() const
returns the radius of the circle.
Definition: geocircle.cpp:17
#define M_PI
Definition: const.h:16
const Coordinate center() const
Returns the Center of circle.
Definition: geocircle.cpp:14
bool Intersect::operator() ( const lc::geo::Vector line,
const lc::entity::Arc arc 
)

Definition at line 45 of file intersect.cpp.

45  {
46  geovisit(line, arc);
47  return false;
48 }
void geovisit(const geo::Vector &, const geo::Vector &)
Definition: intersect.cpp:523
bool Intersect::operator() ( const lc::geo::Vector v,
const lc::entity::Ellipse e 
)

Definition at line 50 of file intersect.cpp.

50  {
51  // TODO Check if point's are on path
52 
53  // TODO Check if the coords we get back are good
54  return false;
55  auto &&coords = maths::Intersection::LineQuad(v.equation(), e.equation());
56  if (coords.size()>0) {
57  std::cerr << __PRETTY_FUNCTION__ << " TODO Check if point's are on path" << std::endl;
58  }
59  for (auto &i : coords) {
60  _intersectionPoints.push_back(i);
61  }
62  return false;
63 }
std::vector< geo::Coordinate > _intersectionPoints
Definition: intersect.h:175
static std::vector< lc::geo::Coordinate > LineQuad(const Equation &l1, const Equation &q1)
const maths::Equation equation() const
Returns the quadratic equation.
Definition: geoellipse.h:153
const maths::Equation equation() const
Definition: geovector.h:115
bool Intersect::operator() ( const lc::geo::Vector v,
const lc::entity::Spline s 
)

Definition at line 65 of file intersect.cpp.

65  {
66  std::cerr << __PRETTY_FUNCTION__ << " requires implementation" << std::endl;
67  return false;
68 }
bool Intersect::operator() ( const lc::geo::Vector v,
const lc::entity::LWPolyline l 
)

Definition at line 70 of file intersect.cpp.

70  {
71  auto list1 = l.asEntities();
72 
73  // Note: The dynamic_pointer_cast won't win a beauty contest, but the plan is to split
74  // the EntityVisitor into a GeoVisitor and EntityVisitor such that a application deciding
75  // to use double dispatch can decide to use a specific implementation.
76  // Once added, we can get rid of the dynamic_pointer_casts and simply
77  // call entity1.visit(entity2);
78  for (auto &entity1 : list1) {
79  if (auto arc = std::dynamic_pointer_cast<const lc::geo::Arc>(entity1)) {
80  geovisit(v, *arc.get());
81  } else {
82  geovisit(v, *std::dynamic_pointer_cast<const lc::geo::Vector>(entity1).get());
83  }
84  }
85  return false;
86 }
void geovisit(const geo::Vector &, const geo::Vector &)
Definition: intersect.cpp:523
std::vector< CADEntity_CSPtr > const asEntities() const
Definition: lwpolyline.cpp:299
bool lc::Intersect::operator() ( const lc::geo::Vector ,
const lc::entity::Image  
)
inline

Definition at line 62 of file intersect.h.

62 {return false;};
bool Intersect::operator() ( const lc::entity::Line l1,
const lc::geo::Vector v 
)

Definition at line 89 of file intersect.cpp.

89  {
90  geovisit(lc::geo::Vector(l1.start(), l1.end()), v);
91  return false;
92 }
const Coordinate end() const
Definition: geovector.h:23
void geovisit(const geo::Vector &, const geo::Vector &)
Definition: intersect.cpp:523
const Coordinate start() const
Definition: geovector.h:20
bool Intersect::operator() ( const lc::entity::Line ,
const lc::entity::Point  
)

Definition at line 94 of file intersect.cpp.

94  {
95  std::cerr << __PRETTY_FUNCTION__ << " requires implementation" << std::endl;
96  return false;
97 }
bool Intersect::operator() ( const lc::entity::Line l1,
const lc::entity::Line l2 
)

Definition at line 99 of file intersect.cpp.

99  {
100  geovisit(lc::geo::Vector(l1.start(), l1.end()), lc::geo::Vector(l2.start(), l2.end()));
101  return false;
102 }
const Coordinate end() const
Definition: geovector.h:23
void geovisit(const geo::Vector &, const geo::Vector &)
Definition: intersect.cpp:523
const Coordinate start() const
Definition: geovector.h:20
bool Intersect::operator() ( const lc::entity::Line l,
const lc::geo::Circle circle 
)

Definition at line 104 of file intersect.cpp.

104  {
105  geovisit(lc::geo::Vector(l.start(), l.end()), lc::geo::Arc(circle.center(), circle.radius(), -M_PI, M_PI));
106  return false;
107 }
const Coordinate end() const
Definition: geovector.h:23
void geovisit(const geo::Vector &, const geo::Vector &)
Definition: intersect.cpp:523
double radius() const
returns the radius of the circle.
Definition: geocircle.cpp:17
#define M_PI
Definition: const.h:16
const Coordinate center() const
Returns the Center of circle.
Definition: geocircle.cpp:14
const Coordinate start() const
Definition: geovector.h:20
bool Intersect::operator() ( const lc::entity::Line l,
const lc::entity::Arc arc 
)

Definition at line 109 of file intersect.cpp.

109  {
110  geovisit(lc::geo::Vector(l.start(), l.end()), arc);
111  return false;
112 }
const Coordinate end() const
Definition: geovector.h:23
void geovisit(const geo::Vector &, const geo::Vector &)
Definition: intersect.cpp:523
const Coordinate start() const
Definition: geovector.h:20
bool Intersect::operator() ( const lc::entity::Line l,
const lc::entity::Ellipse e 
)

Definition at line 114 of file intersect.cpp.

114  {
115  // TODO Check if point's are on path
116  auto &&coords = maths::Intersection::LineQuad(l.equation(), e.equation());
117  if (coords.size()>0) {
118  std::cerr << __PRETTY_FUNCTION__ << " TODO Check if point's are on path" << std::endl;
119  }
120  for (auto &i : coords) {
121  _intersectionPoints.push_back(i);
122  }
123  return false;
124 }
std::vector< geo::Coordinate > _intersectionPoints
Definition: intersect.h:175
static std::vector< lc::geo::Coordinate > LineQuad(const Equation &l1, const Equation &q1)
const maths::Equation equation() const
Returns the quadratic equation.
Definition: geoellipse.h:153
const maths::Equation equation() const
Definition: geovector.h:115
bool Intersect::operator() ( const lc::entity::Line ,
const lc::entity::Spline  
)

Definition at line 126 of file intersect.cpp.

126  {
127  std::cerr << __PRETTY_FUNCTION__ << " requires implementation" << std::endl;
128  return false;
129 }
bool Intersect::operator() ( const lc::entity::Line l,
const lc::entity::LWPolyline p 
)

Definition at line 131 of file intersect.cpp.

131  {
132  auto &&list1 = p.asEntities();
133  // Note: The dynamic_pointer_cast won't win a beauty contest, but the plan is to split
134  // the EntityVisitor into a GeoVisitor and EntityVisitor such that a application deciding
135  // to use double dispatch can decide to use a specific implementation.
136  // Once added, we can get rid of the dynamic_pointer_casts and simply
137  // call entity1.visit(entity2);
138  for (auto &entity1 : list1) {
139  if (auto arc = std::dynamic_pointer_cast<const lc::geo::Arc>(entity1)) {
140  geovisit(l, *arc.get());
141  } else {
142  geovisit(l, *std::dynamic_pointer_cast<const lc::geo::Vector>(entity1).get());
143  }
144  }
145  return false;
146 }
void geovisit(const geo::Vector &, const geo::Vector &)
Definition: intersect.cpp:523
std::vector< CADEntity_CSPtr > const asEntities() const
Definition: lwpolyline.cpp:299
bool lc::Intersect::operator() ( const lc::entity::Line ,
const lc::entity::Image  
)
inline

Definition at line 73 of file intersect.h.

73 {return false;};
bool Intersect::operator() ( const lc::entity::Point ,
const lc::geo::Vector  
)

Definition at line 150 of file intersect.cpp.

150  {
151  std::cerr << __PRETTY_FUNCTION__ << " requires implementation" << std::endl;
152  return false;
153 }
bool Intersect::operator() ( const lc::entity::Point ,
const lc::entity::Point  
)

Definition at line 155 of file intersect.cpp.

155  {
156  std::cerr << __PRETTY_FUNCTION__ << " requires implementation" << std::endl;
157  return false;
158 }
bool Intersect::operator() ( const lc::entity::Point ,
const lc::entity::Line  
)

Definition at line 160 of file intersect.cpp.

160  {
161  std::cerr << __PRETTY_FUNCTION__ << " requires implementation" << std::endl;
162  return false;
163 }
bool Intersect::operator() ( const lc::entity::Point ,
const lc::geo::Circle  
)

Definition at line 165 of file intersect.cpp.

165  {
166  std::cerr << __PRETTY_FUNCTION__ << " requires implementation" << std::endl;
167  return false;
168 }
bool Intersect::operator() ( const lc::entity::Point ,
const lc::entity::Arc  
)

Definition at line 170 of file intersect.cpp.

170  {
171  std::cerr << __PRETTY_FUNCTION__ << " requires implementation" << std::endl;
172  return false;
173 }
bool Intersect::operator() ( const lc::entity::Point ,
const lc::entity::Ellipse  
)

Definition at line 175 of file intersect.cpp.

175  {
176  std::cerr << __PRETTY_FUNCTION__ << " requires implementation" << std::endl;
177  return false;
178 }
bool Intersect::operator() ( const lc::entity::Point ,
const lc::entity::Spline  
)

Definition at line 180 of file intersect.cpp.

180  {
181  std::cerr << __PRETTY_FUNCTION__ << " requires implementation" << std::endl;
182  return false;
183 }
bool Intersect::operator() ( const lc::entity::Point ,
const lc::entity::LWPolyline  
)

Definition at line 185 of file intersect.cpp.

185  {
186  std::cerr << __PRETTY_FUNCTION__ << " requires implementation" << std::endl;
187  return false;
188 }
bool lc::Intersect::operator() ( const lc::entity::Point ,
const lc::entity::Image  
)
inline

Definition at line 84 of file intersect.h.

84 {return false;};
bool Intersect::operator() ( const lc::geo::Circle circle,
const lc::geo::Vector v 
)

Definition at line 191 of file intersect.cpp.

191  {
192  geovisit(v, lc::geo::Arc(circle.center(), circle.radius(), -M_PI, M_PI));
193  return false;
194 }
void geovisit(const geo::Vector &, const geo::Vector &)
Definition: intersect.cpp:523
double radius() const
returns the radius of the circle.
Definition: geocircle.cpp:17
#define M_PI
Definition: const.h:16
const Coordinate center() const
Returns the Center of circle.
Definition: geocircle.cpp:14
bool Intersect::operator() ( const lc::geo::Circle c,
const lc::entity::Point p 
)

Definition at line 196 of file intersect.cpp.

196  {
197  (*this)(p, c);
198  return false;
199 }
bool Intersect::operator() ( const lc::geo::Circle circle,
const lc::entity::Line l 
)

Definition at line 201 of file intersect.cpp.

201  {
202  geovisit(lc::geo::Vector(l.start(), l.end()), lc::geo::Arc(circle.center(), circle.radius(), -M_PI, M_PI));
203  return false;
204 }
const Coordinate end() const
Definition: geovector.h:23
void geovisit(const geo::Vector &, const geo::Vector &)
Definition: intersect.cpp:523
double radius() const
returns the radius of the circle.
Definition: geocircle.cpp:17
#define M_PI
Definition: const.h:16
const Coordinate center() const
Returns the Center of circle.
Definition: geocircle.cpp:14
const Coordinate start() const
Definition: geovector.h:20
bool Intersect::operator() ( const lc::geo::Circle c1,
const lc::geo::Circle c2 
)

Definition at line 206 of file intersect.cpp.

206  {
207  auto &&coords = maths::Intersection::QuadQuad(c1.equation(), c2.equation());
208  for (auto &i : coords) {
209  _intersectionPoints.push_back(i);
210  }
211  return false;
212 }
std::vector< geo::Coordinate > _intersectionPoints
Definition: intersect.h:175
const maths::Equation equation() const
Returns equation of the circle.
Definition: geocircle.h:40
static std::vector< geo::Coordinate > QuadQuad(const Equation &l1, const Equation &l2)
bool Intersect::operator() ( const lc::geo::Circle circle,
const lc::entity::Arc arc 
)

Definition at line 214 of file intersect.cpp.

214  {
215  auto &&coords = maths::Intersection::QuadQuad(circle.equation(), arc.equation());
216  if (_method == Method::OnPath) {
217  _intersectionPoints.reserve(_intersectionPoints.size() + coords.size());
218  _intersectionPoints.insert(coords.end(), coords.begin(), coords.end());
219  } else {
220  for (auto &point : coords) {
221  double a = (point - arc.center()).angle();
222  if (Math::isAngleBetween(a, arc.startAngle(), arc.endAngle(), arc.CCW())) {
223  _intersectionPoints.push_back(point);
224  }
225  }
226  }
227  return false;
228 }
std::vector< geo::Coordinate > _intersectionPoints
Definition: intersect.h:175
bool CCW() const
Returns of the arc is in reversed direction.
Definition: geoarc.cpp:126
double endAngle() const
Returns the EndAngle.
Definition: geoarc.cpp:87
const maths::Equation equation() const
Returns equation of the circle.
Definition: geocircle.h:40
const maths::Equation equation() const
Definition: geoarc.h:112
static bool isAngleBetween(double a, double start, double end, bool CCW)
isAngleBetween, checks if angle is between
Definition: lcmath.cpp:21
const Method _method
Definition: intersect.h:176
static std::vector< geo::Coordinate > QuadQuad(const Equation &l1, const Equation &l2)
double startAngle() const
Returns the startAngle.
Definition: geoarc.cpp:83
const Coordinate center() const
Returns center of Arc.
Definition: geoarc.cpp:91
bool Intersect::operator() ( const lc::geo::Circle c,
const lc::entity::Ellipse e 
)

Definition at line 230 of file intersect.cpp.

230  {
231  // TODO: test if point is on path
232  auto &&coords = maths::Intersection::QuadQuad(c.equation(), e.equation());
233  if (coords.size()>0) {
234  std::cerr << __PRETTY_FUNCTION__ << " TODO Check if point's are on path" << std::endl;
235  }
236  for (auto &i : coords) {
237  _intersectionPoints.push_back(i);
238  }
239  return false;
240 }
std::vector< geo::Coordinate > _intersectionPoints
Definition: intersect.h:175
const maths::Equation equation() const
Returns equation of the circle.
Definition: geocircle.h:40
const maths::Equation equation() const
Returns the quadratic equation.
Definition: geoellipse.h:153
static std::vector< geo::Coordinate > QuadQuad(const Equation &l1, const Equation &l2)
bool Intersect::operator() ( const lc::geo::Circle c,
const lc::entity::Spline s 
)

Definition at line 242 of file intersect.cpp.

242  {
243  std::cerr << __PRETTY_FUNCTION__ << " requires implementation" << std::endl;
244  return false; //visit(c, s);
245 }
bool Intersect::operator() ( const lc::geo::Circle c,
const lc::entity::LWPolyline l 
)

Definition at line 247 of file intersect.cpp.

247  {
248  auto &list1 = l.asEntities();
249  auto a = lc::geo::Arc(c.center(), c.radius(), -M_PI, M_PI);
250  // Note: The dynamic_pointer_cast won't win a beauty contest, but the plan is to split
251  // the EntityVisitor into a GeoVisitor and EntityVisitor such that a application deciding
252  // to use double dispatch can decide to use a specific implementation.
253  // Once added, we can get rid of the dynamic_pointer_casts and simply
254  // call entity1.visit(entity2);
255  for (auto &entity1 : list1) {
256  if (auto arc = std::dynamic_pointer_cast<const lc::geo::Arc>(entity1)) {
257  geovisit(a, *arc.get());
258  } else {
259  geovisit(*std::dynamic_pointer_cast<const lc::geo::Vector>(entity1).get(), a);
260  }
261  }
262  return false;
263 }
void geovisit(const geo::Vector &, const geo::Vector &)
Definition: intersect.cpp:523
double radius() const
returns the radius of the circle.
Definition: geocircle.cpp:17
#define M_PI
Definition: const.h:16
const Coordinate center() const
Returns the Center of circle.
Definition: geocircle.cpp:14
std::vector< CADEntity_CSPtr > const asEntities() const
Definition: lwpolyline.cpp:299
bool lc::Intersect::operator() ( const lc::geo::Circle ,
const lc::entity::Image  
)
inline

Definition at line 95 of file intersect.h.

95 {return false;};
bool Intersect::operator() ( const lc::entity::Arc a,
const lc::geo::Vector v 
)

Definition at line 268 of file intersect.cpp.

268  {
269  geovisit(v, a);
270  return false;
271 
272  /* Please do not delete this for the moment
273  const geo::Coordinate nearest = line.nearestPointOnPath(arc.center());
274  double dist = arc.center().distanceTo(nearest);
275 
276  // special case: arc touches line (tangent):
277  // TODO: We properly should add a tolorance here ??
278  if (fabs(dist - arc.radius()) < _tolerance) {
279  _intersectionPoints.push_back(nearest);
280  return;
281  }
282 
283  const geo::Coordinate d = line.end() - line.start();
284  const double r = arc.radius();
285  const geo:: Coordinate delta = line.start() - arc.center();
286  const double d2 = d.squared();
287 
288  //intersection
289  // solution = p + t d;
290  //| p -c+ t d|^2 = r^2
291  // |d|^2 t^2 + 2 (p-c).d t + |p-c|^2 -r^2 = 0
292  const double a1 = delta.dot(d);
293  const double discriminant = a1 * a1 - d2 * (delta.squared() - r * r);
294 
295  if (discriminant < - _tolerance) {
296  return;
297  } else {
298  const double t = sqrtf(fabs(discriminant));
299  //two intersections
300  const geo::Coordinate c1(line.start() + d * (t - a1) / d2);
301  const geo::Coordinate c2(line.start() - d * (t + a1) / d2);
302 
303  if (_method == Method::OnPath || (_method == Method::OnEntity && arc.isCoordinateOnPath(c1) && line.isCoordinateOnPath(c1))) {
304  _intersectionPoints.push_back(c1);
305  }
306 
307  if (_method == Method::OnPath || (_method == Method::OnEntity && arc.isCoordinateOnPath(c2) && line.isCoordinateOnPath(c2))) {
308  _intersectionPoints.push_back(c2);
309  }
310  } */
311 }
void geovisit(const geo::Vector &, const geo::Vector &)
Definition: intersect.cpp:523
bool Intersect::operator() ( const lc::entity::Arc a,
const lc::entity::Point p 
)

Definition at line 313 of file intersect.cpp.

313  {
314  (*this)(p, a);
315  return false;
316 }
bool Intersect::operator() ( const lc::entity::Arc arc,
const lc::entity::Line line 
)

Definition at line 318 of file intersect.cpp.

318  {
319  geovisit(lc::geo::Vector(line.start(), line.end()), arc);
320  return false;
321 }
const Coordinate end() const
Definition: geovector.h:23
void geovisit(const geo::Vector &, const geo::Vector &)
Definition: intersect.cpp:523
const Coordinate start() const
Definition: geovector.h:20
bool Intersect::operator() ( const lc::entity::Arc arc,
const lc::geo::Circle circle 
)

Definition at line 323 of file intersect.cpp.

323  {
324  (*this)(circle, arc);
325  return false;
326 }
bool Intersect::operator() ( const lc::entity::Arc a1,
const lc::entity::Arc a2 
)

Definition at line 328 of file intersect.cpp.

328  {
329  geovisit(a1, a2);
330  return false;
331 }
void geovisit(const geo::Vector &, const geo::Vector &)
Definition: intersect.cpp:523
bool Intersect::operator() ( const lc::entity::Arc a,
const lc::entity::Ellipse e 
)

Definition at line 333 of file intersect.cpp.

333  {
334  // TODO Check if point's are on path
335  auto &&coords = maths::Intersection::QuadQuad(a.equation(), e.equation());
336  if (coords.size()>0) {
337  std::cerr << __PRETTY_FUNCTION__ << " TODO Check if point's are on path" << std::endl;
338  }
339  for (auto &i : coords) {
340  _intersectionPoints.push_back(i);
341  }
342  return false;
343 }
std::vector< geo::Coordinate > _intersectionPoints
Definition: intersect.h:175
const maths::Equation equation() const
Definition: geoarc.h:112
const maths::Equation equation() const
Returns the quadratic equation.
Definition: geoellipse.h:153
static std::vector< geo::Coordinate > QuadQuad(const Equation &l1, const Equation &l2)
bool Intersect::operator() ( const lc::entity::Arc a,
const lc::entity::Spline s 
)

Definition at line 345 of file intersect.cpp.

345  {
346  std::cerr << __PRETTY_FUNCTION__ << " requires implementation" << std::endl;
347  return false;
348 }
bool Intersect::operator() ( const lc::entity::Arc a1,
const lc::entity::LWPolyline l1 
)

Definition at line 350 of file intersect.cpp.

350  {
351  auto &list1 = l1.asEntities();
352  // Note: The dynamic_pointer_cast won't win a beauty contest, but the plan is to split
353  // the EntityVisitor into a GeoVisitor and EntityVisitor such that a application deciding
354  // to use double dispatch can decide to use a specific implementation.
355  // Once added, we can get rid of the dynamic_pointer_casts and simply
356  // call entity1.visit(entity2);
357  for (auto &entity1 : list1) {
358  if (auto arc = std::dynamic_pointer_cast<const lc::geo::Arc>(entity1)) {
359  geovisit(a1, *arc.get());
360  } else {
361  geovisit(*std::dynamic_pointer_cast<const lc::geo::Vector>(entity1).get(), a1);
362  }
363  }
364  return false; //visit(l1, a1);
365 }
void geovisit(const geo::Vector &, const geo::Vector &)
Definition: intersect.cpp:523
std::vector< CADEntity_CSPtr > const asEntities() const
Definition: lwpolyline.cpp:299
bool lc::Intersect::operator() ( const lc::entity::Arc ,
const lc::entity::Image  
)
inline

Definition at line 106 of file intersect.h.

106 {return false;};
bool Intersect::operator() ( const lc::entity::Ellipse e,
const lc::geo::Vector v 
)

Definition at line 368 of file intersect.cpp.

368  {
369  (*this)(v, e);
370  return false;
371 }
bool Intersect::operator() ( const lc::entity::Ellipse e,
const lc::entity::Point p 
)

Definition at line 373 of file intersect.cpp.

373  {
374  (*this)(p, e);
375  return false;
376 }
bool Intersect::operator() ( const lc::entity::Ellipse e,
const lc::entity::Line l 
)

Definition at line 378 of file intersect.cpp.

378  {
379  (*this)(l, e);
380  return false;
381 }
bool Intersect::operator() ( const lc::entity::Ellipse e,
const lc::geo::Circle c 
)

Definition at line 383 of file intersect.cpp.

383  {
384  (*this)(c, e);
385  return false;
386 }
bool Intersect::operator() ( const lc::entity::Ellipse e,
const lc::entity::Arc a 
)

Definition at line 388 of file intersect.cpp.

388  {
389  (*this)(a, e);
390  return false;
391 }
bool Intersect::operator() ( const lc::entity::Ellipse e1,
const lc::entity::Ellipse e2 
)

Definition at line 393 of file intersect.cpp.

393  {
394  // TODO test if point's are on path for ellipse
395  auto &&coords = maths::Intersection::QuadQuad(e1.equation(), e2.equation());
396  if (coords.size()>0) {
397  std::cerr << __PRETTY_FUNCTION__ << " TODO Check if point's are on path" << std::endl;
398  }
399  for (auto &i : coords) {
400  _intersectionPoints.push_back(i);
401  }
402  return false;
403 }
std::vector< geo::Coordinate > _intersectionPoints
Definition: intersect.h:175
const maths::Equation equation() const
Returns the quadratic equation.
Definition: geoellipse.h:153
static std::vector< geo::Coordinate > QuadQuad(const Equation &l1, const Equation &l2)
bool Intersect::operator() ( const lc::entity::Ellipse ,
const lc::entity::Spline  
)

Definition at line 405 of file intersect.cpp.

405  {
406  std::cerr << __PRETTY_FUNCTION__ << " requires implementation" << std::endl;
407  return false;
408 }
bool Intersect::operator() ( const lc::entity::Ellipse ,
const lc::entity::LWPolyline  
)

Definition at line 410 of file intersect.cpp.

410  {
411  std::cerr << __PRETTY_FUNCTION__ << " requires implementation" << std::endl;
412  return false;
413 }
bool lc::Intersect::operator() ( const lc::entity::Ellipse ,
const lc::entity::Image  
)
inline

Definition at line 117 of file intersect.h.

117 {return false;};
bool Intersect::operator() ( const lc::entity::Spline s,
const lc::geo::Vector v 
)

Definition at line 416 of file intersect.cpp.

416  {
417  (*this)(v, s);
418  return false;
419 }
bool Intersect::operator() ( const lc::entity::Spline s,
const lc::entity::Point p 
)

Definition at line 421 of file intersect.cpp.

421  {
422  (*this)(p, s);
423  return false;
424 }
bool Intersect::operator() ( const lc::entity::Spline s,
const lc::entity::Line l 
)

Definition at line 426 of file intersect.cpp.

426  {
427  (*this)(l, s);
428  return false;
429 }
bool Intersect::operator() ( const lc::entity::Spline s,
const lc::geo::Circle c 
)

Definition at line 431 of file intersect.cpp.

431  {
432  (*this)(c, s);
433  return false;
434 }
bool Intersect::operator() ( const lc::entity::Spline s,
const lc::entity::Arc a 
)

Definition at line 436 of file intersect.cpp.

436  {
437  (*this)(a, s);
438  return false;
439 }
bool Intersect::operator() ( const lc::entity::Spline s,
const lc::entity::Ellipse e 
)

Definition at line 441 of file intersect.cpp.

441  {
442  (*this)(e, s);
443  return false;
444 }
bool Intersect::operator() ( const lc::entity::Spline s1,
const lc::entity::Spline s2 
)

Definition at line 446 of file intersect.cpp.

446  {
447  std::cerr << __PRETTY_FUNCTION__ << " requires implementation" << std::endl;
448  return false;
449 }
bool Intersect::operator() ( const lc::entity::Spline s,
const lc::entity::LWPolyline p 
)

Definition at line 451 of file intersect.cpp.

451  {
452  std::cerr << __PRETTY_FUNCTION__ << " requires implementation" << std::endl;
453  return false;
454 }
bool lc::Intersect::operator() ( const lc::entity::Spline ,
const lc::entity::Image  
)
inline

Definition at line 128 of file intersect.h.

128 {return false;};
bool Intersect::operator() ( const lc::entity::LWPolyline p,
const lc::geo::Vector v 
)

Definition at line 457 of file intersect.cpp.

457  {
458  (*this)(v, p);
459  return false;
460 }
bool Intersect::operator() ( const lc::entity::LWPolyline lwp,
const lc::entity::Point po 
)

Definition at line 462 of file intersect.cpp.

462  {
463  (*this)(po, lwp);
464  return false;
465 }
bool Intersect::operator() ( const lc::entity::LWPolyline p,
const lc::entity::Line l 
)

Definition at line 467 of file intersect.cpp.

467  {
468  (*this)(l, p);
469  return false;
470 }
bool Intersect::operator() ( const lc::entity::LWPolyline l1,
const lc::geo::Circle c1 
)

Definition at line 472 of file intersect.cpp.

472  {
473  (*this)(c1, l1);
474  return false;
475 }
bool Intersect::operator() ( const lc::entity::LWPolyline p,
const lc::entity::Arc a 
)

Definition at line 477 of file intersect.cpp.

477  {
478  (*this)(a, p);
479  return false;
480 }
bool Intersect::operator() ( const lc::entity::LWPolyline p,
const lc::entity::Ellipse e 
)

Definition at line 482 of file intersect.cpp.

482  {
483  (*this)(e, p);
484  return false;
485 }
bool Intersect::operator() ( const lc::entity::LWPolyline p,
const lc::entity::Spline s 
)

Definition at line 487 of file intersect.cpp.

487  {
488  (*this)(s, p);
489  return false;
490 }
bool Intersect::operator() ( const lc::entity::LWPolyline l1,
const lc::entity::LWPolyline l2 
)

Definition at line 492 of file intersect.cpp.

492  {
493  auto &list1 = l1.asEntities();
494  auto &list2 = l2.asEntities();
495 
496  // Note: The dynamic_pointer_cast won't win a beauty contest, but the plan is to split
497  // the EntityVisitor into a GeoVisitor and EntityVisitor such that a application deciding
498  // to use double dispatch can decide to use a specific implementation.
499  // Once added, we can get rid of the dynamic_pointer_casts and simply
500  // call entity1.visit(entity2);
501  for (auto &entity1 : list1) {
502  for (auto &entity2 : list2) {
503  if (auto vector = std::dynamic_pointer_cast<const lc::geo::Vector>(entity1)) {
504  if (auto arc = std::dynamic_pointer_cast<const lc::geo::Arc>(entity2)) {
505  geovisit(*vector.get(), *arc.get());
506  } else {
507  geovisit(*vector.get(), *std::dynamic_pointer_cast<const lc::geo::Vector>(entity2).get());
508  }
509  } else {
510  if (auto arc = std::dynamic_pointer_cast<const lc::geo::Arc>(entity2)) {
511  geovisit(*std::dynamic_pointer_cast<const lc::geo::Arc>(entity1).get(), *arc.get());
512  } else {
513  geovisit(*std::dynamic_pointer_cast<const lc::geo::Vector>(entity2).get(),
514  *std::dynamic_pointer_cast<const lc::geo::Arc>(entity1).get());
515  }
516  }
517  }
518  }
519  return false;
520 }
void geovisit(const geo::Vector &, const geo::Vector &)
Definition: intersect.cpp:523
std::vector< CADEntity_CSPtr > const asEntities() const
Definition: lwpolyline.cpp:299
bool lc::Intersect::operator() ( const lc::entity::LWPolyline ,
const lc::entity::Image  
)
inline

Definition at line 139 of file intersect.h.

139 {return false;};
bool lc::Intersect::operator() ( const lc::entity::Image ,
const lc::geo::Vector  
)
inline

Definition at line 142 of file intersect.h.

142 {return false;};
bool lc::Intersect::operator() ( const lc::entity::Image ,
const lc::entity::Point  
)
inline

Definition at line 143 of file intersect.h.

143 {return false;};
bool lc::Intersect::operator() ( const lc::entity::Image ,
const lc::entity::Line  
)
inline

Definition at line 144 of file intersect.h.

144 {return false;};
bool lc::Intersect::operator() ( const lc::entity::Image ,
const lc::geo::Circle  
)
inline

Definition at line 145 of file intersect.h.

145 {return false;};
bool lc::Intersect::operator() ( const lc::entity::Image ,
const lc::entity::Arc  
)
inline

Definition at line 146 of file intersect.h.

146 {return false;};
bool lc::Intersect::operator() ( const lc::entity::Image ,
const lc::entity::Ellipse  
)
inline

Definition at line 147 of file intersect.h.

147 {return false;};
bool lc::Intersect::operator() ( const lc::entity::Image ,
const lc::entity::Spline  
)
inline

Definition at line 148 of file intersect.h.

148 {return false;};
bool lc::Intersect::operator() ( const lc::entity::Image ,
const lc::entity::LWPolyline  
)
inline

Definition at line 149 of file intersect.h.

149 {return false;};
bool lc::Intersect::operator() ( const lc::entity::Image ,
const lc::entity::Image  
)
inline

Definition at line 150 of file intersect.h.

150 {return false;};
bool lc::Intersect::operator() ( const lc::Visitable s1,
const lc::Visitable s2 
)
inline

Definition at line 152 of file intersect.h.

152  {
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  }
template<typename S >
bool lc::Intersect::operator() ( const S &  s1,
const S &  s2 
)
inline

Definition at line 160 of file intersect.h.

160  {
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  }
std::vector< geo::Coordinate > Intersect::result ( ) const

Definition at line 20 of file intersect.cpp.

20  {
21  return _intersectionPoints;
22 }
std::vector< geo::Coordinate > _intersectionPoints
Definition: intersect.h:175

Member Data Documentation

std::vector<geo::Coordinate> lc::Intersect::_intersectionPoints
private

Definition at line 175 of file intersect.h.

const Method lc::Intersect::_method
private

Definition at line 176 of file intersect.h.

const double lc::Intersect::_tolerance
private

Definition at line 177 of file intersect.h.


The documentation for this struct was generated from the following files: