File: devguide-8.html

package info (click to toggle)
sketch 0.6.13-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 5,284 kB
  • ctags: 8,453
  • sloc: python: 34,711; ansic: 16,543; makefile: 83; sh: 26
file content (247 lines) | stat: -rw-r--r-- 9,188 bytes parent folder | download | duplicates (4)
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<html>
<head>
<title>Developer's Guide: Curve Objects
</title>
</head>
<body bgcolor=white text=black link=blue vlink=navy alink=red>
<TABLE WIDTH="100%">
<TR>
<TH ALIGN="left" WIDTH="33%"><img SRC="Images/arrow-left.png" WIDTH="16" HEIGHT="16" ALIGN="top" ALT="Prev"></TH>
<TH ALIGN="center" WIDTH="33%"><img SRC="Images/arrow-up.png" WIDTH="16" HEIGHT="16" ALIGN="top" ALT="Up"></TH>
<TH ALIGN="right" WIDTH="33%"><img SRC="Images/arrow-right.png" WIDTH="16" HEIGHT="16" ALIGN="top" ALT="Next"></TH>
</TR>
<TR>
<TD ALIGN="left"><A HREF="devguide-4.html">Coordinate Systems
</A></TD>
<TD ALIGN="center"><A HREF="devguide.html">Developer's Guide</A></TD>
<TD ALIGN="right"><A HREF="devguide-9.html">The Document and Graphics Classes</A></TD>
</TR>
</TABLE>
<HR NOSHADE>
<H1><FONT face="Helvetica,Arial"><A NAME="N1"></A>Curve Objects
</font></H1>

<P>A curve object represents a single continuous curve. A curve is a
sequence of segments with each segment starting at the end point of the
preceding segment (except the first segment, of which only the end point
is used as the start point of the second segment).</P>
<P>There are two kinds of segments, line segments and bezier segments.</P>
<P>A line segment is defined by its end point, p, and it defines a straight
line from the preceding segment's end point to p.</P>
<P>A bezier segment consists of an end point, p, and two auxiliary points,
p1 and p2. It defines a bezier curve starting at the preceding segment's
end point, approximating p1 and p2 and ending at p.</P>
<P>The end points of the segments are usually called <EM>nodes</EM>. There are
two special properties associated with them.</P>
<P>The first property is the <EM>continuity</EM>. The continuity can be
`angle', `smooth' or `symmetrical'. This results in constraints in the
editor when the user modifies a bezier object's auxiliary points:
<DL>
<DT><B>angle</B><DD>
<P>No constraint.</P>

<DT><B>smooth</B><DD>
<P>The node, the auxiliary points p2 of the node's segment, and p1
of the following segment must be collinear.</P>

<DT><B>symmetrical</B><DD>
<P>The node, the auxiliary points p2 of the node's segment, and p1
of the following segment must be collinear and the node is the
arithmetic mean of the two auxiliary points.</P>
</DL>
</P>
<P>The second property is only used during editing and has not effect on
the appearance of the curve. It is a flag that indicates whether the
node is selected or not.</P>
<P>Segments are numbered from zero, just like other sequences in Python.</P>



<H2><FONT face="Helvetica,Arial"><A NAME="N2"></A>Constructors</font></H2>

<P>
<DL>
<DT><B><A NAME="N3"></A><tt>CreatePath()</tt></B><DD>
<P>Return an empty curve object.</P>
</DL>
</P>

<H2><FONT face="Helvetica,Arial"><A NAME="N4"></A>Attributes</font></H2>

<P>
<DL>
<DT><B><CODE>len</CODE></B><DD>
<P>The number of segments. An empty curve has zero
length, a curve with just one node has length 1.</P>

<DT><B><CODE>closed</CODE></B><DD>
<P>True (1) if the curve is closed, false (0) 
otherwise. </P>
</DL>
</P>


<H2><FONT face="Helvetica,Arial"><A NAME="N5"></A>Methods</font></H2>


<H3><FONT face="Helvetica,Arial"><A NAME="N6"></A>Segment Construction</font></H3>

<P>When an empty curve has been created, segments can be appended using the
functions listed in this section. The first segment of a curve must be a
line segment.</P>
<P>
<DL>
<DT><B><A NAME="N7"></A><tt>AppendLine(<i>p</i>[, <i>cont</i>])</tt></B><DD>

<DT><B><tt>AppendLine(<i>x</i>, <i>y</i>[, <i>cont</i>])</tt></B><DD>
<P>Append a line segment to self. <i>p</i> must be a <A HREF="devguide-5.html#N11">PointSpec</A>.</P>
<P><i>cont</i> is the continuity at the end node and defaults to
<CODE>ContAngle</CODE>.</P>


<DT><B><A NAME="N8"></A><tt>AppendBezier(<i>p1</i>, <i>p2</i>, <i>p</i>[, <i>cont</i>])</tt></B><DD>

<DT><B><tt>AppendBezier(<i>x1</i>, <i>y1</i>, <i>x2</i>, <i>y2</i>,
<i>x</i>, <i>y</i>[, <i>cont</i>])</tt></B><DD>
<P>Append a bezier segment to self. <i>p</i>, <i>p1</i>, and <i>p2</i>
must be <A HREF="devguide-5.html#N11">PointSpecs</A>. The control points of
the bezier segment are the current end point of the curve,
<i>p1</i> and <i>p2</i> (which are only approximated) and <i>p</i>.</P>
<P><i>cont</i> is the continuity at the end node and defaults to
<CODE>ContAngle</CODE>. </P>


<DT><B><A NAME="N9"></A><tt>AppendSegment(CurveLine, (), <i>p</i>[, cont])</tt></B><DD>

<DT><B><tt>AppendSegment(CurveBezier, (<i>p1</i>, <i>p2</i>), <i>p</i>[,
<i>cont</i>])</tt></B><DD>
<P>Append a segment. If the first parameter is <CODE>CurveLine</CODE>, this
method is equivalent to <CODE>AppendLine(<i>p</i>, <i>cont</i>)</CODE>,
with <i>cont</i> defaulting to <CODE>ContAngle</CODE>.</P>
<P>If the first parameter is <CODE>CurveBezier</CODE>, this method is
equivalent to <CODE>AppendLine(<i>p1</i>, <i>p2</i>, <i>p</i>,
<i>cont</i>)</CODE>, with <i>cont</i> defaulting to <CODE>ContAngle</CODE>.</P>
<P>This method is mainly supplied as the opposite of the method
<A HREF="#N11"><tt>Segment</tt></A>.</P>

</DL>
</P>

<H3><FONT face="Helvetica,Arial"><A NAME="N10"></A>Querying the Curve Geometry</font></H3>

<P>The following methods usually take the index of a segment as argument.
This index counts from 0 to <CODE>len - 1</CODE>. If the index is negative it
counts from the end, just like for other sequences.</P>
<P>
<DL>
<DT><B><A NAME="N11"></A><tt>Segment(<i>i</i>)</tt></B><DD>
<P>Return the segment number <i>i</i> as a 4-tuple.</P>
<P>If the segment is a line segment the result is of the form:</P>
<P><CODE>(CurveLine, (), <i>p</i>, <i>cont</i>)</CODE></P>
<P>if it is a bezier segment the result has the form:</P>
<P><CODE>(CurveBezier, (<i>p1</i>, <i>p2</i>), <i>p</i>, <i>cont</i>)</CODE></P>
<P>The result is suitable as argument tuple to <A HREF="#N9"><tt>AppendSegment</tt></A>.</P>


<DT><B><tt>Node(<i>i</i>)</tt></B><DD>
<P>Return the <i>i</i>th node as a point object.</P>

<DT><B><tt>Continuity(<i>i</i>)</tt></B><DD>
<P>Return the continuity at node <i>i</i>. </P>

<DT><B><tt>SegmentType(<i>i</i>)</tt></B><DD>
<P>Return the type of the <i>i</i>th segment (either <CODE>CurveLine</CODE>
or <CODE>CurveBezier</CODE>). </P>

</DL>
</P>

<H3><FONT face="Helvetica,Arial"><A NAME="N12"></A>Modifying a Curve Object</font></H3>

<P>
<DL>
<DT><B><tt>SetLine(<i>i</i>, <i>p</i>[, <i>cont</i>])</tt></B><DD>

<DT><B><tt>SetLine(<i>i</i>, <i>x</i>, <i>y</i>[, <i>cont</i>])</tt></B><DD>
<P>Replace the <i>i</i>th segment by a line segment. The arguments
<i>p</i>, <i>x</i>, <i>y</i> and <i>cont</i> are used as in <A HREF="#N7"><tt>AppendLine</tt></A>.</P>


<DT><B><tt>SetBezier(<i>i</i>, <i>p1</i>, <i>p2</i>, <i>p</i>[, <i>cont</i>])</tt></B><DD>

<DT><B><tt>SetBezier(<i>i</i>, <i>x1</i>, <i>y1</i>, <i>x2</i>, <i>y2</i>,
<i>x</i>, <i>y</i>[, <i>cont</i>])</tt></B><DD>
<P>Replace the <i>i</i>th segment by a bezier segment. The rest of
the arguments are used as in <A HREF="#N8"><tt>AppendBezier</tt></A>.</P>


<DT><B><tt>SetSegment(<i>i</i>, CurveLine, (), <i>p</i>[, cont])</tt></B><DD>

<DT><B><tt>SetSegment(<i>i</i>, CurveBezier, (<i>p1</i>, <i>p2</i>), <i>p</i>[, <i>cont</i>])</tt></B><DD>
<P>Replace the <i>i</i>th segment by the segment described by the
rest of arguments, which are used as in <A HREF="#N9"><tt>AppendSegment</tt></A>.</P>


<DT><B><tt>ClosePath()</tt></B><DD>
<P>Close the curve.</P>


<DT><B><tt>Transform(<i>trafo</i>)</tt></B><DD>
<P>Apply the transformation <i>trafo</i> (a trafo object) to the
path. The path is modified in place.</P>


<DT><B><tt>Translate(<i>offset</i>)</tt></B><DD>
<P>Translate the path by offset, a point object. The path is
modified in place.</P>

</DL>
</P>


<H3><FONT face="Helvetica,Arial"><A NAME="N13"></A>Managing the Selection</font></H3>

<P>
<DL>
<DT><B><tt>SegmentSelected(<i>i</i>)</tt></B><DD>
<P>Return true (1) if the <i>i</i>th segment is selected, false (0)
otherwise. </P>

<DT><B><tt>SelectSegment(<i>i</i>, [<i>flag</i>])</tt></B><DD>
<P>Mark the <i>i</i>th segment as selected if <i>flag</i> is true and
as unselected otherwise. <i>flag</i> defaults to true.</P>
</DL>
</P>



<H2><FONT face="Helvetica,Arial"><A NAME="N14"></A>Constants</font></H2>

<P>
<DL>
<DT><B><CODE>ContAngle</CODE>, <CODE>ContSmooth</CODE>, <CODE>ContSymmetrical</CODE></B><DD>
<P>The values for the continuity property of the nodes.</P>

<DT><B><CODE>CurveLine</CODE>, <CODE>CurveBezier</CODE></B><DD>
<P>The two different segment types. Used for <A HREF="#N9"><tt>AppendSegment</tt></A> and <A HREF="#N11"><tt>Segment</tt></A>.</P>

</DL>
</P>


<HR NOSHADE>
<TABLE WIDTH="100%">
<TR>
<TD ALIGN="left"><A HREF="devguide-4.html">Coordinate Systems
</A></TD>
<TD ALIGN="center"><A HREF="devguide.html">Developer's Guide</A></TD>
<TD ALIGN="right"><A HREF="devguide-9.html">The Document and Graphics Classes</A></TD>
</TR>
<TR>
<TH ALIGN="left" WIDTH="33%"><img SRC="Images/arrow-left.png" WIDTH="16" HEIGHT="16" ALIGN="top" ALT="Prev"></TH>
<TH ALIGN="center" WIDTH="33%"><img SRC="Images/arrow-up.png" WIDTH="16" HEIGHT="16" ALIGN="top" ALT="Up"></TH>
<TH ALIGN="right" WIDTH="33%"><img SRC="Images/arrow-right.png" WIDTH="16" HEIGHT="16" ALIGN="top" ALT="Next"></TH>
</TR>
</TABLE>
</body>
</html>