Struct deform_grid::DeformGrid

source ·
pub struct DeformGrid {
    pub cols: usize,
    pub rows: usize,
    pub rect: [Scalar; 4],
    pub vertices: Vec<Vec2d>,
    pub indices: Vec<usize>,
    pub texture_coords: Vec<[f32; 2]>,
    pub ps: Vec<[Scalar; 2]>,
    pub qs: Vec<[Scalar; 2]>,
    pub wis: Vec<Scalar>,
}
Expand description

Represents a deformed grid.

Fields§

§cols: usize

The number of columns in the grid.

§rows: usize

The number of rows in the grid.

§rect: [Scalar; 4]

The grid undeformed, which is a plain rectangle.

§vertices: Vec<Vec2d>

The vertices, deformed.

§indices: Vec<usize>

The triangle indices.

§texture_coords: Vec<[f32; 2]>

The texture coordinates.

§ps: Vec<[Scalar; 2]>

Initial position of control points.

§qs: Vec<[Scalar; 2]>

The current position of control points.

§wis: Vec<Scalar>

A weight computation buffer, one for each control point.

Implementations§

source§

impl DeformGrid

source

pub fn new(rect: Rectangle, cols: usize, rows: usize) -> DeformGrid

Creates a new DeformGrid.

source

pub fn set_current(&mut self, i: usize, pos: Vec2d)

Sets current control position.

source

pub fn set_original(&mut self, i: usize, pos: Vec2d)

Sets original control position.

source

pub fn reset_control_points(&mut self)

Removes all control points.

source

pub fn reset_vertices_and_texture_coords(&mut self)

Sets vertices and texture coords back to default.

source

pub fn hit(&self, pos: Vec2d) -> Option<Vec2d>

Finds original coordinate. If the deformed grid is overlapping itself, multiple hits might occur. Returns the first hit it finds.

source

pub fn draw_image<G>( &self, texture: &<G as Graphics>::Texture, draw_state: &DrawState, transform: Matrix2d, g: &mut G )where G: Graphics,

Draws deformed image using default triangulation.

source

pub fn add_control_point(&mut self, pos: Vec2d)

Adds a control point, in original coordinates.

source

pub fn draw_vertical_lines<G>( &self, line: &Line, draw_state: &DrawState, transform: Matrix2d, g: &mut G )where G: Graphics,

Draw vertical grid lines.

source

pub fn draw_horizontal_lines<G>( &self, line: &Line, draw_state: &DrawState, transform: Matrix2d, g: &mut G )where G: Graphics,

Draw horizontal grid lines.

source

pub fn update(&mut self)

Updates the grid, by deforming the vertices.

Trait Implementations§

source§

impl Clone for DeformGrid

source§

fn clone(&self) -> DeformGrid

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

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.