NFP - No Fit Polygon
A Rust library that computes the No Fit Polygon (Minkowski sum) of two closed counter-clockwise oriented polygons.
Overview
NFP implements the Minkowski sum algorithm for polygon nesting and packing problems. Given two CCW-oriented polygons, it computes the boundary region where one polygon can be placed relative to another without overlapping.
Usage
use ;
// Define two CCW-oriented polygons using the point() shortcut
let poly_a = vec!;
let poly_b = vec!;
// Calculate the No Fit Polygon
match NFPnfp
Requirements
- Both polygons must be closed (first and last points form an edge)
- Both polygons must be oriented counter-clockwise (CCW)
- Both polygons must have at least 3 vertices
API
point(x, y)
Shortcut function to create a new point.
Point
2D point with x, y coordinates.
Methods:
new(x, y)- Create a new pointdistance(other)- Calculate distance to another pointdistance_squared(other)- Calculate squared distanceadd(other)- Vector additionsub(other)- Vector subtraction
NFP
Main calculator for Minkowski sums.
Methods:
nfp(poly_a, poly_b)- Compute NFP of two polygons
polygon module
Utility functions for polygon operations:
len(vertices)- Get vertex countis_empty(vertices)- Check if emptyis_ccw(vertices)- Check counter-clockwise orientationensure_ccw(vertices)- Ensure CCW orientation (mutates)translate(vertices, offset)- Translate polygon by offset