# `GSPath`

*Class*

A graphical path made of nodes.

## Declaration

```swift
class GSPath
```

```objc
@interface GSPath : GSShape
```

```python
class GSPath(GSShape)
```

## Overview

A path describes one continuous outline contour; it is not divided into separate subpaths.

The nodes are stored in drawing order. On-curve nodes lie on the contour and define segment endpoints. Off-curve nodes control the shape of curve segments.

A segment runs from one on-curve node to the next on-curve node. The on-curve node type describes the segment ending at that node. A *path time* identifies a position within a segment by combining the ending on-curve node integer index with a fractional segment position.

Closed paths connect the final node to the first node. Open paths do not wrap at their ends. Navigation path APIs wrap indices for closed paths and reject out-of-range indices for open paths.

A path is expected to contain nodes during normal use. Empty paths can exist immediately after creation, but many path operations assume a populated path. Paths without on-curve nodes are interpreted as using quadratic path segments with implicit on-curve nodes.

## Topics

### Creating a Path

- [`GSPath initWithDict:format:`](/Core/GlyphsCore/GSPath/initWithDict:format:) — Creates a path from a Glyphs file dictionary representation.
- [`GSPath initWithGlyphsParser:format:`](/Core/GlyphsCore/GSPath/initWithGlyphsParser:format:) — Creates a path from the Glyphs file representation at the current parser position.
- [`GSPath pathWithString:isClosed:`](/Core/GlyphsCore/GSPath/pathWithString:isClosed:) — Creates a path from a sequence of node element strings.
- [`GSPath pathWithRect:`](/Core/GlyphsCore/GSPath/pathWithRect:) — Creates a closed rectangular path enclosing the rectangle.
- [`GSPath circleWithRect:`](/Core/GlyphsCore/GSPath/circleWithRect:) — Creates a closed cubic path approximating an ellipse inside the rectangle.
- [`GSPath circleWithCenter:radius:`](/Core/GlyphsCore/GSPath/circleWithCenter:radius:) — Creates a closed cubic path approximating a circle.
- [`GSPath ellipseWithCenter:radius1:radius2:angle:`](/Core/GlyphsCore/GSPath/ellipseWithCenter:radius1:radius2:angle:) — Creates a closed cubic path approximating an ellipse.

### Closed/Open

- [`GSPath.closed`](/Core/GlyphsCore/GSPath/closed) — Whether the final node connects to the first node.
- [`GSPath setClosePath:`](/Core/GlyphsCore/GSPath/setClosePath:) — Opens or closes the path and adjusts its endpoint nodes.
- [`GSPath setClosePath:fixStartNode:`](/Core/GlyphsCore/GSPath/setClosePath:fixStartNode:) — Opens or closes the path and adjusts its endpoint nodes.

### Path Direction

- [`GSPath.GSPathDirection`](/Core/GlyphsCore/GSPath/GSPathDirection) — The traversal direction of a path.
- [`GSPath direction`](/Core/GlyphsCore/GSPath/direction) — The direction in which the nodes traverse the path.
- [`GSPath reverse`](/Core/GlyphsCore/GSPath/reverse) — Reverses the path direction.
- [`GSPath reverseFast`](/Core/GlyphsCore/GSPath/reverseFast) — Reverses the path direction without registering undo or notifying the layer.

### Nodes

- [`GSNode`](/Core/GlyphsCore/GSNode) — An on-curve or off-curve point of a path.
- [`GSPath.nodes`](/Core/GlyphsCore/GSPath/nodes) — The ordered nodes describing the path.
- [`GSPath setNodesFast:`](/Core/GlyphsCore/GSPath/setNodesFast:) — Replaces all nodes without registering undo or notifying the layer.
- [`GSPath countOfNodes`](/Core/GlyphsCore/GSPath/countOfNodes) — The number of nodes.

### Inserting Nodes

- [`GSPath addNode:`](/Core/GlyphsCore/GSPath/addNode:) — Appends a node and aligns its position to the layer grid.
- [`GSPath addNodeFast:`](/Core/GlyphsCore/GSPath/addNodeFast:) — Appends a node without registering undo, aligning its position, or notifying the layer.
- [`GSPath addNodes:`](/Core/GlyphsCore/GSPath/addNodes:) — Appends nodes.
- [`GSPath addNodeWithPosition:type:connection:attributes:`](/Core/GlyphsCore/GSPath/addNodeWithPosition:type:connection:attributes:) — Appends a new node and aligns its position to the layer grid.
- [`GSPath addNodeFastWithPosition:type:connection:attributes:`](/Core/GlyphsCore/GSPath/addNodeFastWithPosition:type:connection:attributes:) — Appends a new node without registering undo, aligning its position, or notifying the layer.
- [`GSPath addCurveWithOff1:off2:end:connection:attributes:`](/Core/GlyphsCore/GSPath/addCurveWithOff1:off2:end:connection:attributes:) — Appends a cubic curve segment and aligns its node positions to the layer grid.
- [`GSPath addCurveFastWithOff1:off2:end:connection:attributes:`](/Core/GlyphsCore/GSPath/addCurveFastWithOff1:off2:end:connection:attributes:) — Appends a cubic curve segment without registering undo, aligning its node positions, or notifying the layer.
- [`GSPath insertObject:inNodesAtIndex:`](/Core/GlyphsCore/GSPath/insertObject:inNodesAtIndex:) — Inserts a node at an index and aligns its position to the layer grid.
- [`GSPath insertNodeWithPathTime:`](/Core/GlyphsCore/GSPath/insertNodeWithPathTime:) — Inserts an on-curve node at a path time while preserving the path shape.
- [`GSPath insertOffcurveWithStartIdx:endIdx:`](/Core/GlyphsCore/GSPath/insertOffcurveWithStartIdx:endIdx:) — Inserts an off-curve node into a quadratic segment.
- [`GSPath addExtremes:checkSelection:`](/Core/GlyphsCore/GSPath/addExtremes:checkSelection:) — Adds nodes at extrema of cubic curve segments.
- [`GSPath addInflections`](/Core/GlyphsCore/GSPath/addInflections) — Adds nodes at inflection points of cubic curve segments.

### Removing Nodes

- [`GSPath removeNodes:`](/Core/GlyphsCore/GSPath/removeNodes:) — Removes nodes.
- [`GSPath removeObjectFromNodesAtIndex:`](/Core/GlyphsCore/GSPath/removeObjectFromNodesAtIndex:) — Removes the node at an index.
- [`GSPath removeNode:`](/Core/GlyphsCore/GSPath/removeNode:) — Removes a node.
- [`GSPath removeNodeFast:`](/Core/GlyphsCore/GSPath/removeNodeFast:) — Removes a node without registering undo, updating the layer selection, or notifying the layer.
- [`GSPath removeNodeCheck:`](/Core/GlyphsCore/GSPath/removeNodeCheck:) — Removes a node and adjusts adjacent nodes to keep the path structurally valid.
- [`GSPath removeNodeCheckKeepShape:`](/Core/GlyphsCore/GSPath/removeNodeCheckKeepShape:) — Removes a node and adjusts adjacent segments to approximate the path shape.
- [`GSPath removeNodeCheckKeepShape:normalizeHandles:error:`](/Core/GlyphsCore/GSPath/removeNodeCheckKeepShape:normalizeHandles:error:) — Removes a node and adjusts adjacent segments to approximate the path shape.

### Node Navigation

- [`GSPath nodeAtIndex:`](/Core/GlyphsCore/GSPath/nodeAtIndex:) — The node at an index.
- [`GSPath indexOfNode:`](/Core/GlyphsCore/GSPath/indexOfNode:) — The index of a node, or `NSNotFound` when the node is not in the path.
- [`GSPath firstOncurveNodeIndex`](/Core/GlyphsCore/GSPath/firstOncurveNodeIndex) — An index from which every segment can be traversed in node order.
- [`GSPath nextOncurveNodeFromIndex:`](/Core/GlyphsCore/GSPath/nextOncurveNodeFromIndex:) — The next on-curve node after an index.
- [`GSPath previousOncurveNodeFromIndex:`](/Core/GlyphsCore/GSPath/previousOncurveNodeFromIndex:) — The previous on-curve node before an index.
- [`GSPath.startNode`](/Core/GlyphsCore/GSPath/startNode) — For open paths, returns the first node of the path, otherwise `nil`.
- [`GSPath.endNode`](/Core/GlyphsCore/GSPath/endNode) — For open paths, returns the last node of the path, otherwise `nil`.
- [`GSPath findStartNode`](/Core/GlyphsCore/GSPath/findStartNode) — The node used to begin traversing a closed path, or `nil` for an open path.
- [`GSPath findMinNode`](/Core/GlyphsCore/GSPath/findMinNode) — The lowest on-curve node, preferring the leftmost node at equal height.
- [`GSPath fixStartNode`](/Core/GlyphsCore/GSPath/fixStartNode) — Moves trailing off-curve nodes to the beginning of a closed path.
- [`GSPath makeNodeFirst:`](/Core/GlyphsCore/GSPath/makeNodeFirst:) — Makes a node the start node of the path.
- [`GSPath indexOfTTStartNode`](/Core/GlyphsCore/GSPath/indexOfTTStartNode) — The index preceding the first on-curve node for TrueType path traversal.

### Path Time

- [`GSPath pointAtPathTime:`](/Core/GlyphsCore/GSPath/pointAtPathTime:) — The point at a path time.
- [`GSPath nearestPointOnPath:pathTime:`](/Core/GlyphsCore/GSPath/nearestPointOnPath:pathTime:) — Finds the point on the path nearest a point.
- [`GSPath nearestNodeWithPathTime:`](/Core/GlyphsCore/GSPath/nearestNodeWithPathTime:) — Returns the on-curve node nearest a path time.

### Editing Nodes

- [`GSPath setSmooth:withCenterPoint:oppositePoint:`](/Core/GlyphsCore/GSPath/setSmooth:withCenterPoint:oppositePoint:) — Aligns a node opposite a point about a center point while preserving its distance from the center point.
- [`GSPath setSmooth:withCenterNode:oppositeNode:`](/Core/GlyphsCore/GSPath/setSmooth:withCenterNode:oppositeNode:) — Aligns a node opposite another node about a center node while preserving its distance from the center node.
- [`GSPath setMirrored:withCenterPoint:oppositePoint:`](/Core/GlyphsCore/GSPath/setMirrored:withCenterPoint:oppositePoint:) — Moves an off-curve node to the reflection of a point about a center point.
- [`GSPath checkConnections`](/Core/GlyphsCore/GSPath/checkConnections) — Normalizes node types and connections based on adjacent nodes.
- [`GSPath checkConnectionForNode:`](/Core/GlyphsCore/GSPath/checkConnectionForNode:) — Sets a node connection based on the alignment of adjacent nodes.
- [`GSPath setLocked:withPoint:`](/Core/GlyphsCore/GSPath/setLocked:withPoint:) — Moves an off-curve node by an offset while preserving its locked direction.
- [`GSPath setLocked:shadow:withPoint:`](/Core/GlyphsCore/GSPath/setLocked:shadow:withPoint:) — Moves an off-curve node by an offset, constrained using a corresponding node in another path.

### Segments

- [`GSPath.segments`](/Core/GlyphsCore/GSPath/segments) — The path represented as path segments.
- [`GSPath.segmentsFast`](/Core/GlyphsCore/GSPath/segmentsFast) — The path represented as path segments without collecting path object information.
- [`GSPath segmentAtNodeIndex:`](/Core/GlyphsCore/GSPath/segmentAtNodeIndex:) — The segment associated with a node index.
- [`GSPath segmentAtNodeIndex:segmentStartIndex:segmentEndIndex:`](/Core/GlyphsCore/GSPath/segmentAtNodeIndex:segmentStartIndex:segmentEndIndex:) — The segment associated with a node index and the node index range it covers.

### Geometry

- [`GSPath bounds`](/Core/GlyphsCore/GSPath/bounds) — The bounds of the path.
- [`GSPath fastBounds`](/Core/GlyphsCore/GSPath/fastBounds) — The bounds of the path nodes.
- [`GSPath area`](/Core/GlyphsCore/GSPath/area) — The unsigned area enclosed by the path.
- [`GSPath length`](/Core/GlyphsCore/GSPath/length) — The length of all path segments.
- [`GSPath enclosesPath:`](/Core/GlyphsCore/GSPath/enclosesPath:) — Whether the path encloses another path.
- [`GSPath intersectionsWithLineFrom:to:`](/Core/GlyphsCore/GSPath/intersectionsWithLineFrom:to:) — Intersections between the path and a line segment.

### Tangents

- [`GSPath tangentAngleAtNode:direction:`](/Core/GlyphsCore/GSPath/tangentAngleAtNode:direction:) — The tangent angle at a node.
- [`GSPath tangentAngleAtNodeAtIndex:direction:`](/Core/GlyphsCore/GSPath/tangentAngleAtNodeAtIndex:direction:) — The tangent angle at a node index.
- [`GSPath unitVectorAtNodeAtIndex:`](/Core/GlyphsCore/GSPath/unitVectorAtNodeAtIndex:) — The tangent unit vector at a node index.
- [`GSPath unitVectorAtNodeAtIndex:direction:`](/Core/GlyphsCore/GSPath/unitVectorAtNodeAtIndex:direction:) — The tangent unit vector at a node index.

### Convenience

- [`GSPath positionAtIndex:`](/Core/GlyphsCore/GSPath/positionAtIndex:) — Position for a node index.
- [`GSPath makeCornerFirstNodeIndex:endNodeIndex:`](/Core/GlyphsCore/GSPath/makeCornerFirstNodeIndex:endNodeIndex:) — Replaces a node range with a sharp corner fitted to the neighboring segments.
- [`GSPath openCornerAtNode:offset:`](/Core/GlyphsCore/GSPath/openCornerAtNode:offset:) — Opens an on-curve corner by the offset distance.
- [`GSPath removeOffcurveWithStartIdx:endIdx:`](/Core/GlyphsCore/GSPath/removeOffcurveWithStartIdx:endIdx:) — Removes an off-curve node range from a quadratic segment.

### Representations

- [`GSPath bezierPath`](/Core/GlyphsCore/GSPath/bezierPath) — An AppKit drawing path for the path.
- [`GSPath expandedStroke`](/Core/GlyphsCore/GSPath/expandedStroke) — Stroke outlines built from the path stroke attributes.
- [`GSPath flattenedPath`](/Core/GlyphsCore/GSPath/flattenedPath) — A path with path components expanded into outline nodes.
- [`GSPath removeOutsideOverlaps:`](/Core/GlyphsCore/GSPath/removeOutsideOverlaps:) — Removes outside overlaps at sharp line corners.
- [`GSPath decomposeCorner:`](/Core/GlyphsCore/GSPath/decomposeCorner:) — Replaces a corner, cap, segment, brush, or head hint with outline geometry.
- [`GSPath convertSpecialToBezier`](/Core/GlyphsCore/GSPath/convertSpecialToBezier) — A cubic path representation with special curve types converted to Bezier curves.
- [`GSPath primitiveRepresentation`](/Core/GlyphsCore/GSPath/primitiveRepresentation) — A path tracing the same outline using primitive node types and connections.
- [`GSPath primitiveRepresentationSecondaryPen:`](/Core/GlyphsCore/GSPath/primitiveRepresentationSecondaryPen:) — Paths tracing the same outline using primitive node types and connections.
- [`GSPath.isPrimitive`](/Core/GlyphsCore/GSPath/isPrimitive) — Whether the path already uses primitive node types and connections.

### Cleanup

- [`GSPath cleanUp`](/Core/GlyphsCore/GSPath/cleanUp) — Removes redundant nodes and rounds node positions to the layer grid.
- [`GSPath cleanUpGrid:`](/Core/GlyphsCore/GSPath/cleanUpGrid:) — Removes redundant nodes and rounds node positions to a grid.
- [`GSPath findRequiredNodeIndexes:grid:`](/Core/GlyphsCore/GSPath/findRequiredNodeIndexes:grid:) — Adds the node indices that cleanup would keep.
- [`GSPath removeDuplicateNodes`](/Core/GlyphsCore/GSPath/removeDuplicateNodes) — Removes adjacent on-curve nodes at the same position.

### Curve Conversion

- [`GSPathCurveError`](/Core/GlyphsCore/GSPathCurveError) — The default tolerance for converting cubic curve segments to quadratic curve segments.
- [`GSPath convertToCubic`](/Core/GlyphsCore/GSPath/convertToCubic) — Converts the path to cubic curve segments.
- [`GSPath convertToTrueTypeError`](/Core/GlyphsCore/GSPath/convertToTrueTypeError) — The tolerance used when converting the path to quadratic curve segments.
- [`GSPath convertToQuadratic`](/Core/GlyphsCore/GSPath/convertToQuadratic) — Converts the path to quadratic curve segments.
- [`GSPath convertToQuadraticWithError:`](/Core/GlyphsCore/GSPath/convertToQuadraticWithError:) — Converts the path to quadratic curve segments.
- [`GSPath convertToBezier`](/Core/GlyphsCore/GSPath/convertToBezier) — Converts special curve node types to Bezier curve segments.
- [`GSPath convertToHobby`](/Core/GlyphsCore/GSPath/convertToHobby) — Converts the path to Hobby curve segments.
- [`GSPath applySolutions:toNodes:grid:`](/Core/GlyphsCore/GSPath/applySolutions:toNodes:grid:) — Applies converted quadratic segments to existing nodes.

### Checking Path Contents

- [`GSPath hasOncurve`](/Core/GlyphsCore/GSPath/hasOncurve) — Whether the path contains at least one on-curve node.
- [`GSPath hasTrueTypeOutline`](/Core/GlyphsCore/GSPath/hasTrueTypeOutline) — Whether the path uses TrueType-compatible node types.
- [`GSPath hasTrueTypeCurve`](/Core/GlyphsCore/GSPath/hasTrueTypeCurve) — Whether the path contains quadratic curve node types.
- [`GSPath hasNonCubicCurves`](/Core/GlyphsCore/GSPath/hasNonCubicCurves) — Whether the path contains curve node types that are not cubic.
- [`GSPath hasPenPoints`](/Core/GlyphsCore/GSPath/hasPenPoints) — Whether any node contains pen point data.

### Layer API

- [`GSPath elementDidChange:`](/Core/GlyphsCore/GSPath/elementDidChange:) — Notifies the path that one of its elements changed.

### Encoding

- [`GSPath saveToFile:format:context:error:`](/Core/GlyphsCore/GSPath/saveToFile:format:context:error:) — Writes a Glyphs file representation.

### Equality and Comparison

- [`GSPath isEqualToPath:`](/Core/GlyphsCore/GSPath/isEqualToPath:) — Whether another path has the same closed state, node count, and node positions.
- [`GSPath compareHash`](/Core/GlyphsCore/GSPath/compareHash) — A geometric hash for matching paths with the same node structure.
- [`GSPath nodeIndexForHash:callback:`](/Core/GlyphsCore/GSPath/nodeIndexForHash:callback:) — Enumerates matching node positions for a geometric hash.
- [`GSPath transformForHash:`](/Core/GlyphsCore/GSPath/transformForHash:) — A transform that maps a geometric hash to the matching position on the path.

### Instance Methods

- [`GSPath checkConnectionsFast`](/Core/GlyphsCore/GSPath/checkConnectionsFast) — same as `checkConnections` but without notifying and undo. Good when loading the path
- [`GSPath setClosedFast:`](/Core/GlyphsCore/GSPath/setClosedFast:) — same as ``setClosed:``` but without notifying and undo. Good when loading the path

### Type Methods


## Relationships

### Inherits From

- [`GSShape`](/Core/GlyphsCore/GSShape)

### Conforms To

- [`GSContainerProtocol`](/Core/GlyphsCore/GSContainerProtocol)
- [`GSDrawPath`](/Core/GlyphsCore/GSDrawPath)

## See Also

### Shapes

- [`GSShape`](/Core/GlyphsCore/GSShape) — An abstract base class for graphical elements stored in a glyph layer.
- [`GSComponent`](/Core/GlyphsCore/GSComponent) — A reference to another glyph placed as a shape in a glyph layer.
- [`GSShapeGroup`](/Core/GlyphsCore/GSShapeGroup) — A shape group combines zero or more shapes into a single shape, forming a shape tree.

