Show HN: Various shape regularization algorithms

https://news.ycombinator.com/rss Hits: 8
Summary

shreg - Shape Regularization A Python implementation of various shape regularization algorithms for regularizing line segments and closed contours. Shape regularization is a technique used in computational geometry to clean up noisy or imprecise geometric data by aligning segments to common orientations and adjusting their positions to create cleaner, more regular shapes. Features Segment Regularization : Align line segments to common angles and offsets using quadratic programming optimization : Align line segments to common angles and offsets using quadratic programming optimization Snap Regularization : Connect nearby endpoints to create watertight polygons and meshes : Connect nearby endpoints to create watertight polygons and meshes Metric Regularization : Constrain segment dimensions - equal lengths, length quantization, and equal spacing : Constrain segment dimensions - equal lengths, length quantization, and equal spacing Contour Regularization : Simplify closed polygons by aligning edges to principal directions : Simplify closed polygons by aligning edges to principal directions T-Junction Detection : Snap endpoints onto segment interiors for proper connectivity : Snap endpoints onto segment interiors for proper connectivity Flexible Configuration : Control maximum angle and offset tolerances : Control maximum angle and offset tolerances Visualization : Built-in plotting utilities for before/after comparisons : Built-in plotting utilities for before/after comparisons Pure Python: No dependencies required Installation Using pip pip install shreg Using uv uv pip install shreg From source git clone https://github.com/nickp/shreg.git cd shreg pip install -e . Quick Start Segment Regularization Regularize a set of line segments by aligning their angles and offsets: import numpy as np from shreg import solve_line_segments , seg # Create some segments (each segment is [x1, y1, x2, y2]) segments = [ seg ( 0.0 , 0.0 , 1.0 , 0.02 ), # Nearly horizontal seg ( 0.0 , 1.0...

First seen: 2026-01-09 18:52

Last seen: 2026-01-10 01:53