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
&[Vector3]
required
Array of 3D points defining the path to offset. For 2D paths, use the XZ plane (Y=0 or constant).
f64
required
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.
Option<bool>
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)
OffsetOptions
required
Configuration options controlling corner handling behavior.
Configuration
OffsetOptions
bool
default:"true"
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.f64
default:"35.0"
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
Vec<Vector3>
The offset path vertices. For closed paths, the last point duplicates the first.
Vec<u32>
Indices of vertices in the original path where beveling was applied. Useful for post-processing or visualization.
bool
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
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
See Also
Sweep
Offset a profile along a path
Extrude
Create 3D geometry from 2D shapes
Live Demo
Offset Demo
Try the Offset operation in the browser

