From 36e2b1626f94d8cca5fd2d338ace8cbbd3be9dd6 Mon Sep 17 00:00:00 2001 From: Haarush2006 Date: Thu, 23 Oct 2025 19:29:09 +0530 Subject: [PATCH 1/2] Changed implementation of slope calculation --- Geometry/ConvexHullGraham.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Geometry/ConvexHullGraham.js b/Geometry/ConvexHullGraham.js index 6cdae1de7b..cb89ed9acf 100644 --- a/Geometry/ConvexHullGraham.js +++ b/Geometry/ConvexHullGraham.js @@ -13,16 +13,10 @@ function compare(a, b) { return 1 } function orientation(a, b, c) { - // Check orientation of Line(a, b) and Line(b, c) - const alpha = (b.y - a.y) / (b.x - a.x) - const beta = (c.y - b.y) / (c.x - b.x) + const crossProduct = (b.y - a.y) * (c.x - b.x) - (b.x - a.x) * (c.y - b.y); - // Clockwise - if (alpha > beta) return 1 - // Anticlockwise - else if (beta > alpha) return -1 - // Colinear - return 0 + if(crossProduct === 0) return 0; + return (crossProduct > 0) ? 1 : -1; } function convexHull(points) { From 914e52552310722a240832b827b3b4b19b5ac841 Mon Sep 17 00:00:00 2001 From: Haarush2006 Date: Thu, 23 Oct 2025 19:47:42 +0530 Subject: [PATCH 2/2] ran prettier --- Geometry/ConvexHullGraham.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Geometry/ConvexHullGraham.js b/Geometry/ConvexHullGraham.js index cb89ed9acf..ea48cb6c2e 100644 --- a/Geometry/ConvexHullGraham.js +++ b/Geometry/ConvexHullGraham.js @@ -13,10 +13,10 @@ function compare(a, b) { return 1 } function orientation(a, b, c) { - const crossProduct = (b.y - a.y) * (c.x - b.x) - (b.x - a.x) * (c.y - b.y); + const crossProduct = (b.y - a.y) * (c.x - b.x) - (b.x - a.x) * (c.y - b.y) - if(crossProduct === 0) return 0; - return (crossProduct > 0) ? 1 : -1; + if (crossProduct === 0) return 0 + return crossProduct > 0 ? 1 : -1 } function convexHull(points) {