Creates a line (more precisely, a line segment) between p0 and p1. The single connector between the two
Pointsis set to"--"and the data memberline_switch(of typebool) is set totrue. There are certain operations onPathsthat are only applicable to lines, so it's necessary to store the information that aPathis a line.1Point A(-2, -2.5, -1); Point B(3, 2, 2.5) Path p(A, B); p.show("p:"); -| p: (-2, -2.5, -1) -- (3, 2, 2.5);
![]()
Fig. 110.
Corresponds to the constructor above.
Point P0(1, 2, 3); Point P1(3.5, -12, 75); Path q; q.set(P0, P1); q.show("q:"); -| q: (1, 2, 3) -- (3.5, -12, 75);
For
Pathswith an arbitrary number ofPointsand one type of connector.connector is passed unchanged to
out_file, so it must be a valid connector in MetaPost.cycle indicates whether the
Pathis a cycle or not.cycle_switchis set to cycle. See Path Reference; Data Members. The filling and unfilling functions only work forPathsthat are cycles. See Path Reference; Drawing and Filling. If aPathis a cycle, it is up to the user to make sure that it has sensiblePointand connector values; 3DLDF doesn't check them. If they are not sensible, for instance, if thePathcrosses itself, and you try to fill it, this will cause an error in MetaPost. It is possible that aPathwill be “sensible” in some projections and not in others, although I have not tested this.p is a pointer to the first
Pointthat should go onto thePath. The ellipsis points (...) represent an arbitrary number of pointers toPointsthat should go onto thePath. The final argument must be0, which is interpreted by the C++ compiler as the null pointer.2It is admittedly a bit awkward to have to type “
&p0” rather than “p0”, and I have frequently forgotten to do it, which causes a compiler error, but all of the arguments must be pointers in order to be able to use 0 to indicate the end of the argument list. Convenience in typing function calls is not a high priority in 3DLDF, because once I've written an input routine, these function calls should be generated automatically. It will be more important to define a convenient syntax for the input routine.Point P0; Point P1(2); Point P2(2,2); Point P3(0,2); Path p("..", true, &P0, &P1, &P2, &P3, 0); p.draw();
![]()
Fig. 111.
Corresponds to the constructor above.
Point P[4]; P[0].set(2, 1, 3); P[3] = P[2] = P[1] = P[0]; P[3] *= P[2] *= P[1].rotate(3, 12, 18); P[3] *= P[2].shift(-2, -1, 3); P[3].shear(1.5, .5, 3.5); Path q("...", false, &P[0], &P[1], &P[2], &P[3], 0); q.show("q:"); -| q: (2, 1, 3) ... (0.92139, 1.51449, 3.29505) ... (-1.07861, 0.514487, 6.29505) ... (2.84065, -3.26065, 6.29505);
![]()
Fig. 112.
Constructor for
Pathswith an arbitrary number ofPointsand connectors. The first, required, argument is a pointer to aPoint, followed by pointers tocharalternating with pointers toPoints.3 The last argument must be 0, i.e., the null pointer.There is no need to indicate by means of an argument whether the
Pathis a cycle or not: If it is, the last argument before the 0 will be achar*(pointer tochar), if not, it will be aPoint*. The data membercycle_switch(of typebool) will be set totrueorfalseaccordingly.Point A; Point B(2, 0); Point C(3, 2); Point D(1, 3); Path p(&A, "..", &B, "..", &C, "--", &D, "...", 0);
![]()
Fig. 113.
Corresponds to the constructor above.
Pseudo-constructors for dynamic allocation of
Paths. They create aPathon the free store and allocate memory for it usingnew(Path). They return a pointer to the newPath.If p is a non-zero pointer or a reference, the new
Pathwill be a copy of p. If the new object is not meant to be a copy of an existing one, ‘0’ must be passed tocreate_new<Path>()as its argument. See Dynamic Allocation of Shapes, for more information.
create_new<Path>()is used in the drawing and filling functions for copying aPathand putting the copy onto aPicture. See Path Reference; Drawing and Filling.
[1] It isn't sufficient to check whether a
Path consists of only two Points to determine whether it
is a line or not, since a connector with “curl” could cause it
to be non-linear. On the other hand, Paths containing only
colinear Points and the connector "--" are perfectly
legitimate lines. I'm in the process of changing all of the code that
tests for linearity by checking the value of line_switch, so that
it uses is_linear() instead. When I've done this, it may be
possible to eliminate line_switch.
See Path Reference; Data Members, and
Path Reference; Querying.
[2] Stroustrup, The C++ Programming Language, p. 88.
[3] Where possible, I prefer to use the C++
data
type string rather than char*, however it was necessary to
use char* here because 0 is not a valid string, even
though string may be implemented as char*,
and 0 must be a valid argument, since it is needed to indicate the end
of the argument list.