From 55df8f64d2461ac11985e5fb2e31be0ca748d497 Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Fri, 13 May 2016 09:36:18 +0200
Subject: [PATCH] [GL] Use LineSegment in lineSegmentIntersect2d.

---
 GeoLib/AnalyticalGeometry.cpp               | 10 +++++---
 GeoLib/AnalyticalGeometry.h                 | 11 ++++-----
 Tests/GeoLib/TestLineSegmentIntersect2d.cpp | 26 +++++++--------------
 3 files changed, 19 insertions(+), 28 deletions(-)

diff --git a/GeoLib/AnalyticalGeometry.cpp b/GeoLib/AnalyticalGeometry.cpp
index bf1a4f86264..48226fd895f 100644
--- a/GeoLib/AnalyticalGeometry.cpp
+++ b/GeoLib/AnalyticalGeometry.cpp
@@ -568,10 +568,14 @@ GeoLib::Polygon rotatePolygonToXY(GeoLib::Polygon const& polygon_in,
     return GeoLib::Polygon(rot_polyline);
 }
 
-std::vector<MathLib::Point3d>
-lineSegmentIntersect2d(MathLib::Point3d const& a, MathLib::Point3d const& b,
-    MathLib::Point3d const& c, MathLib::Point3d const& d)
+std::vector<MathLib::Point3d> lineSegmentIntersect2d(
+    GeoLib::LineSegment const& ab, GeoLib::LineSegment const& cd)
 {
+    GeoLib::Point const& a{ab.getBeginPoint()};
+    GeoLib::Point const& b{ab.getEndPoint()};
+    GeoLib::Point const& c{cd.getBeginPoint()};
+    GeoLib::Point const& d{cd.getEndPoint()};
+
     double const orient_abc(ExactPredicates::getOrientation2d(a, b, c));
     double const orient_abd(ExactPredicates::getOrientation2d(a, b, d));
 
diff --git a/GeoLib/AnalyticalGeometry.h b/GeoLib/AnalyticalGeometry.h
index a952d7f502c..f7c7c1cf981 100644
--- a/GeoLib/AnalyticalGeometry.h
+++ b/GeoLib/AnalyticalGeometry.h
@@ -306,17 +306,14 @@ bool lineSegmentIntersect(GeoLib::LineSegment const& s0,
 /// A line segment is given by its two end-points. The function checks,
 /// if the two line segments (ab) and (cd) intersects. This method checks the
 /// intersection only in 2d.
-/// @param a first end-point of the first line segment
-/// @param b second end-point of the first line segment
-/// @param c first end-point of the second line segment
-/// @param d second end-point of the second line segment
+/// @param ab first line segment
+/// @param cd second line segment
 /// @return empty vector in case there isn't an intersection point, a vector
 /// containing one point if the line segments intersect in a single point, a
 /// vector containing two points describing the line segment the original line
 /// segments are interfering.
-std::vector<MathLib::Point3d>
-lineSegmentIntersect2d(MathLib::Point3d const& a, MathLib::Point3d const& b,
-    MathLib::Point3d const& c, MathLib::Point3d const& d);
+std::vector<MathLib::Point3d> lineSegmentIntersect2d(
+    GeoLib::LineSegment const& ab, GeoLib::LineSegment const& cd);
 
 /**
  * Calculates the intersection points of a line PQ and a triangle ABC.
diff --git a/Tests/GeoLib/TestLineSegmentIntersect2d.cpp b/Tests/GeoLib/TestLineSegmentIntersect2d.cpp
index 72afae082c7..819ffc4fa09 100644
--- a/Tests/GeoLib/TestLineSegmentIntersect2d.cpp
+++ b/Tests/GeoLib/TestLineSegmentIntersect2d.cpp
@@ -65,9 +65,7 @@ TEST_F(LineSegmentIntersect2dTest, RandomSegmentOrientationIntersecting)
     auto intersect = [](GeoLib::LineSegment const& s0,
                         GeoLib::LineSegment const& s1)
     {
-        auto ipnts = GeoLib::lineSegmentIntersect2d(
-            s0.getBeginPoint(), s0.getEndPoint(), s1.getBeginPoint(),
-            s1.getEndPoint());
+        auto ipnts = GeoLib::lineSegmentIntersect2d(s0, s1);
         if (ipnts.size() == 1)
         {
             MathLib::Point3d const center{std::array<double, 3>{
@@ -92,12 +90,10 @@ TEST_F(LineSegmentIntersect2dTest, RandomSegmentOrientationIntersecting)
 // chords of non-intersecting circles.
 TEST_F(LineSegmentIntersect2dTest, RandomSegmentOrientationNonIntersecting)
 {
-    auto intersect =
-        [](GeoLib::LineSegment const& s0, GeoLib::LineSegment const& s1)
+    auto intersect = [](GeoLib::LineSegment const& s0,
+                        GeoLib::LineSegment const& s1)
     {
-        auto ipnts = GeoLib::lineSegmentIntersect2d(
-            s0.getBeginPoint(), s0.getEndPoint(), s1.getBeginPoint(),
-            s1.getEndPoint());
+        auto ipnts = GeoLib::lineSegmentIntersect2d(s0, s1);
         return ipnts.empty();
     };
 
@@ -116,11 +112,8 @@ TEST_F(LineSegmentIntersect2dTest, ParallelNonIntersectingSegmentOrientation)
         std::pair<GeoLib::LineSegment const&, GeoLib::LineSegment const&> const&
             segment_pair)
     {
-        auto ipnts =
-            GeoLib::lineSegmentIntersect2d(segment_pair.first.getBeginPoint(),
-                                           segment_pair.first.getEndPoint(),
-                                           segment_pair.second.getBeginPoint(),
-                                           segment_pair.second.getEndPoint());
+        auto ipnts = GeoLib::lineSegmentIntersect2d(segment_pair.first,
+                                                    segment_pair.second);
         return ipnts.empty();
     };
 
@@ -138,11 +131,8 @@ TEST_F(LineSegmentIntersect2dTest, ParallelIntersectingSegmentOrientation)
         std::pair<GeoLib::LineSegment const&, GeoLib::LineSegment const&> const&
             segment_pair)
     {
-        auto ipnts =
-            GeoLib::lineSegmentIntersect2d(segment_pair.first.getBeginPoint(),
-                                           segment_pair.first.getEndPoint(),
-                                           segment_pair.second.getBeginPoint(),
-                                           segment_pair.second.getEndPoint());
+        auto ipnts = GeoLib::lineSegmentIntersect2d(segment_pair.first,
+                                                    segment_pair.second);
         return ipnts.size() == 2;
     };
 
-- 
GitLab