OGS
LineSegment.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "LineSegment.h"
5
6namespace GeoLib
7{
9 bool point_mem_management_by_line_segment)
10 : _a(a),
11 _b(b),
13 point_mem_management_by_line_segment)
14{
15}
16
18 : _a(new Point(line_segment.getBeginPoint())),
19 _b(new Point(line_segment.getEndPoint())),
21{
22}
23
25 : _a(line_segment._a),
26 _b(line_segment._b),
29{
30 line_segment._a = nullptr;
31 line_segment._b = nullptr;
32 line_segment._point_mem_management_by_line_segment = false;
33}
34
36{
38 {
39 delete _b;
40 delete _a;
41 }
42}
43
45
47{
48 _a = line_segment._a;
49 _b = line_segment._b;
51 line_segment._point_mem_management_by_line_segment;
52
53 line_segment._a = nullptr;
54 line_segment._b = nullptr;
55 line_segment._point_mem_management_by_line_segment = false;
56
57 return *this;
58}
59
61{
62 return *_a;
63}
64
66{
67 return *_a;
68}
69
71{
72 return *_b;
73}
74
76{
77 return *_b;
78}
79
80std::ostream& operator<<(std::ostream& os, LineSegment const& s)
81{
82 os << "{(" << s.getBeginPoint() << "), (" << s.getEndPoint() << ")}";
83 return os;
84}
85
86std::ostream& operator<<(std::ostream& os,
87 std::pair<GeoLib::LineSegment const&,
88 GeoLib::LineSegment const&> const& seg_pair)
89{
90 os << seg_pair.first << " x " << seg_pair.second;
91 return os;
92}
93
94bool operator==(LineSegment const& s0, LineSegment const& s1)
95{
96 double const tol(std::numeric_limits<double>::epsilon());
97 return (MathLib::sqrDist(s0.getBeginPoint(), s1.getBeginPoint()) < tol &&
98 MathLib::sqrDist(s0.getEndPoint(), s1.getEndPoint()) < tol) ||
99 (MathLib::sqrDist(s0.getBeginPoint(), s1.getEndPoint()) < tol &&
100 MathLib::sqrDist(s0.getEndPoint(), s1.getBeginPoint()) < tol);
101}
102} // namespace GeoLib
bool _point_mem_management_by_line_segment
Definition LineSegment.h:39
GeoLib::Point const & getBeginPoint() const
GeoLib::Point * _b
Definition LineSegment.h:38
LineSegment & operator=(LineSegment const &rhs)
GeoLib::Point const & getEndPoint() const
LineSegment(GeoLib::Point *const a, GeoLib::Point *const b, bool point_mem_management_by_line_segment=false)
GeoLib::Point * _a
Definition LineSegment.h:37
bool operator==(LineSegment const &s0, LineSegment const &s1)
std::ostream & operator<<(std::ostream &os, LineSegment const &s)
double sqrDist(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
Definition Point3d.cpp:19