Content-Length: 6991 | pFad | http://github.com/cp-algorithms/cp-algorithms/pull/1367.patch
thub.com From 24b8444294aa214bb571f3d2f0db731c4ccfd7fc Mon Sep 17 00:00:00 2001 From: Harsh Mathur <104578544+Harsh-Mathur-1503@users.noreply.github.com> Date: Tue, 15 Oct 2024 19:29:16 +0530 Subject: [PATCH] Update halfplane-intersection.md Changes in this commit - 1. Bounding Box Adjustment: In your initial algorithm (previous code), where you define a static bounding box using Point(inf, inf) and Point(-inf, -inf), you need to replace this with a dynamically calculated bounding box based on the actual input points. 2. eps and inf Updates: You should update eps and inf in the previous code to values that suit your input size better, handling small floating-point inaccuracies more gracefully. --- src/geometry/halfplane-intersection.md | 90 +++++++++++++++----------- 1 file changed, 53 insertions(+), 37 deletions(-) diff --git a/src/geometry/halfplane-intersection.md b/src/geometry/halfplane-intersection.md index c0334fd3a..17f90186e 100644 --- a/src/geometry/halfplane-intersection.md +++ b/src/geometry/halfplane-intersection.md @@ -81,17 +81,15 @@ Here is a sample, direct implementation of the algorithm, with comments explaini Simple point/vector and half-plane structs: ```cpp -// Redefine epsilon and infinity as necessary. Be mindful of precision errors. -const long double eps = 1e-9, inf = 1e9; +const long double eps = 1e-8; +const long double inf = 1e6; // Modify as needed based on input scale. // Basic point/vector struct. -struct Point { - +struct Point { long double x, y; explicit Point(long double x = 0, long double y = 0) : x(x), y(y) {} - // Addition, substraction, multiply by constant, dot product, cross product. - + // Addition, subtraction, multiply by constant, dot product, cross product. friend Point operator + (const Point& p, const Point& q) { return Point(p.x + q.x, p.y + q.y); } @@ -102,10 +100,10 @@ struct Point { friend Point operator * (const Point& p, const long double& k) { return Point(p.x * k, p.y * k); - } - + } + friend long double dot(const Point& p, const Point& q) { - return p.x * q.x + p.y * q.y; + return p.x * q.x + p.y * q.y; } friend long double cross(const Point& p, const Point& q) { @@ -114,10 +112,8 @@ struct Point { }; // Basic half-plane struct. -struct Halfplane { - - // 'p' is a passing point of the line and 'pq' is the direction vector of the line. - Point p, pq; +struct Halfplane { + Point p, pq; // 'p' is a passing point of the line, 'pq' is the direction vector of the line. long double angle; Halfplane() {} @@ -131,10 +127,10 @@ struct Halfplane { return cross(pq, r - p) < -eps; } - // Comparator for sorting. + // Comparator for sorting. bool operator < (const Halfplane& e) const { return angle < e.angle; - } + } // Intersection point of the lines of two half-planes. It is assumed they're never parallel. friend Point inter(const Halfplane& s, const Halfplane& t) { @@ -142,12 +138,31 @@ struct Halfplane { return s.p + (s.pq * alpha); } }; + +// Function to calculate a dynamic bounding box based on input points. +Point calculate_bounding_box(const std::vectorFetched URL: http://github.com/cp-algorithms/cp-algorithms/pull/1367.patch
Alternative Proxies: