GSPath Class Reference
| Inherits from | NSObject |
| Conforms to | NSCoding NSCopying |
Tasks
Other Methods
-
parentproperty -
closedproperty -
– initWithPathDict: -
– pathDict -
– nearestPointOnPath:pathTime: -
– insertNodeWithPathTime:
Nodes
-
nodesproperty -
– 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 -
segmentsproperty
Other Methods
Properties
parent
A pointer to the containing GSLayer object
@property (weak, nonatomic, nullable) GSLayer *parentsegments
Calculates a list of segments
@property (nonatomic, strong) NSArray *segmentsReturn 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)ForceParameters
- 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 *)NodeParameters
- Node
The node to add.
addNodeFast:
Adds the node without notifying the layer
- (void)addNodeFast:(GSNode *)NodeParameters
- 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)bezierPathReturn 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)boundsReturn 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)cleanUpDiscussion
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)countOfNodesReturn Value
The count of nodes in the path.
direction
The path direction
- (GSPathDirection)directionReturn 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)penParameters
- pen
A pen conforming to the GSPenProtocol
elementDidChange:
Is called from node objects if it has changed.
- (void)elementDidChange:(GSElement *)ElementParameters
- 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)endNodefastBounds
Returns the bounding box of the receiver’s path.
- (NSRect)fastBoundsReturn 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 *)NodeParameters
- 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 *)pathDictParameters
- 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)PathTimeParameters
- 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)IndexmakeNodeFirst:
Makes the Node the first in the path.
- (void)makeNodeFirst:(GSNode *)NodeParameters
- 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)PointParameters
- Point
A NSPoint
nearestPointOnPath:pathTime:
gives the nearest Point on the path
- (NSPoint)nearestPointOnPath:(NSPoint)aPoint pathTime:(out CGFloat *)PathTimeParameters
- 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)indexParameters
- 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 *)NodeParameters
- Node
The node to return from the path.
removeNodeCheck:
Removes Node.
- (void)removeNodeCheck:(GSNode *)NodeParameters
- 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 *)NodeParameters
- 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)IndexParameters
- Index
The index of the node to remove.
setClosePath:
Closes or opens the Path. If necessary it adds or removes points.
- (void)setClosePath:(BOOL)ClosedParameters
- Closed
A BOOL
startNode
For open paths, returns the first node of the path, otherwise nil.
- (GSNode *_Nullable)startNodetangentAngleAtNode:direction:
Calculates the angle of the tangent at the given node
- (CGFloat)tangentAngleAtNode:(GSNode *)Node direction:(int)DirectionParameters
- 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)DirectionParameters
- 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