A JavaScript library for decomposing 2D concave polygons into convex pieces, with both fast and optimal algorithms.
poly-decomp.js is a JavaScript library that decomposes 2D concave polygons into convex pieces. It solves the problem of handling complex polygon shapes in applications like physics simulations, game development, and computer graphics, where convex polygons are required for efficient algorithms. The library provides both a fast approximate method and an optimal but slower method for decomposition.
Game developers, physics engine creators, and graphics programmers who need to process 2D polygon data for collision detection, rendering, or geometric computations. It's also useful for researchers and students working in computational geometry.
Developers choose poly-decomp.js because it offers a reliable, dual-algorithm approach (fast vs. optimal) for polygon decomposition, is a well-tested port of an established C++ library, and includes essential utilities for polygon validation and cleanup, all in a lightweight JavaScript package.
Decompose 2D polygons into convex pieces.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Provides both quickDecomp for real-time speed and decomp for optimal precision, allowing developers to choose based on their performance vs. accuracy needs, as highlighted in the README's philosophy section.
Includes essential functions like isSimple for self-intersection checks, makeCCW for winding correction, and removeCollinearPoints for cleanup, covering common preprocessing steps outlined in the Key Features.
Direct manual port of a well-established C++ library, ensuring the algorithms are battle-tested and reliable for computational geometry tasks, as stated in the README's introduction.
Minimal API focused solely on polygon decomposition without bloat, making it easy to integrate into existing projects, evidenced by the simple array-based usage examples.
The decomp algorithm is explicitly noted as slow in the README, which can be a bottleneck for applications requiring optimal decomposition in real-time scenarios.
Functions like makeCCW and removeCollinearPoints modify the input polygon array directly, as documented, leading to potential side effects if original data must be preserved.
Only handles 2D polygons, so it's unsuitable for projects involving 3D geometry or more complex spatial computations, a clear restriction from the project description.
The README provides basic usage but lacks in-depth tutorials on edge cases or integration with modern frameworks, which may require developers to explore the source code.