The `line-circle-collision` package provides a focused utility for performing 2D collision tests between a line segment and a circle. It returns a boolean indicating whether an intersection occurred and can optionally store the nearest collision point. The current stable version is 1.1.3, last published in 2014. Given its stability and specific use case, it operates under a maintenance cadence rather than active feature development. This package differentiates itself by offering a simple, low-level geometric test without the overhead of a full physics engine, making it suitable for projects requiring precise collision detection for these specific shapes. It's often used in conjunction with other basic geometric utilities like `point-in-triangle` or `point-circle-collision` for building more complex collision systems.
npm install line-circle-collisionVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use the `collide` function to check for an intersection between a line segment and a circle, including how to retrieve the nearest collision point if a hit occurs.
Always check the boolean return value of `collide` before using the `nearest` array's contents.
Ensure all vector inputs (`a`, `b`, `circle`) are consistently formatted as `[number, number]` arrays.
Use CommonJS `require` syntax (`const collide = require('line-circle-collision');`) or a default ESM import (`import collide from 'line-circle-collision';`) if your environment supports CJS-ESM interop.If in an ESM context, change `const collide = require('line-circle-collision');` to `import collide from 'line-circle-collision';`. For browser use, ensure your build process bundles CommonJS modules.Verify that all vector inputs are consistently `[number, number]` arrays. For example, `[5, 6]` for a point, not `{x: 5, y: 6}` or `[5]`.No dependency data recorded yet.