Overview
The offset operation creates a new path parallel to the input path at a specified distance. It intelligently handles corners with mitering or beveling, supports both open and closed paths, and maintains geometric correctness for complex shapes.Function Signature
Array of 3D points defining the path to offset. For 2D paths, use the XZ plane (Y=0 or constant).
Offset distance. Positive values offset to the left (counter-clockwise side), negative values offset to the right. The distance is measured perpendicular to the path direction.
Explicitly specify whether the path should be treated as closed:
Some(true): Force closed pathSome(false): Force open pathNone: Auto-detect (closed if first and last points are nearly identical)
Configuration options controlling corner handling behavior.
Configuration
OffsetOptions
Enable beveling for outer corners when the interior angle is below the threshold. When
true, sharp corners are cut off creating two vertices; when false, attempts to miter all corners.The interior angle threshold (in degrees) below which outer corners will be beveled. Valid range: 1.0 to 179.0 degrees. Lower values bevel more aggressively.
Default Options
Return Type
OffsetResult
The offset path vertices. For closed paths, the last point duplicates the first.
Indices of vertices in the original path where beveling was applied. Useful for post-processing or visualization.
Whether the result is a closed loop.
How It Works
- Path Sanitization: Removes consecutive duplicate points and detects if the path is closed
- Segment Analysis: Calculates unit direction vectors and left-normal vectors for each segment
- Corner Processing:
- Straight segments: Simple perpendicular offset
- Outer corners: Mitered intersection or beveled based on angle threshold
- Inner corners (open paths): Clipped to prevent spikes
- Collinear segments: Merged smoothly
- Path Closing: For closed paths, ensures first and last points match exactly
Code Examples
Basic Line Offset
Closed Rectangle Offset
Beveling Acute Corners
Custom Corner Handling
Visual Examples
Corner Behavior
Outer Corners
- Angle > threshold: Mitered (intersection point calculated)
- Angle ≤ threshold: Beveled (two vertices inserted)
- Parallel segments: Smooth continuation
Inner Corners
- Closed paths: Mitered to intersection point
- Open paths: Clipped with two vertices to prevent long spikes
Implementation Details
Source Location
~/workspace/source/main/opengeometry/src/operations/offset.rs:87
Precision
- Uses
EPSILON = 1.0e-9for geometric comparisons - Works in 2D projection (XZ plane, Y preserved)
- Robust handling of degenerate cases (zero-length segments, duplicate points)
Performance Considerations
- Linear time complexity: O(n) where n is the number of input points
- Minimal memory allocation beyond output storage
- Removes duplicate points during sanitization
Edge Cases
- Zero distance: Returns a copy of the input path
- Insufficient points: Returns empty result
- Collinear points: Handled gracefully with tangent smoothing
- Self-intersecting paths: Not automatically resolved; may produce overlapping geometry