GSPath Class Reference
Inherits from | NSObject |
Conforms to | NSCoding NSCopying |
Tasks
Other Methods
-
parent
property -
closed
property -
– initWithPathDict:
-
– pathDict
-
– nearestPointOnPath:pathTime:
-
– insertNodeWithPathTime:
Nodes
-
nodes
property -
– countOfNodes
-
– addNode:
-
– addNodeFast:
-
– insertObject:inNodesAtIndex:
-
– removeObjectFromNodesAtIndex:
-
– removeNode:
-
– removeNodeCheckKeepShape:
-
– removeNodeCheck:
-
– elementDidChange:
-
– findMinNode
-
– findStartNode
-
– makeNodeFirst:
-
– setClosePath:
-
– checkConnections
-
– nodeAtIndex:
-
– indexOfNode:
-
– endNode
-
– startNode
-
– direction
-
– reverse
-
– cleanUp
-
– undoManager
-
– glyph
-
– bounds
-
– fastBounds
-
– moveWithPoint:
-
– addExtremes:
-
– tangentAngleAtNode:direction:
-
– tangentAngleAtNodeAtIndex:direction:
-
– bezierPath
-
segments
property
Other Methods
Properties
parent
A pointer to the containing GSLayer object
@property (weak, nonatomic, nullable) GSLayer *parent
segments
Calculates a list of segments
@property (nonatomic, strong) NSArray *segments
Return Value
A NSArray containing NSArrays.
Discussion
This might simplify path operations in some cases
The array contains an array for each segment. The arrays contain 2 or 4 NSValue object. Call [Value pointValue]
to the the NSPoint object
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
drawInPen:
Draws the path using a pen conforming to the GSPenProtocol
- (void)drawInPen:(NSObject<GSPenProtocol> *_Nonnull)pen
Parameters
- pen
A pen conforming to the GSPenProtocol
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
endNode
For open paths, returns the last node of the path, otherwise nil
.
- (GSNode *_Nullable)endNode
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.
initWithPathDict:
initializes a path with a dictionary loaded from a pList.
- (instancetype)initWithPathDict:(NSDictionary *)pathDict
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.
moveWithPoint:
Moves the path by the offset given be Point.
- (void)moveWithPoint:(NSPoint)Point
Parameters
- Point
A NSPoint
nearestPointOnPath:pathTime:
gives the nearest Point on the path
- (NSPoint)nearestPointOnPath:(NSPoint)aPoint pathTime:(out CGFloat *)PathTime
Parameters
- aPoint
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.
setClosePath:
Closes or opens the Path. If necessary it adds or removes points.
- (void)setClosePath:(BOOL)Closed
Parameters
- Closed
A BOOL
startNode
For open paths, returns the first node of the path, otherwise nil
.
- (GSNode *_Nullable)startNode
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