Header menu logo Euclid

Offset2D Module

A module containing the core algorithms for offsetting 2D polylines. Normally you would not use this directly; prefer the Polyline2D or Points2D module.

Types

Type Description

UTurn

An Enum for describing what to do at U-turns (180 degree turns). It is not possible to offset U-turns correctly. This Enum describes the options: 1: Fail 2: Add a chamfer with two points. 3: Use the offset point for the threshold angle, by default this is 179 degrees. 4: Just skip the point.

VarDistParallel

An Enum for describing what to do with colinear segments with different offset distances. It is not possible to offset colinear segments if the distances are not the same. This Enum describes the options: 1: Fail 2: just skip the point. 3: add a point at closest distance on the oblique segment, non parallel offsets. 4: add a point perpendicular from here intersecting the oblique segment, non parallel offsets. 5: add a step with two points.

Functions and values

Function or value Description

makeOffsetDirections pts

Full Usage: makeOffsetDirections pts

Parameters:
    pts : ResizeArray<Pt>

Returns: ResizeArray<UnitVc>

Returns the normals of the segments of a polyline; each segment is rotated 90 degrees in counter-clockwise order. The count is one less than the input points. Fails on duplicate points.

pts : ResizeArray<Pt>
Returns: ResizeArray<UnitVc>

offset dist pts

Full Usage: offset dist pts

Parameters:
    dist : float - The distance to offset the Polyline2D. A positive distance will offset inwards on counter-clockwise curves. A negative distance will offset inwards on clockwise curves.
    pts : ResizeArray<Pt> - The points of the Polyline2D to offset.

Returns: ResizeArray<Pt> A new ResizeArray of Points. The point count will be the same as the input.

A constant-distance offset algorithm for closed or open polylines. Fails at corners or U-turns sharper than joints after 177.5° degrees.

dist : float

The distance to offset the Polyline2D. A positive distance will offset inwards on counter-clockwise curves. A negative distance will offset inwards on clockwise curves.

pts : ResizeArray<Pt>

The points of the Polyline2D to offset.

Returns: ResizeArray<Pt>

A new ResizeArray of Points. The point count will be the same as the input.

offset' uTurnBehavior dist pts

Full Usage: offset' uTurnBehavior dist pts

Parameters:
    uTurnBehavior : UTurn - What to do at a 180 degree U-turn? Fail, Chamfer with two points, UseThreshold or Skip the point. This will only be applied for joints bigger than 175° degrees.
    dist : float - The distance to offset the Polyline2D. A positive distance will offset inwards on counter-clockwise curves. A negative distance will offset inwards on clockwise curves.
    pts : ResizeArray<Pt> - The points of the Polyline2D to offset.

Returns: ResizeArray<Pt> A new ResizeArray of Points. Due to error correction at sharp U-turns the point count may not be the same as the input.

A constant-distance offset algorithm for closed or open polylines.

uTurnBehavior : UTurn

What to do at a 180 degree U-turn? Fail, Chamfer with two points, UseThreshold or Skip the point. This will only be applied for joints bigger than 175° degrees.

dist : float

The distance to offset the Polyline2D. A positive distance will offset inwards on counter-clockwise curves. A negative distance will offset inwards on clockwise curves.

pts : ResizeArray<Pt>

The points of the Polyline2D to offset.

Returns: ResizeArray<Pt>

A new ResizeArray of Points. Due to error correction at sharp U-turns the point count may not be the same as the input.

offset'' useUTurnBehaviorAbove uTurnBehavior dist pts

Full Usage: offset'' useUTurnBehaviorAbove uTurnBehavior dist pts

Parameters:
    useUTurnBehaviorAbove : float<MeasureProduct<cosine, MeasureOne>> - The angle between normals after which the uTurnBehavior is applied.
    uTurnBehavior : UTurn - What to do at a 180 degree U-turn? Fail, Chamfer with two points, UseThreshold or Skip the point.
    dist : float - The distance to offset the Polyline2D. A positive distance will offset inwards on counter-clockwise curves. A negative distance will offset inwards on clockwise curves.
    pts : ResizeArray<Pt> - The points of the Polyline2D to offset.

Returns: ResizeArray<Pt> A new ResizeArray of Points. Due to error correction at sharp U-turns the point count may not be the same as the input.

A constant-distance offset algorithm for closed or open polylines.

useUTurnBehaviorAbove : float<MeasureProduct<cosine, MeasureOne>>

The angle between normals after which the uTurnBehavior is applied.

uTurnBehavior : UTurn

What to do at a 180 degree U-turn? Fail, Chamfer with two points, UseThreshold or Skip the point.

dist : float

The distance to offset the Polyline2D. A positive distance will offset inwards on counter-clockwise curves. A negative distance will offset inwards on clockwise curves.

pts : ResizeArray<Pt>

The points of the Polyline2D to offset.

Returns: ResizeArray<Pt>

A new ResizeArray of Points. Due to error correction at sharp U-turns the point count may not be the same as the input.

offsetVariable dists pts

Full Usage: offsetVariable dists pts

Parameters:
    dists : ResizeArray<float> - The distances to offset the Polyline. One item less than pts.
    pts : ResizeArray<Pt> - The points of the Polyline to offset. Positive values will create inside offsets on counter-clockwise polylines.

Returns: ResizeArray<Pt> A new ResizeArray of Points. The point count is the same as the input.

Offsetting each segment by its own distance. For closed or open polylines. Fails at U-turns above 175 degrees and at colinear segments within less than 2.5 degrees.

dists : ResizeArray<float>

The distances to offset the Polyline. One item less than pts.

pts : ResizeArray<Pt>

The points of the Polyline to offset. Positive values will create inside offsets on counter-clockwise polylines.

Returns: ResizeArray<Pt>

A new ResizeArray of Points. The point count is the same as the input.

offsetVariable' uTurnBehavior varDistParallelBehavior dists pts

Full Usage: offsetVariable' uTurnBehavior varDistParallelBehavior dists pts

Parameters:
    uTurnBehavior : UTurn - What to do at a 180 degree U-turn? Fail, Chamfer with two points, UseThreshold or Skip the point. will be applied for joints bigger than 175° degrees.
    varDistParallelBehavior : VarDistParallel - What to do with colinear segments within 2.5 degrees when offset distances are different too..
    dists : ResizeArray<float> - The distances to offset the Polyline. One item less than pts. Positive values will create inside offsets on counter-clockwise polylines.
    pts : ResizeArray<Pt> - The points of the Polyline to offset.

Returns: ResizeArray<Pt> A new ResizeArray of Points. Due to error correction at sharp U-turns or the picked behaviour for collinear segments the point count may not be the same as the input.

Offsetting each segment by its own distance. The behaviour for colinear and 180 degree U-turns is configurable.

uTurnBehavior : UTurn

What to do at a 180 degree U-turn? Fail, Chamfer with two points, UseThreshold or Skip the point. will be applied for joints bigger than 175° degrees.

varDistParallelBehavior : VarDistParallel

What to do with colinear segments within 2.5 degrees when offset distances are different too..

dists : ResizeArray<float>

The distances to offset the Polyline. One item less than pts. Positive values will create inside offsets on counter-clockwise polylines.

pts : ResizeArray<Pt>

The points of the Polyline to offset.

Returns: ResizeArray<Pt>

A new ResizeArray of Points. Due to error correction at sharp U-turns or the picked behaviour for collinear segments the point count may not be the same as the input.

offsetVariable'' useUTurnBehaviorAbove useVarDistParallelBehaviorBelow uTurnBehavior varDistParallelBehavior dists pts

Full Usage: offsetVariable'' useUTurnBehaviorAbove useVarDistParallelBehaviorBelow uTurnBehavior varDistParallelBehavior dists pts

Parameters:
    useUTurnBehaviorAbove : float<MeasureProduct<cosine, MeasureOne>> - The angle between normals after which, instead of a normal miter, the joint is chamfered by adding an extra point.
    useVarDistParallelBehaviorBelow : float<MeasureProduct<cosine, MeasureOne>> - The angle between normals below which points are considered colinear and VarDistParallelBehavior is applied if distances are not the same.
    uTurnBehavior : UTurn - What to do at a 180 degree U-turn? Fail, Chamfer with two points, UseThreshold or Skip the point.
    varDistParallelBehavior : VarDistParallel - What to do with colinear segments below 'useVarDistParallelBehaviorBelow' degrees when offset distances are different too.
    dists : ResizeArray<float> - The distances to offset the Polyline. One item less than pts. Positive values will create inside offsets on counter-clockwise polylines.
    pts : ResizeArray<Pt> - The points of the Polyline to offset.

Returns: ResizeArray<Pt> A new ResizeArray of Points. Due to error correction at sharp U-turns or the picked behaviour for collinear segments the point count may not be the same as the input.

Offsetting each segment by its own distance. For closed or open polylines. The behaviour and the limits for colinear and 180 degree U-turns are configurable.

useUTurnBehaviorAbove : float<MeasureProduct<cosine, MeasureOne>>

The angle between normals after which, instead of a normal miter, the joint is chamfered by adding an extra point.

useVarDistParallelBehaviorBelow : float<MeasureProduct<cosine, MeasureOne>>

The angle between normals below which points are considered colinear and VarDistParallelBehavior is applied if distances are not the same.

uTurnBehavior : UTurn

What to do at a 180 degree U-turn? Fail, Chamfer with two points, UseThreshold or Skip the point.

varDistParallelBehavior : VarDistParallel

What to do with colinear segments below 'useVarDistParallelBehaviorBelow' degrees when offset distances are different too.

dists : ResizeArray<float>

The distances to offset the Polyline. One item less than pts. Positive values will create inside offsets on counter-clockwise polylines.

pts : ResizeArray<Pt>

The points of the Polyline to offset.

Returns: ResizeArray<Pt>

A new ResizeArray of Points. Due to error correction at sharp U-turns or the picked behaviour for collinear segments the point count may not be the same as the input.

offsetVariableWithDirections (pts, nDirs, dists, varDistParallelBehavior, uTurnBehavior, useVarDistParallelBehaviorBelow, useUTurnBehaviorAbove)

Full Usage: offsetVariableWithDirections (pts, nDirs, dists, varDistParallelBehavior, uTurnBehavior, useVarDistParallelBehaviorBelow, useUTurnBehaviorAbove)

Parameters:
    pts : ResizeArray<Pt> - The points of the Polyline to offset.
    nDirs : ResizeArray<UnitVc> - The directions or normals of the Polyline segments to offset. One item less than pts. Must be created by counter clockwise rotation of each segment.
    dists : IList<float> - The distances to offset the Polyline. One item less than pts. Positive values will create inside offsets on counter-clockwise polylines.
    varDistParallelBehavior : VarDistParallel - What to do with colinear segments below 'useVarDistParallelBehaviorBelow' degrees when offset distances are different too.
    uTurnBehavior : UTurn - What to do at a 180 degree U-turn? Fail, Chamfer with two points, UseThreshold or Skip the point.
    useVarDistParallelBehaviorBelow : float<MeasureProduct<cosine, MeasureOne>> - The angle between normals below which points are considered colinear and VarDistParallelBehavior is applied if distances are not the same.
    useUTurnBehaviorAbove : float<MeasureProduct<cosine, MeasureOne>> - The angle between normals after which uTurnBehavior is applied .

Returns: ResizeArray<Pt> A new ResizeArray of Points. Due to error correction at sharp U-turns the point count may not be the same as the input.

Offsetting each segment by its own distance. For closed or open polylines. Adds 2 chamfer points at U-turns and skips colinear points.

This function requires precomputed segment normals; the simpler 'Offset2D.offsetVariable' uses it internally too.

pts : ResizeArray<Pt>

The points of the Polyline to offset.

nDirs : ResizeArray<UnitVc>

The directions or normals of the Polyline segments to offset. One item less than pts. Must be created by counter clockwise rotation of each segment.

dists : IList<float>

The distances to offset the Polyline. One item less than pts. Positive values will create inside offsets on counter-clockwise polylines.

varDistParallelBehavior : VarDistParallel

What to do with colinear segments below 'useVarDistParallelBehaviorBelow' degrees when offset distances are different too.

uTurnBehavior : UTurn

What to do at a 180 degree U-turn? Fail, Chamfer with two points, UseThreshold or Skip the point.

useVarDistParallelBehaviorBelow : float<MeasureProduct<cosine, MeasureOne>>

The angle between normals below which points are considered colinear and VarDistParallelBehavior is applied if distances are not the same.

useUTurnBehaviorAbove : float<MeasureProduct<cosine, MeasureOne>>

The angle between normals after which uTurnBehavior is applied .

Returns: ResizeArray<Pt>

A new ResizeArray of Points. Due to error correction at sharp U-turns the point count may not be the same as the input.

offsetWithDirections (pts, dirs, dist, uTurnBehavior, useUTurnBehaviorAbove)

Full Usage: offsetWithDirections (pts, dirs, dist, uTurnBehavior, useUTurnBehaviorAbove)

Parameters:
    pts : ResizeArray<Pt> - The points of the Polyline2D to offset.
    dirs : ResizeArray<UnitVc> - The normals of the Polyline2D to offset. One item less than pts. Must be created by counter clockwise rotation of each segment.
    dist : float - The distance to offset the Polyline2D.
    uTurnBehavior : UTurn - What to do at a 180 degree U-turn? Fail, Chamfer with two points, UseThreshold or Skip the point.
    useUTurnBehaviorAbove : float<MeasureProduct<cosine, MeasureOne>> - The angle between normals after which, U-TurnBehavior is used.

Returns: ResizeArray<Pt> A new ResizeArray of Points. Due to error correction at sharp U-turns the point count may not be the same as the input.

For closed or open polylines.

This function requires precomputed segment normals; the simpler 'Offset2D.offset' uses it internally too.

pts : ResizeArray<Pt>

The points of the Polyline2D to offset.

dirs : ResizeArray<UnitVc>

The normals of the Polyline2D to offset. One item less than pts. Must be created by counter clockwise rotation of each segment.

dist : float

The distance to offset the Polyline2D.

uTurnBehavior : UTurn

What to do at a 180 degree U-turn? Fail, Chamfer with two points, UseThreshold or Skip the point.

useUTurnBehaviorAbove : float<MeasureProduct<cosine, MeasureOne>>

The angle between normals after which, U-TurnBehavior is used.

Returns: ResizeArray<Pt>

A new ResizeArray of Points. Due to error correction at sharp U-turns the point count may not be the same as the input.

setOffCorner pt dist nPrev nNext cosine

Full Usage: setOffCorner pt dist nPrev nNext cosine

Parameters:
Returns: Pt
Modifiers: inline

The core offset Algorithm for constant distance offsets. Returns the offset point based on the previous and next normals, the distance, and the precomputed cosine (= dot product of nPrev * nNext). (pt + (nPrev + nNext) * (dist / (1.0 + cosine)))

pt : Pt
dist : float
nPrev : UnitVc
nNext : UnitVc
cosine : float
Returns: Pt

sqOpenTolerance

Full Usage: sqOpenTolerance

Returns: float

The squared tolerance for open polylines.

Returns: float

Type something to start searching.