Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: correct division by zero bug in ConvexHull orientation function fixes: #1815#1817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
bhautikrathod9 wants to merge2 commits intoTheAlgorithms:master
base:master
Choose a base branch
Loading
frombhautikrathod9:fix-convex-hull

Conversation

bhautikrathod9
Copy link

Description

This PR fixes a critical bug in the ConvexHull algorithm and improves the implementation.

Changes Made

  1. Fixed Division by Zero Bug: Replaced slope-based orientation calculation with cross product method
  2. Improved Algorithm: Implemented standard Monotone Chain algorithm
  3. Better Error Handling: ChangedError toRangeError for invalid inputs
  4. Input Protection: Algorithm no longer mutates original input array
  5. Enhanced Documentation: Added comprehensive JSDoc comments
  6. Comprehensive Tests: Added 13 test cases covering:
    • Edge cases (collinear points, duplicates, vertical/horizontal lines)
    • Various geometric configurations
    • Negative and floating-point coordinates
    • Large datasets
    • Input immutability

Bug Details

Before: The orientation function used division which caused crashes:

constalpha=(b.y-a.y)/(b.x-a.x)// Division by zero!

After: Using robust cross product:

constcrossProduct=(b.y-a.y)*(c.x-b.x)-(b.x-a.x)*(c.y-b.y)

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.94%. Comparing base (08d8c6b) to head (6035c65).

Additional details and impacted files
@@            Coverage Diff             @@##           master    #1817      +/-   ##==========================================+ Coverage   85.91%   85.94%   +0.02%==========================================  Files         379      379                Lines       19778    19795      +17       Branches     3015     3018       +3     ==========================================+ Hits        16993    17012      +19+ Misses       2785     2783       -2

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report?Share it here.

🚀 New features to boost your workflow:
  • ❄️Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@raklaptudirmraklaptudirmAwaiting requested review from raklaptudirmraklaptudirm is a code owner

@appgurueuappgurueuAwaiting requested review from appgurueuappgurueu is a code owner

At least 2 approving reviews are required to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@bhautikrathod9@codecov-commenter

[8]ページ先頭

©2009-2025 Movatter.jp