Title: [BUG]: ConvexHull algorithm crashes with division by zero on vertical lines · Issue #1815 · TheAlgorithms/JavaScript · GitHub
Open Graph Title: [BUG]: ConvexHull algorithm crashes with division by zero on vertical lines · Issue #1815 · TheAlgorithms/JavaScript
X Title: [BUG]: ConvexHull algorithm crashes with division by zero on vertical lines · Issue #1815 · TheAlgorithms/JavaScript
Description: Description The current ConvexHull implementation has a critical bug in the orientation function that causes division by zero when processing points that share the same x-coordinate (vertical lines). Location File: Geometry/ConvexHull.js...
Open Graph Description: Description The current ConvexHull implementation has a critical bug in the orientation function that causes division by zero when processing points that share the same x-coordinate (vertical lines...
X Description: Description The current ConvexHull implementation has a critical bug in the orientation function that causes division by zero when processing points that share the same x-coordinate (vertical lines...
Opengraph URL: https://github.com/TheAlgorithms/JavaScript/issues/1815
X: @github
Domain: togithub.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[BUG]: ConvexHull algorithm crashes with division by zero on vertical lines","articleBody":"### Description\n\nThe current ConvexHull implementation has a critical bug in the `orientation` function that causes division by zero when processing points that share the same x-coordinate (vertical lines).\n\n## Location\nFile: `Geometry/ConvexHull.js`\nFunction: `orientation(a, b, c)`\n\n### Expected Behavior\n\nThe algorithm should handle vertical lines correctly and return the proper convex hull vertices.\n\n### Actual Behavior\n\n### Current Implementation (Buggy):\n```javascript\nfunction orientation(a, b, c) {\n const alpha = (b.y - a.y) / (b.x - a.x) // ❌ Division by zero!\n const beta = (c.y - b.y) / (c.x - b.x) // ❌ Division by zero!\n \n if (alpha \u003e beta) return 1\n else if (beta \u003e alpha) return -1\n return 0\n}\n```\n\n## Problem:\nWhen b.x === a.x or c.x === b.x, the division results in Infinity or NaN, causing incorrect results or crashes.\nSteps to Reproduce\n```javascript\nimport { convexHull } from './Geometry/ConvexHull.js'\n\n// Points with same x-coordinate (vertical line)\nconst points = [\n { x: 2, y: 0 },\n { x: 2, y: 1 }, // Same x as above\n { x: 2, y: 2 }, // Same x as above\n { x: 0, y: 1 },\n { x: 4, y: 1 }\n]\n\nconvexHull(points) // ❌ Returns incorrect result or crashes","author":{"url":"https://github.com/bhautikrathod9","@type":"Person","name":"bhautikrathod9"},"datePublished":"2025-10-02T18:49:17.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/1815/JavaScript/issues/1815"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:202bbb2d-df24-686b-c1da-5b5f7a221de4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DBFA:C18A5:8BB47F:C60F4F:696A519F |
| html-safe-nonce | d82d985d4ec6cc860f1c201c0eed0ba1a60fda4fbaa164a4571c85a56a9b5463 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQkZBOkMxOEE1OjhCQjQ3RjpDNjBGNEY6Njk2QTUxOUYiLCJ2aXNpdG9yX2lkIjoiNTI0NTI0MDYzNjA1MzU0MTI3OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 420ca2bbd81e35c59cc1e4050cb589ef00c9237a50ac35b8a5f4c1c0c7329446 |
| hovercard-subject-tag | issue:3478557649 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/TheAlgorithms/JavaScript/1815/issue_layout |
| twitter:image | https://opengraph.githubassets.com/28f6c210c35581cae7f90d8efdad708e3f29853162252c83dcef381b36c8eca9/TheAlgorithms/JavaScript/issues/1815 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/28f6c210c35581cae7f90d8efdad708e3f29853162252c83dcef381b36c8eca9/TheAlgorithms/JavaScript/issues/1815 |
| og:image:alt | Description The current ConvexHull implementation has a critical bug in the orientation function that causes division by zero when processing points that share the same x-coordinate (vertical lines... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bhautikrathod9 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3f871c8e07f0ae1886fa8dac284166d28b09ad5bada6476fc10b674e489788ef |
| turbo-cache-control | no-preview |
| go-import | github.com/TheAlgorithms/JavaScript git https://github.com/TheAlgorithms/JavaScript.git |
| octolytics-dimension-user_id | 20487725 |
| octolytics-dimension-user_login | TheAlgorithms |
| octolytics-dimension-repository_id | 97086543 |
| octolytics-dimension-repository_nwo | TheAlgorithms/JavaScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 97086543 |
| octolytics-dimension-repository_network_root_nwo | TheAlgorithms/JavaScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 63c426b30d262aba269ef14c40e3c817b384cd61 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width