Type Alias freya_engine::prelude::Path

pub type Path = Handle<SkPath>;

Aliased Type§

struct Path(/* private fields */);

Implementations

§

impl Handle<SkPath>

Path contain geometry. Path may be empty, or contain one or more verbs that outline a figure. Path always starts with a move verb to a Cartesian coordinate, and may be followed by additional verbs that add lines or curves. Adding a close verb makes the geometry into a continuous loop, a closed contour. Path may contain any number of contours, each beginning with a move verb.

Path contours may contain only a move verb, or may also contain lines, quadratic beziers, conics, and cubic beziers. Path contours may be open or closed.

When used to draw a filled area, Path describes whether the fill is inside or outside the geometry. Path also describes the winding rule used to fill overlapping contours.

Internally, Path lazily computes metrics likes bounds and convexity. Call [Path::update_bounds_cache] to make Path thread safe.

pub fn new_from( points: &[Point], verbs: &[u8], conic_weights: &[f32], fill_type: SkPathFillType, is_volatile: impl Into<Option<bool>>, ) -> Handle<SkPath>

Create a new path with the specified segments.

The points and weights arrays are read in order, based on the sequence of verbs.

Move 1 point Line 1 point Quad 2 points Conic 2 points and 1 weight Cubic 3 points Close 0 points

If an illegal sequence of verbs is encountered, or the specified number of points or weights is not sufficient given the verbs, an empty Path is returned.

A legal sequence of verbs consists of any number of Contours. A contour always begins with a Move verb, followed by 0 or more segments: Line, Quad, Conic, Cubic, followed by an optional Close.

pub fn rect( rect: impl AsRef<Rect>, dir: impl Into<Option<SkPathDirection>>, ) -> Handle<SkPath>

pub fn oval( oval: impl AsRef<Rect>, dir: impl Into<Option<SkPathDirection>>, ) -> Handle<SkPath>

pub fn oval_with_start_index( oval: impl AsRef<Rect>, dir: SkPathDirection, start_index: usize, ) -> Handle<SkPath>

pub fn circle( center: impl Into<Point>, radius: f32, dir: impl Into<Option<SkPathDirection>>, ) -> Handle<SkPath>

pub fn rrect( rect: impl AsRef<RRect>, dir: impl Into<Option<SkPathDirection>>, ) -> Handle<SkPath>

pub fn rrect_with_start_index( rect: impl AsRef<RRect>, dir: SkPathDirection, start_index: usize, ) -> Handle<SkPath>

pub fn polygon( pts: &[Point], is_closed: bool, fill_type: impl Into<Option<SkPathFillType>>, is_volatile: impl Into<Option<bool>>, ) -> Handle<SkPath>

pub fn line(a: impl Into<Point>, b: impl Into<Point>) -> Handle<SkPath>

pub fn new() -> Handle<SkPath>

Constructs an empty Path. By default, Path has no verbs, no Point, and no weights. FillType is set to Winding.

Returns: empty Path

example: https://fiddle.skia.org/c/@Path_empty_constructor

pub fn snapshot(&self) -> Handle<SkPath>

Returns a copy of this path in the current state.

pub fn detach(&mut self) -> Handle<SkPath>

Returns a copy of this path in the current state, and resets the path to empty.

pub fn is_interpolatable(&self, compare: &Handle<SkPath>) -> bool

Returns true if Path contain equal verbs and equal weights. If Path contain one or more conics, the weights must match.

conic_to() may add different verbs depending on conic weight, so it is not trivial to interpolate a pair of Path containing conics with different conic weight values.

  • compare - Path to compare

Returns: true if Path verb array and weights are equivalent

example: https://fiddle.skia.org/c/@Path_isInterpolatable

pub fn interpolate( &self, ending: &Handle<SkPath>, weight: f32, ) -> Option<Handle<SkPath>>

Interpolates between Path with Point array of equal size. Copy verb array and weights to out, and set out Point array to a weighted average of this Point array and ending Point array, using the formula: (Path Point * weight) + ending Point * (1 - weight).

weight is most useful when between zero (ending Point array) and one (this Point_Array); will work with values outside of this range.

interpolate() returns false and leaves out unchanged if Point array is not the same size as ending Point array. Call is_interpolatable() to check Path compatibility prior to calling interpolate().

  • ending - Point array averaged with this Point array
  • weight - contribution of this Point array, and one minus contribution of ending Point array
  • out - Path replaced by interpolated averages

Returns: true if Path contain same number of Point

example: https://fiddle.skia.org/c/@Path_interpolate

pub fn fill_type(&self) -> SkPathFillType

Returns PathFillType, the rule used to fill Path.

Returns: current PathFillType setting

pub fn set_fill_type(&mut self, ft: SkPathFillType) -> &mut Handle<SkPath>

Sets FillType, the rule used to fill Path. While there is no check that ft is legal, values outside of FillType are not supported.

pub fn is_inverse_fill_type(&self) -> bool

Returns if FillType describes area outside Path geometry. The inverse fill area extends indefinitely.

Returns: true if FillType is InverseWinding or InverseEvenOdd

pub fn toggle_inverse_fill_type(&mut self) -> &mut Handle<SkPath>

Replaces FillType with its inverse. The inverse of FillType describes the area unmodified by the original FillType.

pub fn convexity_type(&self) -> !

👎Deprecated since 0.36.0: Removed, use is_convex()

pub fn convexity_type_or_unknown(&self) -> !

👎Deprecated since 0.36.0: Removed, use is_convex()

pub fn is_convex(&self) -> bool

Returns true if the path is convex. If necessary, it will first compute the convexity.

pub fn is_oval(&self) -> Option<Rect>

Returns true if this path is recognized as an oval or circle.

bounds receives bounds of oval.

bounds is unmodified if oval is not found.

  • bounds - storage for bounding Rect of oval; may be None

Returns: true if Path is recognized as an oval or circle

example: https://fiddle.skia.org/c/@Path_isOval

pub fn is_rrect(&self) -> Option<RRect>

Returns RRect if path is representable as RRect. Returns None if path is representable as oval, circle, or Rect.

Returns: RRect if Path contains only RRect

example: https://fiddle.skia.org/c/@Path_isRRect

pub fn is_arc(&self) -> Option<Arc>

Returns [Arc] if path is representable as an oval arc. In other words, could this path be drawn using Canvas::draw_arc().

Returns: [Arc] if Path contains only a single arc from an oval

pub fn reset(&mut self) -> &mut Handle<SkPath>

Sets Path to its initial state. Removes verb array, Point array, and weights, and sets FillType to Winding. Internal storage associated with Path is released.

Returns: reference to Path

example: https://fiddle.skia.org/c/@Path_reset

pub fn rewind(&mut self) -> &mut Handle<SkPath>

Sets Path to its initial state, preserving internal storage. Removes verb array, Point array, and weights, and sets FillType to Winding. Internal storage associated with Path is retained.

Use rewind() instead of reset() if Path storage will be reused and performance is critical.

Returns: reference to Path

example: https://fiddle.skia.org/c/@Path_rewind

pub fn is_empty(&self) -> bool

Returns if Path is empty. Empty Path may have FillType but has no Point, [Verb], or conic weight. [Path::default()] constructs empty Path; reset() and rewind() make Path empty.

Returns: true if the path contains no [Verb] array

pub fn is_last_contour_closed(&self) -> bool

Returns if contour is closed. Contour is closed if Path [Verb] array was last modified by close(). When stroked, closed contour draws [crate::paint::Join] instead of [crate::paint::Cap] at first and last Point.

Returns: true if the last contour ends with a [Verb::Close]

example: https://fiddle.skia.org/c/@Path_isLastContourClosed

pub fn is_finite(&self) -> bool

Returns true for finite Point array values between negative SK_ScalarMax and positive SK_ScalarMax. Returns false for any Point array value of SK_ScalarInfinity, SK_ScalarNegativeInfinity, or SK_ScalarNaN.

Returns: true if all Point values are finite

pub fn is_volatile(&self) -> bool

Returns true if the path is volatile; it will not be altered or discarded by the caller after it is drawn. Path by default have volatile set false, allowing crate::Surface to attach a cache of data which speeds repeated drawing. If true, crate::Surface may not speed repeated drawing.

Returns: true if caller will alter Path after drawing

pub fn set_is_volatile(&mut self, is_volatile: bool) -> &mut Handle<SkPath>

Specifies whether Path is volatile; whether it will be altered or discarded by the caller after it is drawn. Path by default have volatile set false, allowing Device to attach a cache of data which speeds repeated drawing.

Mark temporary paths, discarded or modified after use, as volatile to inform Device that the path need not be cached.

Mark animating Path volatile to improve performance. Mark unchanging Path non-volatile to improve repeated rendering.

raster surface Path draws are affected by volatile for some shadows. GPU surface Path draws are affected by volatile for some shadows and concave geometries.

  • is_volatile - true if caller will alter Path after drawing

Returns: reference to Path

pub fn is_line_degenerate( p1: impl Into<Point>, p2: impl Into<Point>, exact: bool, ) -> bool

Tests if line between Point pair is degenerate. Line with no length or that moves a very short distance is degenerate; it is treated as a point.

exact changes the equality test. If true, returns true only if p1 equals p2. If false, returns true if p1 equals or nearly equals p2.

  • p1 - line start point
  • p2 - line end point
  • exact - if false, allow nearly equals

Returns: true if line is degenerate; its length is effectively zero

example: https://fiddle.skia.org/c/@Path_IsLineDegenerate

pub fn is_quad_degenerate( p1: impl Into<Point>, p2: impl Into<Point>, p3: impl Into<Point>, exact: bool, ) -> bool

Tests if quad is degenerate. Quad with no length or that moves a very short distance is degenerate; it is treated as a point.

  • p1 - quad start point
  • p2 - quad control point
  • p3 - quad end point
  • exact - if true, returns true only if p1, p2, and p3 are equal; if false, returns true if p1, p2, and p3 are equal or nearly equal

Returns: true if quad is degenerate; its length is effectively zero

pub fn is_cubic_degenerate( p1: impl Into<Point>, p2: impl Into<Point>, p3: impl Into<Point>, p4: impl Into<Point>, exact: bool, ) -> bool

Tests if cubic is degenerate. Cubic with no length or that moves a very short distance is degenerate; it is treated as a point.

  • p1 - cubic start point
  • p2 - cubic control point 1
  • p3 - cubic control point 2
  • p4 - cubic end point
  • exact - if true, returns true only if p1, p2, p3, and p4 are equal; if false, returns true if p1, p2, p3, and p4 are equal or nearly equal

Returns: true if cubic is degenerate; its length is effectively zero

pub fn is_line(&self) -> Option<(Point, Point)>

Returns true if Path contains only one line; [Verb] array has two entries: [Verb::Move], [Verb::Line]. If Path contains one line and line is not None, line is set to line start point and line end point. Returns false if Path is not one line; line is unaltered.

  • line - storage for line. May be None

Returns: true if Path contains exactly one line

example: https://fiddle.skia.org/c/@Path_isLine

pub fn count_points(&self) -> usize

Returns the number of points in Path. Point count is initially zero.

Returns: Path Point array length

example: https://fiddle.skia.org/c/@Path_countPoints

pub fn get_point(&self, index: usize) -> Option<Point>

Returns Point at index in Point array. Valid range for index is 0 to count_points() - 1. Returns (0, 0) if index is out of range.

  • index - Point array element selector

Returns: Point array value or (0, 0)

example: https://fiddle.skia.org/c/@Path_getPoint

pub fn get_points(&self, points: &mut [Point]) -> usize

Returns number of points in Path. Up to max points are copied. points may be None; then, max must be zero. If max is greater than number of points, excess points storage is unaltered.

  • points - storage for Path Point array. May be None
  • max - maximum to copy; must be greater than or equal to zero

Returns: Path Point array length

example: https://fiddle.skia.org/c/@Path_getPoints

pub fn count_verbs(&self) -> usize

Returns the number of verbs: [Verb::Move], [Verb::Line], [Verb::Quad], [Verb::Conic], [Verb::Cubic], and [Verb::Close]; added to Path.

Returns: length of verb array

example: https://fiddle.skia.org/c/@Path_countVerbs

pub fn get_verbs(&self, verbs: &mut [u8]) -> usize

Returns the number of verbs in the path. Up to max verbs are copied. The verbs are copied as one byte per verb.

  • verbs - storage for verbs, may be None
  • max - maximum number to copy into verbs

Returns: the actual number of verbs in the path

example: https://fiddle.skia.org/c/@Path_getVerbs

pub fn approximate_bytes_used(&self) -> usize

Returns the approximate byte size of the Path in memory.

Returns: approximate size

pub fn swap(&mut self, other: &mut Handle<SkPath>) -> &mut Handle<SkPath>

Exchanges the verb array, Point array, weights, and FillType with other. Cached state is also exchanged. swap() internally exchanges pointers, so it is lightweight and does not allocate memory.

swap() usage has largely been replaced by PartialEq. Path do not copy their content on assignment until they are written to, making assignment as efficient as swap().

  • other - Path exchanged by value

example: https://fiddle.skia.org/c/@Path_swap

pub fn bounds(&self) -> &Rect

Returns minimum and maximum axes values of Point array. Returns (0, 0, 0, 0) if Path contains no points. Returned bounds width and height may be larger or smaller than area affected when Path is drawn.

Rect returned includes all Point added to Path, including Point associated with [Verb::Move] that define empty contours.

Returns: bounds of all Point in Point array

pub fn update_bounds_cache(&mut self) -> &mut Handle<SkPath>

Updates internal bounds so that subsequent calls to bounds() are instantaneous. Unaltered copies of Path may also access cached bounds through bounds().

For now, identical to calling bounds() and ignoring the returned value.

Call to prepare Path subsequently drawn from multiple threads, to avoid a race condition where each draw separately computes the bounds.

pub fn compute_tight_bounds(&self) -> Rect

Returns minimum and maximum axes values of the lines and curves in Path. Returns (0, 0, 0, 0) if Path contains no points. Returned bounds width and height may be larger or smaller than area affected when Path is drawn.

Includes Point associated with [Verb::Move] that define empty contours.

Behaves identically to bounds() when Path contains only lines. If Path contains curves, computed bounds includes the maximum extent of the quad, conic, or cubic; is slower than bounds(); and unlike bounds(), does not cache the result.

Returns: tight bounds of curves in Path

example: https://fiddle.skia.org/c/@Path_computeTightBounds

pub fn conservatively_contains_rect(&self, rect: impl AsRef<Rect>) -> bool

Returns true if rect is contained by Path. May return false when rect is contained by Path.

For now, only returns true if Path has one contour and is convex. rect may share points and edges with Path and be contained. Returns true if rect is empty, that is, it has zero width or height; and the Point or line described by rect is contained by Path.

  • rect - Rect, line, or Point checked for containment

Returns: true if rect is contained

example: https://fiddle.skia.org/c/@Path_conservativelyContainsRect

pub fn inc_reserve(&mut self, extra_pt_count: usize) -> &mut Handle<SkPath>

Grows Path verb array and Point array to contain extra_pt_count additional Point. May improve performance and use less memory by reducing the number and size of allocations when creating Path.

  • extra_pt_count - number of additional Point to allocate

example: https://fiddle.skia.org/c/@Path_incReserve

pub fn inc_reserve_with_verb_and_conic( &mut self, extra_pt_count: usize, extra_verb_count: impl Into<Option<usize>>, extract_conic_count: impl Into<Option<usize>>, ) -> &mut Handle<SkPath>

Grows Path verb array and Point array to contain extra_pt_count additional Point. May improve performance and use less memory by reducing the number and size of allocations when creating Path.

  • extra_pt_count - number of additional Point to allocate
  • extra_verb_count - number of additional verbs
  • extra_conic_count - number of additional conics

example: https://fiddle.skia.org/c/@Path_incReserve

pub fn shrink_to_fit(&mut self) -> !

👎Deprecated since 0.37.0: Removed without replacement

pub fn move_to(&mut self, p: impl Into<Point>) -> &mut Handle<SkPath>

Adds beginning of contour at Point (x, y).

  • x - x-axis value of contour start
  • y - y-axis value of contour start

Returns: reference to Path

example: https://fiddle.skia.org/c/@Path_moveTo

pub fn r_move_to(&mut self, d: impl Into<Point>) -> &mut Handle<SkPath>

Adds beginning of contour relative to last point. If Path is empty, starts contour at (dx, dy). Otherwise, start contour at last point offset by (dx, dy). Function name stands for “relative move to”.

  • dx - offset from last point to contour start on x-axis
  • dy - offset from last point to contour start on y-axis

Returns: reference to Path

example: https://fiddle.skia.org/c/@Path_rMoveTo

pub fn line_to(&mut self, p: impl Into<Point>) -> &mut Handle<SkPath>

Adds line from last point to (x, y). If Path is empty, or last [Verb] is [Verb::Close], last point is set to (0, 0) before adding line.

line_to() appends [Verb::Move] to verb array and (0, 0) to Point array, if needed. line_to() then appends [Verb::Line] to verb array and (x, y) to Point array.

  • x - end of added line on x-axis
  • y - end of added line on y-axis

Returns: reference to Path

example: https://fiddle.skia.org/c/@Path_lineTo

pub fn r_line_to(&mut self, d: impl Into<Point>) -> &mut Handle<SkPath>

Adds line from last point to vector (dx, dy). If Path is empty, or last [Verb] is [Verb::Close], last point is set to (0, 0) before adding line.

Appends [Verb::Move] to verb array and (0, 0) to Point array, if needed; then appends [Verb::Line] to verb array and line end to Point array. Line end is last point plus vector (dx, dy). Function name stands for “relative line to”.

  • dx - offset from last point to line end on x-axis
  • dy - offset from last point to line end on y-axis

Returns: reference to Path

example: https://fiddle.skia.org/c/@Path_rLineTo example: https://fiddle.skia.org/c/@Quad_a example: https://fiddle.skia.org/c/@Quad_b

pub fn quad_to( &mut self, p1: impl Into<Point>, p2: impl Into<Point>, ) -> &mut Handle<SkPath>

Adds quad from last point towards (x1, y1), to (x2, y2). If Path is empty, or last [Verb] is [Verb::Close], last point is set to (0, 0) before adding quad.

Appends [Verb::Move] to verb array and (0, 0) to Point array, if needed; then appends [Verb::Quad] to verb array; and (x1, y1), (x2, y2) to Point array.

  • x1 - control Point of quad on x-axis
  • y1 - control Point of quad on y-axis
  • x2 - end Point of quad on x-axis
  • y2 - end Point of quad on y-axis

Returns: reference to Path

example: https://fiddle.skia.org/c/@Path_quadTo

pub fn r_quad_to( &mut self, dx1: impl Into<Point>, dx2: impl Into<Point>, ) -> &mut Handle<SkPath>

Adds quad from last point towards vector (dx1, dy1), to vector (dx2, dy2). If Path is empty, or last [Verb] is [Verb::Close], last point is set to (0, 0) before adding quad.

Appends [Verb::Move] to verb array and (0, 0) to Point array, if needed; then appends [Verb::Quad] to verb array; and appends quad control and quad end to Point array. Quad control is last point plus vector (dx1, dy1). Quad end is last point plus vector (dx2, dy2). Function name stands for “relative quad to”.

  • dx1 - offset from last point to quad control on x-axis
  • dy1 - offset from last point to quad control on y-axis
  • dx2 - offset from last point to quad end on x-axis
  • dy2 - offset from last point to quad end on y-axis

Returns: reference to Path

example: https://fiddle.skia.org/c/@Conic_Weight_a example: https://fiddle.skia.org/c/@Conic_Weight_b example: https://fiddle.skia.org/c/@Conic_Weight_c example: https://fiddle.skia.org/c/@Path_rQuadTo

pub fn conic_to( &mut self, p1: impl Into<Point>, p2: impl Into<Point>, w: f32, ) -> &mut Handle<SkPath>

Adds conic from last point towards (x1, y1), to (x2, y2), weighted by w. If Path is empty, or last [Verb] is [Verb::Close], last point is set to (0, 0) before adding conic.

Appends [Verb::Move] to verb array and (0, 0) to Point array, if needed.

If w is finite and not one, appends [Verb::Conic] to verb array; and (x1, y1), (x2, y2) to Point array; and w to conic weights.

If w is one, appends [Verb::Quad] to verb array, and (x1, y1), (x2, y2) to Point array.

If w is not finite, appends [Verb::Line] twice to verb array, and (x1, y1), (x2, y2) to Point array.

  • x1 - control Point of conic on x-axis
  • y1 - control Point of conic on y-axis
  • x2 - end Point of conic on x-axis
  • y2 - end Point of conic on y-axis
  • w - weight of added conic

Returns: reference to Path

pub fn r_conic_to( &mut self, d1: impl Into<Point>, d2: impl Into<Point>, w: f32, ) -> &mut Handle<SkPath>

Adds conic from last point towards vector (dx1, dy1), to vector (dx2, dy2), weighted by w. If Path is empty, or last [Verb] is [Verb::Close], last point is set to (0, 0) before adding conic.

Appends [Verb::Move] to verb array and (0, 0) to Point array, if needed.

If w is finite and not one, next appends [Verb::Conic] to verb array, and w is recorded as conic weight; otherwise, if w is one, appends [Verb::Quad] to verb array; or if w is not finite, appends [Verb::Line] twice to verb array.

In all cases appends Point control and end to Point array. control is last point plus vector (dx1, dy1). end is last point plus vector (dx2, dy2).

Function name stands for “relative conic to”.

  • dx1 - offset from last point to conic control on x-axis
  • dy1 - offset from last point to conic control on y-axis
  • dx2 - offset from last point to conic end on x-axis
  • dy2 - offset from last point to conic end on y-axis
  • w - weight of added conic

Returns: reference to Path

pub fn cubic_to( &mut self, p1: impl Into<Point>, p2: impl Into<Point>, p3: impl Into<Point>, ) -> &mut Handle<SkPath>

Adds cubic from last point towards (x1, y1), then towards (x2, y2), ending at (x3, y3). If Path is empty, or last [Verb] is [Verb::Close], last point is set to (0, 0) before adding cubic.

Appends [Verb::Move] to verb array and (0, 0) to Point array, if needed; then appends [Verb::Cubic] to verb array; and (x1, y1), (x2, y2), (x3, y3) to Point array.

  • x1 - first control Point of cubic on x-axis
  • y1 - first control Point of cubic on y-axis
  • x2 - second control Point of cubic on x-axis
  • y2 - second control Point of cubic on y-axis
  • x3 - end Point of cubic on x-axis
  • y3 - end Point of cubic on y-axis

Returns: reference to Path

pub fn r_cubic_to( &mut self, d1: impl Into<Point>, d2: impl Into<Point>, d3: impl Into<Point>, ) -> &mut Handle<SkPath>

Adds cubic from last point towards vector (dx1, dy1), then towards vector (dx2, dy2), to vector (dx3, dy3). If Path is empty, or last [Verb] is [Verb::Close], last point is set to (0, 0) before adding cubic.

Appends [Verb::Move] to verb array and (0, 0) to Point array, if needed; then appends [Verb::Cubic] to verb array; and appends cubic control and cubic end to Point array. Cubic control is last point plus vector (dx1, dy1). Cubic end is last point plus vector (dx2, dy2). Function name stands for “relative cubic to”.

  • dx1 - offset from last point to first cubic control on x-axis
  • dy1 - offset from last point to first cubic control on y-axis
  • dx2 - offset from last point to second cubic control on x-axis
  • dy2 - offset from last point to second cubic control on y-axis
  • dx3 - offset from last point to cubic end on x-axis
  • dy3 - offset from last point to cubic end on y-axis

Returns: reference to Path

pub fn arc_to( &mut self, oval: impl AsRef<Rect>, start_angle: f32, sweep_angle: f32, force_move_to: bool, ) -> &mut Handle<SkPath>

Appends arc to Path. Arc added is part of ellipse bounded by oval, from start_angle through sweep_angle. Both start_angle and sweep_angle are measured in degrees, where zero degrees is aligned with the positive x-axis, and positive sweeps extends arc clockwise.

arc_to() adds line connecting Path last Point to initial arc Point if force_move_to is false and Path is not empty. Otherwise, added contour begins with first point of arc. Angles greater than -360 and less than 360 are treated modulo 360.

  • oval - bounds of ellipse containing arc
  • start_angle - starting angle of arc in degrees
  • sweep_angle - sweep, in degrees. Positive is clockwise; treated modulo 360
  • force_move_to - true to start a new contour with arc

Returns: reference to Path

example: https://fiddle.skia.org/c/@Path_arcTo

pub fn arc_to_tangent( &mut self, p1: impl Into<Point>, p2: impl Into<Point>, radius: f32, ) -> &mut Handle<SkPath>

Appends arc to Path, after appending line if needed. Arc is implemented by conic weighted to describe part of circle. Arc is contained by tangent from last Path point to (x1, y1), and tangent from (x1, y1) to (x2, y2). Arc is part of circle sized to radius, positioned so it touches both tangent lines.

If last Path Point does not start Arc, arc_to appends connecting Line to Path. The length of Vector from (x1, y1) to (x2, y2) does not affect Arc.

Arc sweep is always less than 180 degrees. If radius is zero, or if tangents are nearly parallel, arc_to appends Line from last Path Point to (x1, y1).

arc_to_tangent appends at most one Line and one conic. arc_to_tangent implements the functionality of PostScript arct and HTML Canvas arc_to.

  • p1.x - x-axis value common to pair of tangents
  • p1.y - y-axis value common to pair of tangents
  • p2.x - x-axis value end of second tangent
  • p2.y - y-axis value end of second tangent
  • radius - distance from arc to circle center

Returns: reference to Path

example: https://fiddle.skia.org/c/@Path_arcTo_2_a example: https://fiddle.skia.org/c/@Path_arcTo_2_b example: https://fiddle.skia.org/c/@Path_arcTo_2_c

pub fn arc_to_rotated( &mut self, r: impl Into<Point>, x_axis_rotate: f32, large_arc: SkPath_ArcSize, sweep: SkPathDirection, end: impl Into<Point>, ) -> &mut Handle<SkPath>

Appends arc to Path. Arc is implemented by one or more conics weighted to describe part of oval with radii (rx, ry) rotated by x_axis_rotate degrees. Arc curves from last Path Point to (x, y), choosing one of four possible routes: clockwise or counterclockwise, and smaller or larger.

Arc sweep is always less than 360 degrees. arc_to_rotated() appends line to (x, y) if either radii are zero, or if last Path Point equals (x, y). arc_to_rotated() scales radii (rx, ry) to fit last Path Point and (x, y) if both are greater than zero but too small.

arc_to_rotated() appends up to four conic curves. arc_to_rotated() implements the functionality of SVG arc, although SVG sweep-flag value is opposite the integer value of sweep; SVG sweep-flag uses 1 for clockwise, while Direction::CW cast to int is zero.

  • r.x - radius on x-axis before x-axis rotation
  • r.y - radius on y-axis before x-axis rotation
  • x_axis_rotate - x-axis rotation in degrees; positive values are clockwise
  • large_arc - chooses smaller or larger arc
  • sweep - chooses clockwise or counterclockwise arc
  • end.x - end of arc
  • end.y - end of arc

Returns: reference to Path

pub fn r_arc_to_rotated( &mut self, r: impl Into<Point>, x_axis_rotate: f32, large_arc: SkPath_ArcSize, sweep: SkPathDirection, d: impl Into<Point>, ) -> &mut Handle<SkPath>

Appends arc to Path, relative to last Path Point. Arc is implemented by one or more conic, weighted to describe part of oval with radii (r.x, r.y) rotated by x_axis_rotate degrees. Arc curves from last Path Point to relative end Point: (dx, dy), choosing one of four possible routes: clockwise or counterclockwise, and smaller or larger. If Path is empty, the start arc Point is (0, 0).

Arc sweep is always less than 360 degrees. arc_to() appends line to end Point if either radii are zero, or if last Path Point equals end Point. arc_to() scales radii (rx, ry) to fit last Path Point and end Point if both are greater than zero but too small to describe an arc.

arc_to() appends up to four conic curves. arc_to() implements the functionality of svg arc, although SVG “sweep-flag” value is opposite the integer value of sweep; SVG “sweep-flag” uses 1 for clockwise, while Direction::CW cast to int is zero.

  • r.x - radius before x-axis rotation
  • r.y - radius before x-axis rotation
  • x_axis_rotate - x-axis rotation in degrees; positive values are clockwise
  • large_arc - chooses smaller or larger arc
  • sweep - chooses clockwise or counterclockwise arc
  • d.x - x-axis offset end of arc from last Path Point
  • d.y - y-axis offset end of arc from last Path Point

Returns: reference to Path

pub fn close(&mut self) -> &mut Handle<SkPath>

Appends [Verb::Close] to Path. A closed contour connects the first and last Point with line, forming a continuous loop. Open and closed contour draw the same with fill style. With stroke style, open contour draws [crate::paint::Cap] at contour start and end; closed contour draws [crate::paint::Join] at contour start and end.

close() has no effect if Path is empty or last Path [Verb] is [Verb::Close].

Returns: reference to Path

example: https://fiddle.skia.org/c/@Path_close

pub fn convert_conic_to_quads( p0: impl Into<Point>, p1: impl Into<Point>, p2: impl Into<Point>, w: f32, pts: &mut [Point], pow2: usize, ) -> Option<usize>

Approximates conic with quad array. Conic is constructed from start Point p0, control Point p1, end Point p2, and weight w. Quad array is stored in pts; this storage is supplied by caller. Maximum quad count is 2 to the pow2. Every third point in array shares last Point of previous quad and first Point of next quad. Maximum pts storage size is given by: (1 + 2 * (1 << pow2)) * sizeof(Point).

Returns quad count used the approximation, which may be smaller than the number requested.

conic weight determines the amount of influence conic control point has on the curve. w less than one represents an elliptical section. w greater than one represents a hyperbolic section. w equal to one represents a parabolic section.

Two quad curves are sufficient to approximate an elliptical conic with a sweep of up to 90 degrees; in this case, set pow2 to one.

  • p0 - conic start Point
  • p1 - conic control Point
  • p2 - conic end Point
  • w - conic weight
  • pts - storage for quad array
  • pow2 - quad count, as power of two, normally 0 to 5 (1 to 32 quad curves)

Returns: number of quad curves written to pts

pub fn is_rect(&self) -> Option<(Rect, bool, SkPathDirection)>

Returns Some(Rect, bool, PathDirection) if Path is equivalent to Rect when filled. If false: rect, is_closed, and direction are unchanged. If true: rect, is_closed, and direction are written to.

rect may be smaller than the Path bounds. Path bounds may include [Verb::Move] points that do not alter the area drawn by the returned rect.

Returns: Some(rect, is_closed, direction) if Path contains Rect

  • rect - bounds of Rect
  • is_closed - set to true if Path is closed
  • direction - to Rect direction

example: https://fiddle.skia.org/c/@Path_isRect

pub fn add_rect( &mut self, rect: impl AsRef<Rect>, dir_start: Option<(SkPathDirection, usize)>, ) -> &mut Handle<SkPath>

Adds a new contour to the path, defined by the rect, and wound in the specified direction. The verbs added to the path will be:

Move, Line, Line, Line, Close

start specifies which corner to begin the contour: 0: upper-left corner 1: upper-right corner 2: lower-right corner 3: lower-left corner

This start point also acts as the implied beginning of the subsequent, contour, if it does not have an explicit move_to(). e.g.

path.add_rect(...) // if we don’t say move_to() here, we will use the rect’s start point path.line_to(…)`

  • rect - Rect to add as a closed contour
  • dir - Direction to orient the new contour
  • start - initial corner of Rect to add

Returns: reference to Path

example: https://fiddle.skia.org/c/@Path_addRect_2

pub fn add_oval( &mut self, oval: impl AsRef<Rect>, dir_start: Option<(SkPathDirection, usize)>, ) -> &mut Handle<SkPath>

Adds oval to Path, appending [Verb::Move], four [Verb::Conic], and [Verb::Close]. Oval is upright ellipse bounded by Rect oval with radii equal to half oval width and half oval height. Oval begins at start and continues clockwise if dir is Direction::CW, counterclockwise if dir is Direction::CCW.

  • oval - bounds of ellipse added
  • dir - Direction to wind ellipse
  • start - index of initial point of ellipse

Returns: reference to Path

example: https://fiddle.skia.org/c/@Path_addOval_2

pub fn add_circle( &mut self, p: impl Into<Point>, radius: f32, dir: impl Into<Option<SkPathDirection>>, ) -> &mut Handle<SkPath>

Adds circle centered at (x, y) of size radius to Path, appending [Verb::Move], four [Verb::Conic], and [Verb::Close]. Circle begins at: (x + radius, y), continuing clockwise if dir is Direction::CW, and counterclockwise if dir is Direction::CCW.

Has no effect if radius is zero or negative.

  • p - center of circle
  • radius - distance from center to edge
  • dir - Direction to wind circle

Returns: reference to Path

pub fn add_arc( &mut self, oval: impl AsRef<Rect>, start_angle: f32, sweep_angle: f32, ) -> &mut Handle<SkPath>

Appends arc to Path, as the start of new contour. Arc added is part of ellipse bounded by oval, from start_angle through sweep_angle. Both start_angle and sweep_angle are measured in degrees, where zero degrees is aligned with the positive x-axis, and positive sweeps extends arc clockwise.

If sweep_angle <= -360, or sweep_angle >= 360; and start_angle modulo 90 is nearly zero, append oval instead of arc. Otherwise, sweep_angle values are treated modulo 360, and arc may or may not draw depending on numeric rounding.

  • oval - bounds of ellipse containing arc
  • start_angle - starting angle of arc in degrees
  • sweep_angle - sweep, in degrees. Positive is clockwise; treated modulo 360

Returns: reference to Path

example: https://fiddle.skia.org/c/@Path_addArc

pub fn add_round_rect( &mut self, rect: impl AsRef<Rect>, _: (f32, f32), dir: impl Into<Option<SkPathDirection>>, ) -> &mut Handle<SkPath>

Appends RRect to Path, creating a new closed contour. RRect has bounds equal to rect; each corner is 90 degrees of an ellipse with radii (rx, ry). If dir is Direction::CW, RRect starts at top-left of the lower-left corner and winds clockwise. If dir is Direction::CCW, RRect starts at the bottom-left of the upper-left corner and winds counterclockwise.

If either rx or ry is too large, rx and ry are scaled uniformly until the corners fit. If rx or ry is less than or equal to zero, add_round_rect() appends Rect rect to Path.

After appending, Path may be empty, or may contain: Rect, oval, or RRect.

  • rect - bounds of RRect
  • rx - x-axis radius of rounded corners on the RRect
  • ry - y-axis radius of rounded corners on the RRect
  • dir - Direction to wind RRect

Returns: reference to Path

pub fn add_rrect( &mut self, rrect: impl AsRef<RRect>, dir_start: Option<(SkPathDirection, usize)>, ) -> &mut Handle<SkPath>

Adds rrect to Path, creating a new closed contour. If dir is Direction::CW, rrect winds clockwise; if dir is Direction::CCW, rrect winds counterclockwise. start determines the first point of rrect to add.

  • rrect - bounds and radii of rounded rectangle
  • dir - PathDirection to wind RRect
  • start - index of initial point of RRect

Returns: reference to Path

example: https://fiddle.skia.org/c/@Path_addRRect_2

pub fn add_poly(&mut self, pts: &[Point], close: bool) -> &mut Handle<SkPath>

Adds contour created from line array, adding pts.len() - 1 line segments. Contour added starts at pts[0], then adds a line for every additional Point in pts slice. If close is true, appends [Verb::Close] to Path, connecting pts[pts.len() - 1] and pts[0].

If count is zero, append [Verb::Move] to path. Has no effect if ps.len() is less than one.

  • pts - slice of line sharing end and start Point
  • close - true to add line connecting contour end and start

Returns: reference to Path

example: https://fiddle.skia.org/c/@Path_addPoly

pub fn add_path( &mut self, src: &Handle<SkPath>, d: impl Into<Point>, mode: impl Into<Option<SkPath_AddPathMode>>, ) -> &mut Handle<SkPath>

Appends src to Path, offset by (d.x, d.y).

If mode is [AddPathMode::Append], src verb array, Point array, and conic weights are added unaltered. If mode is [AddPathMode::Extend], add line before appending verbs, Point, and conic weights.

  • src - Path verbs, Point, and conic weights to add
  • d.x - offset added to src Point array x-axis coordinates
  • d.y - offset added to src Point array y-axis coordinates
  • mode - [AddPathMode::Append] or [AddPathMode::Extend]

Returns: reference to Path

pub fn add_path_matrix( &mut self, src: &Handle<SkPath>, matrix: &Matrix, mode: impl Into<Option<SkPath_AddPathMode>>, ) -> &mut Handle<SkPath>

Appends src to Path, transformed by matrix. Transformed curves may have different verbs, Point, and conic weights.

If mode is [AddPathMode::Append], src verb array, Point array, and conic weights are added unaltered. If mode is [AddPathMode::Extend], add line before appending verbs, Point, and conic weights.

  • src - Path verbs, Point, and conic weights to add
  • matrix - transform applied to src
  • mode - [AddPathMode::Append] or [AddPathMode::Extend]

Returns: reference to Path

pub fn reverse_add_path(&mut self, src: &Handle<SkPath>) -> &mut Handle<SkPath>

Appends src to Path, from back to front. Reversed src always appends a new contour to Path.

  • src - Path verbs, Point, and conic weights to add

Returns: reference to Path

example: https://fiddle.skia.org/c/@Path_reverseAddPath

pub fn with_offset(&self, d: impl Into<Point>) -> Handle<SkPath>

Offsets Point array by (d.x, d.y).

  • dx - offset added to Point array x-axis coordinates
  • dy - offset added to Point array y-axis coordinates

Returns: overwritten, translated copy of Path; may be None

example: https://fiddle.skia.org/c/@Path_offset

pub fn offset(&mut self, d: impl Into<Point>) -> &mut Handle<SkPath>

Offsets Point array by (d.x, d.y). Path is replaced by offset data.

  • d.x - offset added to Point array x-axis coordinates
  • d.y - offset added to Point array y-axis coordinates

pub fn with_transform(&self, matrix: &Matrix) -> Handle<SkPath>

Transforms verb array, Point array, and weight by matrix. transform may change verbs and increase their number.

example: https://fiddle.skia.org/c/@Path_transform

pub fn with_transform_with_perspective_clip( &self, matrix: &Matrix, perspective_clip: SkApplyPerspectiveClip, ) -> Handle<SkPath>

Transforms verb array, Point array, and weight by matrix. transform may change verbs and increase their number.

  • matrix - Matrix to apply to Path
  • pc - whether to apply perspective clipping

example: https://fiddle.skia.org/c/@Path_transform

pub fn transform(&mut self, matrix: &Matrix) -> &mut Handle<SkPath>

Transforms verb array, Point array, and weight by matrix. transform may change verbs and increase their number.

pub fn transform_with_perspective_clip( &mut self, matrix: &Matrix, pc: SkApplyPerspectiveClip, ) -> &mut Handle<SkPath>

Transforms verb array, Point array, and weight by matrix. transform may change verbs and increase their number.

  • matrix - Matrix to apply to Path
  • pc - whether to apply perspective clipping

pub fn make_transform( &mut self, m: &Matrix, pc: impl Into<Option<SkApplyPerspectiveClip>>, ) -> Handle<SkPath>

pub fn make_scale(&mut self, _: (f32, f32)) -> Handle<SkPath>

pub fn last_pt(&self) -> Option<Point>

Returns last point on Path. Returns None if Point array is empty, storing (0, 0) if last_pt is not None.

Returns final Point in Point array; may be None Returns: Some if Point array contains one or more Point

example: https://fiddle.skia.org/c/@Path_getLastPt

pub fn set_last_pt(&mut self, p: impl Into<Point>) -> &mut Handle<SkPath>

Sets the last point on the path. If Point array is empty, append [Verb::Move] to verb array and append p to Point array.

  • p - set value of last point

pub fn segment_masks(&self) -> PathSegmentMask

Returns a mask, where each set bit corresponds to a [SegmentMask] constant if Path contains one or more verbs of that type. Returns zero if Path contains no lines, or curves: quads, conics, or cubics.

segment_masks() returns a cached result; it is very fast.

Returns: [SegmentMask] bits or zero

pub fn contains(&self, p: impl Into<Point>) -> bool

Returns true if the point (p.x, p.y) is contained by Path, taking into account FillType.

  • p.x - x-axis value of containment test
  • p.y - y-axis value of containment test

Returns: true if Point is in Path

example: https://fiddle.skia.org/c/@Path_contains

pub fn dump_as_data(&self, dump_as_hex: bool) -> RCHandle<SkData>

Writes text representation of Path to Data. Set dump_as_hex true to generate exact binary representations of floating point numbers used in Point array and conic weights.

  • dump_as_hex - true if scalar values are written as hexadecimal

example: https://fiddle.skia.org/c/@Path_dump

pub fn dump(&self)

See [Path::dump_as_data()]

pub fn dump_hex(&self)

See [Path::dump_as_data()]

pub fn dump_arrays_as_data(&self, dump_as_hex: bool) -> RCHandle<SkData>

pub fn dump_arrays(&self)

pub fn serialize(&self) -> RCHandle<SkData>

Writes Path to buffer, returning the buffer written to, wrapped in Data.

serialize() writes FillType, verb array, Point array, conic weight, and additionally writes computed information like convexity and bounds.

serialize() should only be used in concert with read_from_memory(). The format used for Path in memory is not guaranteed.

Returns: Path data wrapped in Data buffer

example: https://fiddle.skia.org/c/@Path_serialize

pub fn deserialize(data: &RCHandle<SkData>) -> Option<Handle<SkPath>>

pub fn generation_id(&self) -> u32

(See Skia bug 1762.) Returns a non-zero, globally unique value. A different value is returned if verb array, Point array, or conic weight changes.

Setting FillType does not change generation identifier.

Each time the path is modified, a different generation identifier will be returned. FillType does affect generation identifier on Android framework.

Returns: non-zero, globally unique value

example: https://fiddle.skia.org/c/@Path_getGenerationID

pub fn is_valid(&self) -> bool

Returns if Path data is consistent. Corrupt Path data is detected if internal values are out of range or internal storage does not match array dimensions.

Returns: true if Path data is consistent

§

impl Handle<SkPath>

pub fn from_str( text: impl AsRef<str>, p: impl Into<Point>, font: &Handle<SkFont>, ) -> Handle<SkPath>

§

impl Handle<SkPath>

pub fn from_svg(svg: impl AsRef<str>) -> Option<Handle<SkPath>>

pub fn to_svg(&self) -> String

pub fn to_svg_with_encoding(&self, encoding: SkParsePath_PathEncoding) -> String

§

impl Handle<SkPath>

pub fn op( &self, path: &Handle<SkPath>, path_op: SkPathOp, ) -> Option<Handle<SkPath>>

pub fn simplify(&self) -> Option<Handle<SkPath>>

pub fn tight_bounds(&self) -> Option<Rect>

pub fn as_winding(&self) -> Option<Handle<SkPath>>

Trait Implementations

§

impl<N> AsRef<Handle<N>> for Handle<N>
where N: NativeDrop,

§

fn as_ref(&self) -> &Handle<N>

Converts this type into a shared reference of the (usually inferred) input type.
§

impl<N> Clone for Handle<N>
where N: NativeDrop + NativeClone,

§

fn clone(&self) -> Handle<N>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for Handle<SkPath>

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for Handle<SkPath>

§

fn default() -> Handle<SkPath>

See [Self::new()]

§

impl<N> Drop for Handle<N>
where N: NativeDrop,

§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

impl<N> Hash for Handle<N>
where N: NativeDrop + NativeHash,

§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl<N> PartialEq for Handle<N>
where N: NativeDrop + NativePartialEq,

§

fn eq(&self, rhs: &Handle<N>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<N> RefWrapper<N> for Handle<N>
where N: NativeDrop,

§

fn wrap_ref(native: &N) -> &Handle<N>

§

fn wrap_mut(native: &mut N) -> &mut Handle<N>

§

fn inner(&self) -> &N

§

fn inner_mut(&mut self) -> &mut N

§

impl<N> ValueWrapper<N> for Handle<N>
where N: NativeDrop,

§

fn wrap(native: N) -> Handle<N>
where N: NativeDrop,

§

fn unwrap(self) -> N

§

fn inner(&self) -> &N

§

fn inner_mut(&mut self) -> &mut N

§

impl Send for Handle<SkPath>

§

impl Sync for Handle<SkPath>