A path is a line going through a set of points. There are two kinds
of paths:
poly Straight line segments connect the points smooth A smooth (curved) line connects the points
The line of a path has a graphical->texture
and a graphical->pen
(thickness). The first and last point of the path may be connected (path->closed)
and the interior of the path may be filled with a colour using
path->fill.
Class path is a
subclass of class joint
and therefore may have joint->arrows
attached.
How the path gets to a point is determined by the class of the point. A plain point is reached by a straight line. The following subclasses of class point describe other segments, using the same vocabulary as Cairo and SVG paths:
curve_point A quadratic or cubic Bezier curve arc_point An elliptical arc (as SVG A) move_point No line: start a new sub-path
For example, a closed shape that is a half circle on top of a rectangle:
new(P, path),
send_list(P, append, [ point(0,40), arc_point(80,40, 40),
point(80,100), point(0,100) ]),
send(P, closed, @on),
send(P, fill, colour(skyblue)).
Paths can be used for numerous purposes:
->kind:
smooth may be used for simple smoothing of the diagram, while path->mark
may be used to mark the
control-points.
<-closed
says otherwise.
Defaults: @off
|gradient|image|{foreground,background}*<-fill_rule.
Defaults: @nil (not filled)
winding, a point is inside if
the path goes around it more often in one direction than in the other.
Using even_odd, a point is inside if a ray from it crosses
the path an odd number of times. The difference shows for a sub-path
inside another one, drawn the same way round: with
even_odd it is a hole. The rule is also used by path->inside
and for selecting a filled path with the mouse.
Defaults: winding
smooth, this is a chain of interpolated
points. The interpolation is recomputed each time the path has been
modified and needs to be painted. See also graphical->request_compute.
Defaults: Resource defined (10).
<->intervals
and the
chain object holding
all interpolated points is available in
path<-interpolation.
Defaults: poly (line segments).
Defaults: @nil
<-points
of the path if the path is painted. See also
path->reference and path->relative_move.smooth paths. The send-method validates and possibly
converts all members of the argument chain to be instances of class point
and raises the error unexpected_type on failure. On
successs, it replaces the path<-points
chain of the path with the argument. The argument thus becomes a part of
the path object. See
also path->initialise.poly lines. Only corners
between two straight segments are rounded. If the segments are too
short, the radius is reduced such that each corner uses at most half of
a segment.
Defaults: 0 (non-rounded corners).
<-device
coordinate system. path->insert
may be used to insert points in the middle or prepend points.
<-area
from the path<-points
and path<-interpolation
from path<-points
if
path<-kind
= smooth.<-point.->resize.<-kind.
When path<-kind
equals smooth, the second argument specifies the path<-intervals.
If the
points arguments is supplied, the method path->points
is invoked using this argument to specify the initial set of
control-points.<-segment
may be used to find the point to insert after.
<-device
coordinate system — lies inside the area the path encloses, as
determined by
path<-fill_rule.
Each sub-path is implicitly closed, so path<-closed
is not consulted: an open polygon can still be probed as a closed region
for hit-testing purposes. For smooth paths the test is performed against
the interpolated poly-line. Fails silently when the path has fewer than
two points.
Companion to graphical->in_event_area,
which combines this test with a near-outline distance test to make edge
hits work on closed paths as well as open ones.
d attribute of an SVG <path>
element. All commands (M, L, H, V, C, S, Q, T, A
and Z, absolute and relative) are supported. Sets path<-kind
to poly and path<-closed
to whether the first sub-path is closed. Fails with a syntax error if
the data is not valid.
send(P, svg_data, "M10 80 Q 52.5 10, 95 80 T 180 80").
<-offset
(default) or by adjusting each of the
path<-points.<-device’s
coordinate system.
|event|graphical -> int<-position
is used), compute the distance of this point to the path-line. If the
path is interpolated, the distance to the interpolation is computed.
If the argument is a graphical, use graphical<-distance.
See also line<-distance
and graphical->in_event_area.
<-device
coordinate system) of the last point of the path. See also path<-start.
|event,
max_distance=[int] -> pointSee also path<-segment.
Defaults: The default maximum distance (2nd argument) is 10.
Diagnostics: Fails silently if no such point exist.
|event,
accept=[0..] -> point<-position.
May be used to interactively
path->insert
new points:
send(Path, click_gesture(left, '', single,
message(@receiver, insert,
?(@event, position, @receiver?device),
?(@receiver, segment, @event)))).
See also path<-point.
->svg_data.<-end.