2.4 <GskPath>

Structure: <GskPath>

Describes lines and curves that are more complex than simple rectangles.

Paths can used for rendering (filling or stroking) and for animations (e.g. as trajectories).

<GskPath> is an immutable, opaque, reference-counted struct. After creation, you cannot change the types it represents. Instead, new <GskPath> objects have to be created. The <GskPathBuilder> structure is meant to help in this endeavor.

Conceptually, a path consists of zero or more contours (continuous, connected curves), each of which may or may not be closed. Contours are typically constructed from Bézier segments.

Procedures

Method: path:equal? self path2 ⇒ %return
Method: equal? self path2 ⇒ %return

Returns whether two paths have identical structure.

Note that it is possible to construct paths that render identical even though they don’t have the same structure.

self

Passed: a <GskPath>.

a path

path2

Passed: a <GskPath>.

another path

%return

Returned: a boolean.

true if self and path2 have identical structure

Method: path:foreach-intersection? self path2 func ⇒ %return
Method: foreach-intersection? self path2 func ⇒ %return

Finds intersections between two paths.

This function finds intersections between self and path2, and calls func for each of them, in increasing order for self.

If path2 is not provided or equal to self, the function finds non-trivial self-intersections of self.

When segments of the paths coincide, the callback is called once for the start of the segment, with GSK-PATH-INTERSECTION-START, and once for the end of the segment, with GSK-PATH-INTERSECTION-END. Note that other intersections may occur between the start and end of such a segment.

If func returns FALSE, the iteration is stopped.

self

Passed: a <GskPath>.

the first path

path2

Passed: a <GskPath>, or #f.

the second path

func

Passed: a procedure.

the function to call for intersections

See GskPathIntersectionFunc for how it is called.

%return

Returned: a boolean.

FALSE if func returned FALSE‘, TRUE otherwise.

user-data

Not passed: guile-gi supplies it.

user data passed to func

Method: path:foreach? self flags func ⇒ %return
Method: foreach? self flags func ⇒ %return

Calls func for every operation of the path.

Note that this may only approximate self, because paths can contain optimizations for various specialized contours, and depending on the flags, the path may be decomposed into simpler curves than the ones that it contained originally.

This function serves two purposes:

  • When the flags allow everything, it provides access to the raw, unmodified data of the path.
  • When the flags disallow certain operations, it provides an approximation of the path using just the allowed operations.
self

Passed: a <GskPath>.

a path

flags

Passed: a <GskPathForeachFlags>, or a list of its symbols, or one of them.

flags to pass to the foreach function

func

Passed: a procedure.

the function to call for operations

See GskPathForeachFunc for how it is called.

%return

Returned: a boolean.

false if func returned false, true otherwise.

user-data

Not passed: guile-gi supplies it.

user data passed to func

Method: path:get-bounds! self bounds ⇒ %return bounds
Method: get-bounds! self bounds ⇒ %return bounds

Computes the bounds of the given path.

The returned bounds may be larger than necessary, because this function aims to be fast, not accurate. The bounds are guaranteed to contain the path. For accurate bounds, use path:get-tight-bounds!.

It is possible that the returned rectangle has 0 width and/or height. This can happen when the path only describes a point or an axis-aligned line.

If the path is empty, false is returned and bounds are set to rect-zero. This is different from the case where the path is a single point at the origin, where the bounds will also be set to the zero rectangle but true will be returned.

self

Passed: a <GskPath>.

a path

bounds

Passed, filled in, and returned: a <GrapheneRect>.

return location for the bounds

%return

Returned: a boolean.

true if the path has bounds, false if the path is known to be empty and have no bounds

Method: path:get-closest-point! self point threshold result ⇒ %return result distance
Method: get-closest-point! self point threshold result ⇒ %return result distance

Computes the closest point on the path to the given point.

If there is no point closer than the given threshold, false is returned.

self

Passed: a <GskPath>.

a path

point

Passed: a <GraphenePoint>.

the point

threshold

Passed: a real number.

maximum allowed distance

result

Passed, filled in, and returned: a <GskPathPoint>.

return location for the closest point

%return

Returned: a boolean.

true if point was set to the closest point on self, false if no point is closer than threshold

distance

Returned: a real number.

return location for the distance

Method: path:get-end-point! self result ⇒ %return result
Method: get-end-point! self result ⇒ %return result

Gets the end point of the path.

An empty path has no points, so false is returned in this case.

self

Passed: a <GskPath>.

a path

result

Passed, filled in, and returned: a <GskPathPoint>.

return location for point

%return

Returned: a boolean.

true if result was filled

Method: path:get-next! self point ⇒ %return point
Method: get-next! self point ⇒ %return point

Moves point to the next vertex.

An empty path has no points, so false is returned in this case.

self

Passed: a <GskPath>.

a path

point

Passed, and returned: a <GskPathPoint>.

the current point

%return

Returned: a boolean.

true if point was set

Method: path:get-previous! self point ⇒ %return point
Method: get-previous! self point ⇒ %return point

Moves point to the previous vertex.

An empty path has no points, so false is returned in this case.

self

Passed: a <GskPath>.

a path

point

Passed, and returned: a <GskPathPoint>.

the current point

%return

Returned: a boolean.

true if point was set

Method: path:get-start-point! self result ⇒ %return result
Method: get-start-point! self result ⇒ %return result

Gets the start point of the path.

An empty path has no points, so false is returned in this case.

self

Passed: a <GskPath>.

a path

result

Passed, filled in, and returned: a <GskPathPoint>.

return location for point

%return

Returned: a boolean.

true if result was filled

Method: path:get-stroke-bounds! self stroke bounds ⇒ %return bounds
Method: get-stroke-bounds! self stroke bounds ⇒ %return bounds

Computes the bounds for stroking the given path with the given parameters.

The returned bounds may be larger than necessary, because this function aims to be fast, not accurate. The bounds are guaranteed to contain the area affected by the stroke, including protrusions like miters.

self

Passed: a <GskPath>.

a path

stroke

Passed: a <GskStroke>.

stroke parameters

bounds

Passed, filled in, and returned: a <GrapheneRect>.

the bounds to fill in

%return

Returned: a boolean.

true if the path has bounds, false if the path is known to be empty and have no bounds.

Method: path:get-tight-bounds! self bounds ⇒ %return bounds
Method: get-tight-bounds! self bounds ⇒ %return bounds

Computes the tight bounds of the given path.

This function works harder than path:get-bounds! to produce the smallest possible bounds.

self

Passed: a <GskPath>.

a path

bounds

Passed, filled in, and returned: a <GrapheneRect>.

return location for the bounds

%return

Returned: a boolean.

true if the path has bounds, false if the path is known to be empty and have no bounds

Method: path:in-fill? self point fill-rule ⇒ %return
Method: in-fill? self point fill-rule ⇒ %return

Returns whether a point is inside the fill area of a path.

Note that this function assumes that filling a contour implicitly closes it.

self

Passed: a <GskPath>.

a path

point

Passed: a <GraphenePoint>.

the point to test

fill-rule

Passed: a <GskFillRule>, or one of its symbols.

the fill rule to follow

%return

Returned: a boolean.

true if point is inside

Method: path:is-closed? self ⇒ %return
Method: is-closed? self ⇒ %return

Returns if the path represents a single closed contour.

self

Passed: a <GskPath>.

a path

%return

Returned: a boolean.

true if the path is closed

Method: path:is-empty? self ⇒ %return
Method: is-empty? self ⇒ %return

Checks if the path is empty, i.e. contains no lines or curves.

self

Passed: a <GskPath>.

a path

%return

Returned: a boolean.

true if the path is empty

Procedure: path:parse string ⇒ %return

Constructs a path from a serialized form.

The string is expected to be in (a superset of) SVG path syntax, as e.g. produced by path:to-string.

A high-level summary of the syntax:

  • M x y Move to (x, y)
  • L x y Add a line from the current point to (x, y)
  • Q x1 y1 x2 y2 Add a quadratic Bézier from the current point to (x2, y2), with control point (x1, y1)
  • C x1 y1 x2 y2 x3 y3 Add a cubic Bézier from the current point to (x3, y3), with control points (x1, y1) and (x2, y2)
  • Z Close the contour by drawing a line back to the start point
  • H x Add a horizontal line from the current point to the given x value
  • V y Add a vertical line from the current point to the given y value
  • T x2 y2 Add a quadratic Bézier, using the reflection of the previous segments’ control point as control point
  • S x2 y2 x3 y3 Add a cubic Bézier, using the reflection of the previous segments’ second control point as first control point
  • A rx ry r l s x y Add an elliptical arc from the current point to (x, y) with radii rx and ry. See the SVG documentation for how the other parameters influence the arc.
  • O x1 y1 x2 y2 w Add a rational quadratic Bézier from the current point to (x2, y2) with control point (x1, y1) and weight w.

All the commands have lowercase variants that interpret coordinates relative to the current point.

The O command is an extension that is not supported in SVG.

string

Passed: a string.

a string

%return

Returned: a <GskPath>, or #f.

a new <GskPath>, or NULL if string could not be parsed

Method: path:print self string
Method: print self string

Converts the path into a human-readable representation.

The string is compatible with (a superset of) SVG path syntax, see path:parse for a summary of the syntax.

self

Passed: a <GskPath>.

a path

string

Passed: a <GString>.

the string to print into

Method: path:ref self ⇒ %return
Method: ref self ⇒ %return

Increases the reference count of a path by one.

self

Passed: a <GskPath>.

a path

%return

Returned: a <GskPath>.

the passed in <GskPath>

Method: path:to-cairo self cr
Method: to-cairo self cr

Appends the path to a cairo context for drawing with Cairo.

This may cause some suboptimal conversions to be performed as Cairo does not support all features of <GskPath>.

This function does not clear the existing Cairo path. Call cairo_new_path() if you want this.

self

Passed: a <GskPath>.

a path

cr

Passed: a <CairoContext>.

a cairo context

Method: path:to-string self ⇒ %return
Method: to-string self ⇒ %return

Converts the path into a human-readable string.

You can use this function in a debugger to get a quick overview of the path.

This is a wrapper around path:print, see that function for details.

self

Passed: a <GskPath>.

a path

%return

Returned: a string.

a new string for self

Method: path:unref self
Method: unref self

Decreases the reference count of a path by one.

If the resulting reference count is zero, frees the path.

self

Passed: a <GskPath>.

a path