pub struct Path { /* private fields */ }
v4_14
only.Expand description
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).
Path
is an immutable, opaque, reference-counted struct.
After creation, you cannot change the types it represents. Instead,
new Path
objects have to be created. The PathBuilder
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.
GLib type: Shared boxed type with reference counted clone semantics.
Implementations§
Source§impl Path
impl Path
Sourcepub fn bounds(&self) -> Option<Rect>
pub fn bounds(&self) -> Option<Rect>
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.
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 graphene_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.
§Returns
true if the path has bounds, false if the path is known to be empty and have no bounds
§bounds
return location for the bounds
Sourcepub fn closest_point(
&self,
point: &Point,
threshold: f32,
) -> Option<(PathPoint, f32)>
pub fn closest_point( &self, point: &Point, threshold: f32, ) -> Option<(PathPoint, f32)>
Computes the closest point on the path to the given point.
If there is no point closer than the given threshold, false is returned.
§point
the point
§threshold
maximum allowed distance
§Returns
true if @point was set to the closest point on @self, false if no point is closer than @threshold
§result
return location for the closest point
§distance
return location for the distance
Sourcepub fn start_point(&self) -> Option<PathPoint>
pub fn start_point(&self) -> Option<PathPoint>
Sourcepub fn stroke_bounds(&self, stroke: &Stroke) -> Option<Rect>
pub fn stroke_bounds(&self, stroke: &Stroke) -> Option<Rect>
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.
§stroke
stroke parameters
§Returns
true if the path has bounds, false if the path is known to be empty and have no bounds.
§bounds
the bounds to fill in
Sourcepub fn to_str(&self) -> GString
pub fn to_str(&self) -> GString
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 Gsk::Path::print()
, see that function
for details.
§Returns
a new string for @self
Sourcepub fn parse(string: &str) -> Result<Path, BoolError>
pub fn parse(string: &str) -> Result<Path, BoolError>
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 to_str()
.
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 pointH x
Add a horizontal line from the current point to the given x valueV y
Add a vertical line from the current point to the given y valueT x2 y2
Add a quadratic Bézier, using the reflection of the previous segments’ control point as control pointS x2 y2 x3 y3
Add a cubic Bézier, using the reflection of the previous segments’ second control point as first control pointA 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 weightw
.
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
a string
§Returns
a new Path
, or NULL
if @string could not be parsed
Source§impl Path
impl Path
Sourcepub fn foreach<P: FnMut(&PathOperation, &Point, usize, f32) -> ControlFlow>(
&self,
flags: PathForeachFlags,
func: P,
) -> ControlFlow
pub fn foreach<P: FnMut(&PathOperation, &Point, usize, f32) -> ControlFlow>( &self, flags: PathForeachFlags, func: P, ) -> ControlFlow
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.
§flags
flags to pass to the foreach function
§func
the function to call for operations
§Returns
false if @func returned false, true otherwise.
Trait Implementations§
Source§impl HasParamSpec for Path
impl HasParamSpec for Path
Source§impl Ord for Path
impl Ord for Path
Source§impl PartialOrd for Path
impl PartialOrd for Path
Source§impl StaticType for Path
impl StaticType for Path
Source§fn static_type() -> Type
fn static_type() -> Type
Self
.