Skip to main content

PathStorage

Struct PathStorage 

Source
pub struct PathStorage { /* private fields */ }
Expand description

Path storage — the main vertex container.

Stores an ordered sequence of vertices, each with an (x, y) coordinate and a path command. Supports multiple sub-paths separated by move_to or stop commands. Implements VertexSource for use in the rendering pipeline.

Port of C++ agg::path_storage (typedef for path_base<vertex_block_storage<double>>).

Implementations§

Source§

impl PathStorage

Source

pub fn new() -> Self

Create an empty path storage.

Source

pub fn remove_all(&mut self)

Remove all vertices (keeps allocated memory).

Source

pub fn free_all(&mut self)

Remove all vertices and free memory.

Source

pub fn start_new_path(&mut self) -> usize

Begin a new sub-path. If the last command is not stop, inserts a stop command first. Returns the index where the new path will start.

Source

pub fn add_vertex(&mut self, x: f64, y: f64, cmd: u32)

Add a vertex with an explicit command.

Port of C++ path_storage::add_vertex(x, y, cmd).

Source

pub fn move_to(&mut self, x: f64, y: f64)

Add a move_to command.

Source

pub fn move_rel(&mut self, dx: f64, dy: f64)

Add a relative move_to command.

Source

pub fn line_to(&mut self, x: f64, y: f64)

Add a line_to command.

Source

pub fn line_rel(&mut self, dx: f64, dy: f64)

Add a relative line_to command.

Source

pub fn hline_to(&mut self, x: f64)

Add a horizontal line_to command.

Source

pub fn hline_rel(&mut self, dx: f64)

Add a relative horizontal line_to command.

Source

pub fn vline_to(&mut self, y: f64)

Add a vertical line_to command.

Source

pub fn vline_rel(&mut self, dy: f64)

Add a relative vertical line_to command.

Source

pub fn arc_to( &mut self, rx: f64, ry: f64, angle: f64, large_arc_flag: bool, sweep_flag: bool, x: f64, y: f64, )

Add an SVG-style arc_to command.

Source

pub fn arc_rel( &mut self, rx: f64, ry: f64, angle: f64, large_arc_flag: bool, sweep_flag: bool, dx: f64, dy: f64, )

Add a relative SVG-style arc_to command.

Source

pub fn curve3(&mut self, x_ctrl: f64, y_ctrl: f64, x_to: f64, y_to: f64)

Add a quadratic Bezier curve (curve3) with explicit control point.

Source

pub fn curve3_rel(&mut self, dx_ctrl: f64, dy_ctrl: f64, dx_to: f64, dy_to: f64)

Add a relative quadratic Bezier curve with explicit control point.

Source

pub fn curve3_smooth(&mut self, x_to: f64, y_to: f64)

Add a smooth quadratic Bezier curve (reflected control point).

Source

pub fn curve3_smooth_rel(&mut self, dx_to: f64, dy_to: f64)

Add a relative smooth quadratic Bezier curve.

Source

pub fn curve4( &mut self, x_ctrl1: f64, y_ctrl1: f64, x_ctrl2: f64, y_ctrl2: f64, x_to: f64, y_to: f64, )

Add a cubic Bezier curve (curve4) with two explicit control points.

Source

pub fn curve4_rel( &mut self, dx_ctrl1: f64, dy_ctrl1: f64, dx_ctrl2: f64, dy_ctrl2: f64, dx_to: f64, dy_to: f64, )

Add a relative cubic Bezier curve with two explicit control points.

Source

pub fn curve4_smooth( &mut self, x_ctrl2: f64, y_ctrl2: f64, x_to: f64, y_to: f64, )

Add a smooth cubic Bezier curve (reflected first control point).

Source

pub fn curve4_smooth_rel( &mut self, dx_ctrl2: f64, dy_ctrl2: f64, dx_to: f64, dy_to: f64, )

Add a relative smooth cubic Bezier curve.

Source

pub fn end_poly(&mut self, flags: u32)

Add an end_poly command with optional flags.

Source

pub fn close_polygon(&mut self, flags: u32)

Close the current polygon.

Source

pub fn total_vertices(&self) -> usize

Total number of vertices stored.

Source

pub fn rel_to_abs(&self, x: &mut f64, y: &mut f64)

Convert relative coordinates to absolute by adding last vertex position.

Source

pub fn last_vertex_xy(&self, x: &mut f64, y: &mut f64) -> u32

Get the last vertex’s (x, y) and command. Returns PATH_CMD_STOP if empty.

Source

pub fn prev_vertex_xy(&self, x: &mut f64, y: &mut f64) -> u32

Get the second-to-last vertex’s (x, y) and command.

Source

pub fn last_command(&self) -> u32

Get the last command (or PATH_CMD_STOP if empty).

Source

pub fn last_x(&self) -> f64

Get the X coordinate of the last vertex (or 0.0 if empty).

Source

pub fn last_y(&self) -> f64

Get the Y coordinate of the last vertex (or 0.0 if empty).

Source

pub fn vertex_idx(&self, idx: usize, x: &mut f64, y: &mut f64) -> u32

Get a vertex by index. Returns the command.

Source

pub fn command(&self, idx: usize) -> u32

Get a command by index.

Source

pub fn modify_vertex(&mut self, idx: usize, x: f64, y: f64)

Modify a vertex’s coordinates.

Source

pub fn modify_vertex_cmd(&mut self, idx: usize, x: f64, y: f64, cmd: u32)

Modify a vertex’s coordinates and command.

Source

pub fn modify_command(&mut self, idx: usize, cmd: u32)

Modify only a vertex’s command.

Source

pub fn swap_vertices(&mut self, v1: usize, v2: usize)

Swap two vertices (coordinates and commands).

Source

pub fn concat_path(&mut self, vs: &mut dyn VertexSource, path_id: u32)

Concatenate all vertices from a vertex source as-is.

Source

pub fn join_path(&mut self, vs: &mut dyn VertexSource, path_id: u32)

Join a vertex source to the existing path (pen stays down).

The first move_to of the joined path is converted to line_to if the current path already has a vertex endpoint.

Source

pub fn concat_poly(&mut self, data: &[f64], closed: bool)

Concatenate a polygon from flat coordinate data.

Source

pub fn join_poly(&mut self, data: &[f64], closed: bool)

Join a polygon from flat coordinate data.

Source

pub fn invert_polygon(&mut self, start: usize)

Invert the polygon starting at start.

Source

pub fn arrange_polygon_orientation( &mut self, start: usize, orientation: u32, ) -> usize

Arrange polygon orientation for a single polygon starting at start. Returns the index past the end of the polygon.

Source

pub fn arrange_orientations(&mut self, start: usize, orientation: u32) -> usize

Arrange orientations of all polygons in a sub-path.

Source

pub fn arrange_orientations_all_paths(&mut self, orientation: u32)

Arrange orientations of all polygons in all paths.

Source

pub fn flip_x(&mut self, x1: f64, x2: f64)

Flip all vertices horizontally between x1 and x2.

Source

pub fn flip_y(&mut self, y1: f64, y2: f64)

Flip all vertices vertically between y1 and y2.

Source

pub fn translate(&mut self, dx: f64, dy: f64, path_id: usize)

Translate vertices starting from path_id until a stop command.

Source

pub fn translate_all_paths(&mut self, dx: f64, dy: f64)

Translate all vertices in all paths.

Source

pub fn transform<F: Fn(f64, f64) -> (f64, f64)>( &mut self, trans: &F, path_id: usize, )

Transform vertices starting from path_id using a closure.

Source

pub fn transform_all_paths<F: Fn(f64, f64) -> (f64, f64)>(&mut self, trans: &F)

Transform all vertices in all paths using a closure.

Source

pub fn align_path(&mut self, idx: usize) -> usize

Align a single path so that nearly-equal start/end points become exact. Returns the index past the end of this path.

Source

pub fn align_all_paths(&mut self)

Align all paths.

Trait Implementations§

Source§

impl Clone for PathStorage

Source§

fn clone(&self) -> PathStorage

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Default for PathStorage

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl VertexSource for PathStorage

Source§

fn rewind(&mut self, path_id: u32)

Reset the vertex source to the beginning of the given path. path_id selects which sub-path to iterate (0 for the first/only path).
Source§

fn vertex(&mut self, x: &mut f64, y: &mut f64) -> u32

Return the next vertex. Writes coordinates to x and y, returns a path command. Returns PATH_CMD_STOP when iteration is complete.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.