GSPath Class Reference
Inherits from | GSShape : NSObject |
Conforms to | GSContainerProtocol |
Declared in | GSPath.h |
Tasks
Other Methods
closed
– initWithDict:format:
– saveToFile:format:compact:error:
– nearestPointOnPath:pathTime:
– insertNodeWithPathTime:
Nodes
nodes
– countOfNodes
– addNode:
– addNodeFast:
– insertObject:inNodesAtIndex:
– removeObjectFromNodesAtIndex:
– removeNode:
– removeNodeCheckKeepShape:
– removeNodeCheck:
– elementDidChange:
– findMinNode
– findStartNode
– makeNodeFirst:
– setClosePath:
– checkConnections
– nodeAtIndex:
– indexOfNode:
startNode
endNode
– direction
– reverse
– cleanUp
– bounds
– fastBounds
– addExtremes:
– tangentAngleAtNode:direction:
– tangentAngleAtNodeAtIndex:direction:
– bezierPath
segments
Properties
endNode
For open paths, returns the last node of the path, otherwise
nil
.
@property (nonatomic, readonly, nullable) GSNode
*endNode
segments
Calculates a list of segments
@property (nonatomic, strong) NSArray<GSPathSegment*>
*segments
Return Value
A NSArray containing GSPathSegment.
Discussion
This might simplify path operations in some cases
Instance Methods
addExtremes:
Adds extremes to the path.
- (void)addExtremes:(BOOL)force
Parameters
- force
-
Determines if it adds nodes even if there is not enough space and it would add a bump.
Discussion
If there is a node closed to actual extreme, it will try to move it. If Force is not set, it does not add extremes if there is not enough space
addNode:
Adds the node to the end of the paths array.
- (void)addNode:(GSNode *)node
Parameters
- node
-
The node to add.
addNodeFast:
Adds the node without notifying the layer
- (void)addNodeFast:(GSNode *)node
Parameters
- node
-
The node to add.
Discussion
You need to make sure that the layer is notified
bezierPath
Calculates a bezier path representing the path.
- (NSBezierPath *_Nullable)bezierPath
Return Value
A NSBezierPath representing the path.
Discussion
This is a bit expensive call so you might cache the result.
is is probably better to get the bezier path from the layer
bounds
Returns the bounding box of the receiver’s path.
- (NSRect)bounds
Return Value
The rectangle that encloses the path of the receiver. If the path contains curve segments, the bounding box encloses the curve but may not enclose the control points used to calculate the curve.
cleanUp
Cleans up the Path
- (void)cleanUp
Discussion
Removes empty line segments
Converts flat curves into line
Rounds coordinates to the gridLenth specified in the font
countOfNodes
Returns the count of nodes in the path.
- (NSUInteger)countOfNodes
Return Value
The count of nodes in the path.
direction
The path direction
- (GSPathDirection)direction
Return Value
-1 for counter clock wise and 1 for clock wise
elementDidChange:
Is called from node objects if it has changed.
- (void)elementDidChange:(GSElement *)element
Parameters
- element
-
A GSNode object
Discussion
This triggers the update of the interface
fastBounds
Returns the bounding box of the receiver’s path.
- (NSRect)fastBounds
Return Value
The rectangle that encloses the path of the receiver. If the path contains curve segments, the bounding box encloses control points.
Discussion
It only calculates the bounds from the control points. This is usually to big for curves
indexOfNode:
Returns the index of the Node in nodes.
- (NSUInteger)indexOfNode:(GSNode *)node
Parameters
- node
-
A GSNode object
Return Value
The index of the node in the path.
initWithDict:format:
Initializes a path with a dictionary loaded from a pList.
- (instancetype)initWithDict:(NSDictionary
*)pathDict
format:(GSFormatVersion)formatVersion
Parameters
- pathDict
-
A dictionary
insertNodeWithPathTime:
Tests if pt lays on the path and than inserts a new point and corrects the handles of the other points to preserve the paths appearance.
- (GSNode
*_Nullable)insertNodeWithPathTime:(CGFloat)pathTime
Parameters
- pathTime
-
the “path time” the integer part is the Index of the next on-curve point. The fractional digits contain the time to the point.
Return Value
If the new point object, or nil if something went wrong.
insertObject:inNodesAtIndex:
Inserts a Node at the Index into nodes.
- (void)insertObject:(GSNode *)node
inNodesAtIndex:(NSInteger)index
makeNodeFirst:
Makes the Node the first in the path.
- (void)makeNodeFirst:(GSNode *)node
Parameters
- node
-
The node that should be the starting node.
Discussion
It checks if the node is in the path. If not, it makes nothing.
nearestPointOnPath:pathTime:
Gives the nearest Point on the path
- (NSPoint)nearestPointOnPath:(NSPoint)loc
pathTime:(out CGFloat *)pathTime
Parameters
- loc
-
the point
- pathTime
-
On return the “path time” on reference. The integer part is the Index of the next on-curve point. The fractional digits contain the time to the point.
Return Value
the Point on the path
nodeAtIndex:
Returns the GSNode located at Index.
- (GSNode
*_Nullable)nodeAtIndex:(NSInteger)index
Parameters
- index
-
An index.
Return Value
A GSNode object.
Discussion
The Index is corrected for overflow and underflow. Index = -1 retunes the last node…
removeNode:
Removes Node from path.
- (void)removeNode:(GSNode *)node
Parameters
- node
-
The node to return from the path.
removeNodeCheck:
Removes Node.
- (void)removeNodeCheck:(GSNode *)node
Parameters
- node
-
The node to return from the path.
Discussion
If Node is a off-curve node, it removes the second off-curve node and sets the segment to LINE.
removeNodeCheckKeepShape:
Removes Node and tries to keep the shape of the path.
- (BOOL)removeNodeCheckKeepShape:(GSNode
*)node
Parameters
- node
-
The node to return from the path.
Discussion
e.g. If Node is a off-curve node, it removes the second off-curve node and sets the segment to LINE.
removeObjectFromNodesAtIndex:
Removes the point at Index from the path.
-
(void)removeObjectFromNodesAtIndex:(NSInteger)index
Parameters
- index
-
The index of the node to remove.
saveToFile:format:compact:error:
Description
- (BOOL)saveToFile:(FILE *)file
format:(GSFormatVersion)formatVersion
compact:(BOOL)compact error:(NSError
**)error
Parameters
- file
-
Nullable for testing purposes.
- formatVersion
-
formatVersion
- compact
-
use shorter representaion
- error
-
error
Return Value
return value description
setClosePath:
Closes or opens the Path. If necessary it adds or removes points.
- (void)setClosePath:(BOOL)closed
Parameters
- closed
-
A BOOL
tangentAngleAtNode:direction:
Calculates the angle of the tangent at the given node
- (CGFloat)tangentAngleAtNode:(GSNode *)node
direction:(int)direction
Parameters
- node
-
The node where to calculate the angle
- direction
-
-1 for the angle to the previous node, 1 of the next node
Return Value
the angle in degrees
tangentAngleAtNodeAtIndex:direction:
Calculates the angle of the tangent at the node at the given Index
-
(CGFloat)tangentAngleAtNodeAtIndex:(NSInteger)index
direction:(int)direction
Parameters
- index
-
The index of the node where to calculate the angle
- direction
-
-1 for the angle to the previous node, 1 of the next node
Return Value
the angle in degrees