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.

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 xys

Full Usage: makeOffsetDirections xys

Parameters:
    xys : ResizeArray<float>

Returns: ResizeArray<float>

Returns the normals of the segments of an X and Y interleaved ResizeArray; each segment is rotated 90 degrees in counter-clockwise order. The vector count is one less than the input point count. The result is interleaved x/y values. Fails on duplicate points.

xys : ResizeArray<float>
Returns: ResizeArray<float>

makeUnitTangents xys

Full Usage: makeUnitTangents xys

Parameters:
    xys : ResizeArray<float>

Returns: ResizeArray<float>

Returns the unit tangents of the segments of an X and Y interleaved ResizeArray. The vector count is one less than the input point count. The result is interleaved x/y values. Fails on duplicate points.

xys : ResizeArray<float>
Returns: ResizeArray<float>

offset dist xys

Full Usage: offset dist xys

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.
    xys : ResizeArray<float> - The points of the Polyline2D to offset.

Returns: ResizeArray<float> 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.

xys : ResizeArray<float>

The points of the Polyline2D to offset.

Returns: ResizeArray<float>

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

offset' uTurnBehavior dist xys

Full Usage: offset' uTurnBehavior dist xys

Parameters:
    uTurnBehavior : UTurn - What to do at a 180 degree U-turn? Fail, Chamfer with two points, or UseThreshold. 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.
    xys : ResizeArray<float> - The X and Y interleaved ResizeArray of the Polyline2D to offset.

Returns: ResizeArray<float> 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, or UseThreshold. 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.

xys : ResizeArray<float>

The X and Y interleaved ResizeArray of the Polyline2D to offset.

Returns: ResizeArray<float>

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 xys

Full Usage: offset'' useUTurnBehaviorAbove uTurnBehavior dist xys

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, or UseThreshold.
    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.
    xys : ResizeArray<float> - The X and Y interleaved ResizeArray of the Polyline2D to offset.

Returns: ResizeArray<float> 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, or UseThreshold.

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.

xys : ResizeArray<float>

The X and Y interleaved ResizeArray of the Polyline2D to offset.

Returns: ResizeArray<float>

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 xys

Full Usage: offsetVariable dists xys

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

Returns: ResizeArray<float> 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 xys.

xys : ResizeArray<float>

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

Returns: ResizeArray<float>

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

offsetVariable' uTurnBehavior varDistParallelBehavior dists xys

Full Usage: offsetVariable' uTurnBehavior varDistParallelBehavior dists xys

Parameters:
    uTurnBehavior : UTurn - What to do at a 180 degree U-turn? Fail, Chamfer with two points, or UseThreshold. 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 xys. Positive values will create inside offsets on counter-clockwise polylines.
    xys : ResizeArray<float> - The points of the Polyline to offset.

Returns: ResizeArray<float> 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, or UseThreshold. 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 xys. Positive values will create inside offsets on counter-clockwise polylines.

xys : ResizeArray<float>

The points of the Polyline to offset.

Returns: ResizeArray<float>

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 xys

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

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, or UseThreshold.
    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 xys. Positive values will create inside offsets on counter-clockwise polylines.
    xys : ResizeArray<float> - The points of the Polyline to offset.

Returns: ResizeArray<float> 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, or UseThreshold.

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 xys. Positive values will create inside offsets on counter-clockwise polylines.

xys : ResizeArray<float>

The points of the Polyline to offset.

Returns: ResizeArray<float>

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 (xys, nDirs, dists, varDistParallelBehavior, uTurnBehavior, useVarDistParallelBehaviorBelow, useUTurnBehaviorAbove)

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

Parameters:
    xys : ResizeArray<float> - The points of the Polyline to offset as a flat array of coordinates.
    nDirs : ResizeArray<float> - The interleaved directions or normals of the Polyline segments to offset. One vector less than xys. Must be created by counter clockwise rotation of each segment.
    dists : IList<float> - The distances to offset the Polyline. One item less than xys. 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, or UseThreshold.
    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<float> A new ResizeArray of Points as a flat array of coordinates. If UTurnBehavior.Chamfer is used the total point count may be more than 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.

xys : ResizeArray<float>

The points of the Polyline to offset as a flat array of coordinates.

nDirs : ResizeArray<float>

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

dists : IList<float>

The distances to offset the Polyline. One item less than xys. 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, or UseThreshold.

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<float>

A new ResizeArray of Points as a flat array of coordinates. If UTurnBehavior.Chamfer is used the total point count may be more than the input.

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

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

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

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

For closed or open X and Y interleaved ResizeArrays of x and y.

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

xys : ResizeArray<float>

The interleaved coordinates of the Polyline2D to offset.

dirs : ResizeArray<float>

The interleaved normals of the Polyline2D to offset. One vector less than the point count. Must be created by counter clockwise rotation of each segment.

dist : float

The distance to offset the coordinates.

uTurnBehavior : UTurn

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

useUTurnBehaviorAbove : float<MeasureProduct<cosine, MeasureOne>>

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

Returns: ResizeArray<float>

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

removeUTurns (xys, ns, minCos)

Full Usage: removeUTurns (xys, ns, minCos)

Parameters:
    xys : ResizeArray<float> - The interleaved coordinates of the polyline.
    ns : ResizeArray<float> - The precomputed interleaved unit tangents or unit normals. (either are fine)
    minCos : float<MeasureProduct<cosine, MeasureOne>> - The minimum cosine value for detecting U-turns.

Returns: ResizeArray<float> If no U-turns are present, the original ResizeArray is returned. If U-turns are present, a new ResizeArray of coordinates is returned with the U-turns removed.

Removes Sharp U-Turns from an X and Y interleaved ResizeArray, like Polyline2D is using

xys : ResizeArray<float>

The interleaved coordinates of the polyline.

ns : ResizeArray<float>

The precomputed interleaved unit tangents or unit normals. (either are fine)

minCos : float<MeasureProduct<cosine, MeasureOne>>

The minimum cosine value for detecting U-turns.

Returns: ResizeArray<float>

If no U-turns are present, the original ResizeArray is returned. If U-turns are present, a new ResizeArray of coordinates is returned with the U-turns removed.

setOffCorner (res, x, y, dist, nPrevX, nPrevY, nNextX, nNextY, cosine)

Full Usage: setOffCorner (res, x, y, dist, nPrevX, nPrevY, nNextX, nNextY, cosine)

Parameters:
    res : ResizeArray<float>
    x : float
    y : float
    dist : float
    nPrevX : float
    nPrevY : float
    nNextX : float
    nNextY : float
    cosine : float

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)))

res : ResizeArray<float>
x : float
y : float
dist : float
nPrevX : float
nPrevY : float
nNextX : float
nNextY : float
cosine : float

sqOpenTolerance

Full Usage: sqOpenTolerance

Returns: float

The squared tolerance for open polylines.

Returns: float

toStringXYs xys

Full Usage: toStringXYs xys

Parameters:
    xys : ResizeArray<float>

Returns: string

A helper function to print interleaved ResizeArrays for debugging.

xys : ResizeArray<float>
Returns: string

Type something to start searching.