Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.8k
Open
Labels
bugSomething isn't workingSomething isn't working
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
Function: orientation(a, b, c)
Expected Behavior
The algorithm should handle vertical lines correctly and return the proper convex hull vertices.
Actual Behavior
Current Implementation (Buggy):
functionorientation(a,b,c){constalpha=(b.y-a.y)/(b.x-a.x)// ❌ Division by zero!constbeta=(c.y-b.y)/(c.x-b.x)// ❌ Division by zero!if(alpha>beta)return1elseif(beta>alpha)return-1return0}Problem:
When b.x === a.x or c.x === b.x, the division results in Infinity or NaN, causing incorrect results or crashes.
Steps to Reproduce
import{convexHull}from'./Geometry/ConvexHull.js'// Points with same x-coordinate (vertical line)constpoints=[{x: 2,y: 0},{x: 2,y: 1},// Same x as above{x: 2,y: 2},// Same x as above{x: 0,y: 1},{x: 4,y: 1}]convexHull(points)// ❌ Returns incorrect result or crashesMetadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working