Skip to main content

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

Generates an offset path from a sequence of points.
points
&[Vector3]
required
Array of 3D points defining the path to offset. For 2D paths, use the XZ plane (Y=0 or constant).
distance
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.
force_closed
Option<bool>
Explicitly specify whether the path should be treated as closed:
  • Some(true): Force closed path
  • Some(false): Force open path
  • None: Auto-detect (closed if first and last points are nearly identical)
options
OffsetOptions
required
Configuration options controlling corner handling behavior.

Configuration

OffsetOptions

bevel
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.
acute_threshold_degrees
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

points
Vec<Vector3>
The offset path vertices. For closed paths, the last point duplicates the first.
beveled_vertex_indices
Vec<u32>
Indices of vertices in the original path where beveling was applied. Useful for post-processing or visualization.
is_closed
bool
Whether the result is a closed loop.

How It Works

  1. Path Sanitization: Removes consecutive duplicate points and detects if the path is closed
  2. Segment Analysis: Calculates unit direction vectors and left-normal vectors for each segment
  3. 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
  4. 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-9 for 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
Last modified on March 14, 2026