diff --git a/GeoLib/AnalyticalGeometry.cpp b/GeoLib/AnalyticalGeometry.cpp index 523152f046d9f5775f778c7b74dc8100e043b668..026462a5f816c2f6db687fd30adb4941e1319ac2 100644 --- a/GeoLib/AnalyticalGeometry.cpp +++ b/GeoLib/AnalyticalGeometry.cpp @@ -44,25 +44,15 @@ double getOrientation2d(MathLib::Point3d const& a, namespace GeoLib { -Orientation getOrientation(const double& p0_x, const double& p0_y, const double& p1_x, - const double& p1_y, const double& p2_x, const double& p2_y) -{ - double h1((p1_x - p0_x) * (p2_y - p0_y)); - double h2((p2_x - p0_x) * (p1_y - p0_y)); - - double tol(std::numeric_limits<double>::epsilon()); - if (fabs(h1 - h2) <= tol * std::max(fabs(h1), fabs(h2))) - return COLLINEAR; - if (h1 - h2 > 0.0) - return CCW; - - return CW; -} - Orientation getOrientation(const GeoLib::Point* p0, const GeoLib::Point* p1, const GeoLib::Point* p2) { - return getOrientation((*p0)[0], (*p0)[1], (*p1)[0], (*p1)[1], (*p2)[0], (*p2)[1]); + double const orientation = ExactPredicates::getOrientation2d(*p0, *p1, *p2); + if (orientation > 0) + return CCW; + if (orientation < 0) + return CW; + return COLLINEAR; } bool parallel(MathLib::Vector3 v, MathLib::Vector3 w) @@ -380,8 +370,8 @@ std::vector<MathLib::Point3d> lineSegmentIntersect2d( 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)); + double const orient_abc(getOrientation(a, b, c)); + double const orient_abd(getOrientation(a, b, d)); // check if the segment (cd) lies on the left or on the right of (ab) if ((orient_abc > 0 && orient_abd > 0) || (orient_abc < 0 && orient_abd < 0)) { @@ -497,8 +487,8 @@ std::vector<MathLib::Point3d> lineSegmentIntersect2d( } // check if the segment (ab) lies on the left or on the right of (cd) - double const orient_cda(ExactPredicates::getOrientation2d(c, d, a)); - double const orient_cdb(ExactPredicates::getOrientation2d(c, d, b)); + double const orient_cda(getOrientation(c, d, a)); + double const orient_cdb(getOrientation(c, d, b)); if ((orient_cda > 0 && orient_cdb > 0) || (orient_cda < 0 && orient_cdb < 0)) { return std::vector<MathLib::Point3d>(); } diff --git a/GeoLib/AnalyticalGeometry.h b/GeoLib/AnalyticalGeometry.h index 5000dc35ff4e3abcb5c928ee6513f1eead221124..4363725d604c74a054bc8aae61962a9a493a0b40 100644 --- a/GeoLib/AnalyticalGeometry.h +++ b/GeoLib/AnalyticalGeometry.h @@ -37,20 +37,13 @@ enum Orientation }; /** - * computes the orientation of the three 2D-Points given by their coordinates - * p0_x, p0_y, p1_x, p1_y, p2_x and p2_y - * \returns CW (clockwise), CCW (counterclockwise) or COLLINEAR (points are on a line) + * Computes the orientation of the three 2D-Points. + * \returns CW (clockwise), CCW (counterclockwise) or COLLINEAR (points are on a + * line) */ -Orientation getOrientation (const double& p0_x, const double& p0_y, - const double& p1_x, const double& p1_y, - const double& p2_x, const double& p2_y); - -/** - * wrapper for getOrientation () - */ -Orientation getOrientation (const GeoLib::Point* p0, - const GeoLib::Point* p1, - const GeoLib::Point* p2); +Orientation getOrientation(const GeoLib::Point* p0, + const GeoLib::Point* p1, + const GeoLib::Point* p2); /** * compute a supporting plane (represented by plane_normal and the value d) for the polygon