-
Notifications
You must be signed in to change notification settings - Fork 4
/
NSBezierPath+Geometry.h
186 lines (137 loc) · 7.21 KB
/
NSBezierPath+Geometry.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
///**********************************************************************************************************************************
/// NSBezierPath-Geometry.h
/// DrawKit ©2005-2008 Apptree.net
///
/// Created by graham on 22/10/2006.
///
/// This software is released subject to licensing conditions as detailed in DRAWKIT-LICENSING.TXT, which must accompany this source file.
///
///**********************************************************************************************************************************
#import <Cocoa/Cocoa.h>
@interface NSBezierPath (Geometry)
// simple transformations
- (NSBezierPath*) scaledPath:(float) scale;
- (NSBezierPath*) scaledPath:(float) scale aboutPoint:(NSPoint) cp;
- (NSBezierPath*) rotatedPath:(float) angle;
- (NSBezierPath*) rotatedPath:(float) angle aboutPoint:(NSPoint) cp;
- (NSBezierPath*) insetPathBy:(float) amount;
- (NSBezierPath*) horizontallyFlippedPathAboutPoint:(NSPoint) cp;
- (NSBezierPath*) verticallyFlippedPathAboutPoint:(NSPoint) cp;
- (NSBezierPath*) horizontallyFlippedPath;
- (NSBezierPath*) verticallyFlippedPath;
- (NSPoint) centreOfBounds;
- (float) minimumCornerAngle;
// iterating over a path using a iteration delegate:
- (NSBezierPath*) bezierPathByIteratingWithDelegate:(id) delegate contextInfo:(void*) contextInfo;
- (NSBezierPath*) paralleloidPathWithOffset:(float) delta;
- (NSBezierPath*) paralleloidPathWithOffset2:(float) delta;
- (NSBezierPath*) paralleloidPathWithOffset22:(float) delta;
- (NSBezierPath*) offsetPathWithStartingOffset:(float) delta1 endingOffset:(float) delta2;
- (NSBezierPath*) offsetPathWithStartingOffset2:(float) delta1 endingOffset:(float) delta2;
// interpolating flattened paths:
- (NSBezierPath*) bezierPathByInterpolatingPath:(float) amount;
// calculating a fillet
- (NSBezierPath*) filletPathForVertex:(NSPoint[]) vp filletSize:(float) fs;
// roughening and randomising paths
- (NSBezierPath*) bezierPathByRandomisingPoints:(float) maxAmount;
#if 0
- (NSBezierPath*) bezierPathWithRoughenedStrokeOutline:(float) amount;
#endif
- (NSBezierPath*) bezierPathWithFragmentedLineSegments:(float) flatness;
// zig-zags and waves
- (NSBezierPath*) bezierPathWithZig:(float) zig zag:(float) zag;
- (NSBezierPath*) bezierPathWithWavelength:(float) lambda amplitude:(float) amp spread:(float) spread;
// getting the outline of a stroked path:
#if 0
- (NSBezierPath*) strokedPath;
- (NSBezierPath*) strokedPathWithStrokeWidth:(float) width;
#endif
// breaking a path apart:
- (NSArray*) subPaths;
- (int) countSubPaths;
// converting to and from Core Graphics paths
#if 0
- (CGPathRef) newQuartzPath;
- (CGMutablePathRef) newMutableQuartzPath;
- (CGContextRef) setQuartzPath;
- (void) setQuartzPathInContext:(CGContextRef) context isNewPath:(BOOL) np;
+ (NSBezierPath*) bezierPathWithCGPath:(CGPathRef) path;
+ (NSBezierPath*) bezierPathWithPathFromContext:(CGContextRef) context;
#endif
- (NSPoint) pointOnPathAtLength:(float) length slope:(float*) slope;
- (float) slopeStartingPath;
- (float) distanceFromStartOfPathAtPoint:(NSPoint) p tolerance:(float) tol;
- (int) pointWithinPathRegion:(NSPoint) p;
// clipping utilities:
#if 0
- (void) addInverseClip;
#endif
// path trimming
- (float) lengthOfElement:(int) i;
- (float) lengthOfPathFromElement:(int) startElement toElement:(int) endElement;
- (NSPoint) firstPoint;
- (NSPoint) lastPoint;
// trimming utilities - modified source originally from A J Houghton, see copyright notice below
- (NSBezierPath*) bezierPathByTrimmingToLength:(float) trimLength;
- (NSBezierPath*) bezierPathByTrimmingToLength:(float) trimLength withMaximumError:(float) maxError;
- (NSBezierPath*) bezierPathByTrimmingFromLength:(float) trimLength;
- (NSBezierPath*) bezierPathByTrimmingFromLength:(float) trimLength withMaximumError:(float) maxError;
- (NSBezierPath*) bezierPathByTrimmingFromBothEnds:(float) trimLength;
- (NSBezierPath*) bezierPathByTrimmingFromBothEnds:(float) trimLength withMaximumError:(float) maxError;
- (NSBezierPath*) bezierPathByTrimmingFromCentre:(float) trimLength;
- (NSBezierPath*) bezierPathByTrimmingFromCentre:(float) trimLength withMaximumError:(float) maxError;
- (NSBezierPath*) bezierPathByTrimmingFromLength:(float) startLength toLength:(float) newLength;
- (NSBezierPath*) bezierPathByTrimmingFromLength:(float) startLength toLength:(float) newLength withMaximumError:(float) maxError;
- (NSBezierPath*) bezierPathWithArrowHeadForStartOfLength:(float) length angle:(float) angle closingPath:(BOOL) closeit;
- (NSBezierPath*) bezierPathWithArrowHeadForEndOfLength:(float)length angle:(float) angle closingPath:(BOOL) closeit;
- (void) appendBezierPathRemovingInitialMoveToPoint:(NSBezierPath*) path;
- (float) length;
- (float) lengthWithMaximumError:(float) maxError;
@end
// informal protocol for iterating over the elements in a bezier path using bezierPathByIteratingWithDelegate:contextInfo:
@interface NSObject (BezierElementIterationDelegate)
- (void) path:(NSBezierPath*) path // the new path that the delegate can build or modify from the information given
elementIndex:(int) element // the element index
type:(NSBezierPathElement) type // the element type
points:(NSPoint*) p // list of associated points 0 = next point, 1 = cp1, 2 = cp2 (for curves), 3 = last point on subpath
subPathIndex:(int) spi // which subpath this is
subPathClosed:(BOOL) spClosed // is the subpath closed?
contextInfo:(void*) contextInfo; // the context info
@end
// undocumented Core Graphics:
#if 0
extern CGPathRef CGContextCopyPath( CGContextRef context );
#endif
/*
* Bezier path utility category (trimming)
*
* (c) 2004 Alastair J. Houghton
* All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. The name of the author of this software may not be used to endorse
* or promote products derived from the software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY DIRECT, INDIRECT,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
void subdivideBezierAtT(const NSPoint bez[4], NSPoint bez1[4], NSPoint bez2[4], float t);