Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > by-pkgid > 51f7de0838007e2876221e819c82d833 > files > 589

sketch-0.6.13-2mdk.ppc.rpm

<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>