OGS
LineSegment.cpp
Go to the documentation of this file.
1 
10 #include "LineSegment.h"
11 
12 namespace GeoLib
13 {
15  bool point_mem_management_by_line_segment)
16  : _a(a),
17  _b(b),
18  _point_mem_management_by_line_segment(
19  point_mem_management_by_line_segment)
20 {
21 }
22 
24  : _a(new Point(line_segment.getBeginPoint())),
25  _b(new Point(line_segment.getEndPoint())),
26  _point_mem_management_by_line_segment(true)
27 {
28 }
29 
31  : _a(line_segment._a),
32  _b(line_segment._b),
33  _point_mem_management_by_line_segment(
34  line_segment._point_mem_management_by_line_segment)
35 {
36  line_segment._a = nullptr;
37  line_segment._b = nullptr;
38  line_segment._point_mem_management_by_line_segment = false;
39 }
40 
42 {
44  {
45  delete _b;
46  delete _a;
47  }
48 }
49 
51 
53 {
54  _a = line_segment._a;
55  _b = line_segment._b;
57  line_segment._point_mem_management_by_line_segment;
58 
59  line_segment._a = nullptr;
60  line_segment._b = nullptr;
61  line_segment._point_mem_management_by_line_segment = false;
62 
63  return *this;
64 }
65 
67 {
68  return *_a;
69 }
70 
72 {
73  return *_a;
74 }
75 
77 {
78  return *_b;
79 }
80 
82 {
83  return *_b;
84 }
85 
86 std::ostream& operator<<(std::ostream& os, LineSegment const& s)
87 {
88  os << "{(" << s.getBeginPoint() << "), (" << s.getEndPoint() << ")}";
89  return os;
90 }
91 
92 std::ostream& operator<<(std::ostream& os,
93  std::pair<GeoLib::LineSegment const&,
94  GeoLib::LineSegment const&> const& seg_pair)
95 {
96  os << seg_pair.first << " x " << seg_pair.second;
97  return os;
98 }
99 
100 bool operator==(LineSegment const& s0, LineSegment const& s1)
101 {
102  double const tol(std::numeric_limits<double>::epsilon());
103  return (MathLib::sqrDist(s0.getBeginPoint(), s1.getBeginPoint()) < tol &&
104  MathLib::sqrDist(s0.getEndPoint(), s1.getEndPoint()) < tol) ||
105  (MathLib::sqrDist(s0.getBeginPoint(), s1.getEndPoint()) < tol &&
106  MathLib::sqrDist(s0.getEndPoint(), s1.getBeginPoint()) < tol);
107 }
108 } // namespace GeoLib
bool _point_mem_management_by_line_segment
Definition: LineSegment.h:45
GeoLib::Point const & getBeginPoint() const
Definition: LineSegment.cpp:66
GeoLib::Point * _b
Definition: LineSegment.h:44
LineSegment & operator=(LineSegment const &rhs)
GeoLib::Point const & getEndPoint() const
Definition: LineSegment.cpp:76
LineSegment(GeoLib::Point *const a, GeoLib::Point *const b, bool point_mem_management_by_line_segment=false)
Definition: LineSegment.cpp:14
GeoLib::Point * _a
Definition: LineSegment.h:43
bool operator==(LineSegment const &s0, LineSegment const &s1)
std::ostream & operator<<(std::ostream &os, LineSegment const &s)
Definition: LineSegment.cpp:86
double sqrDist(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
Definition: Point3d.h:48