Skip to main content

MeshGradient

Struct MeshGradient 

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

A grid of colored control points blended smoothly across each cell.

Each cell blends its four corner colors in Oklab with smoothstep weights, so color is continuous across cells and flat at every control point. Cell geometry is the bilinear patch of its corner positions; moving control points warps the colors. Alpha interpolates linearly. Authored paints evaluate inverse-bilinear patches independently on CPU/GPU; explicit rasterization retains the tessellated image baking path for existing artwork.

use motion_core::{
    Color, MeshGradient, PixelSize, RasterLimits, Rect,
};
let mesh = MeshGradient::grid(2, 2, &[
    Color::from_hex(0xff0000), Color::from_hex(0x00ff00),
    Color::from_hex(0x0000ff), Color::WHITE,
])?;
let pattern = mesh.pattern(
    Rect::new(0.0, 0.0, 64.0, 64.0),
    PixelSize::new(16, 16),
    4,
    RasterLimits::default(),
)?;
assert_eq!(pattern.image.width(), 16);

Implementations§

Source§

impl MeshGradient

Source

pub fn new( columns: u32, rows: u32, vertices: Vec<MeshVertex>, ) -> Result<Self, ValidationError>

Creates a mesh from row-major control points.

Requires at least two points per axis, at most MAX_MESH_POINTS_PER_AXIS, and exactly columns * rows finite vertices.

Source

pub fn grid( columns: u32, rows: u32, colors: &[Color], ) -> Result<Self, ValidationError>

Creates a regular lattice covering the unit square from row-major colors.

Source

pub fn columns(&self) -> u32

Control points along the horizontal axis.

Source

pub fn rows(&self) -> u32

Control points along the vertical axis.

Source

pub fn vertices(&self) -> &[MeshVertex]

Row-major control points.

Source

pub fn patch(&self, column: u32, row: u32) -> Result<MeshPatch, ValidationError>

Creates one admitted analytic patch without allocating an image or lattice.

Rejects out-of-range indices or coordinates/colors outside shared shader support.

Source

pub fn rasterize( &self, size: PixelSize, subdivisions: u32, limits: RasterLimits, ) -> Result<MeshImage, ValidationError>

Rasterizes the unit square into a size image, splitting every cell edge into subdivisions pieces. Pixels outside the mesh stay transparent.

Admits pixels, storage and triangle work through limits before allocating.

Source

pub fn pattern( &self, bounds: Rect, size: PixelSize, subdivisions: u32, limits: RasterLimits, ) -> Result<ImagePattern, ValidationError>

Rasterizes the mesh and maps it onto bounds as an extend-padded bilinear pattern.

Trait Implementations§

Source§

impl Clone for MeshGradient

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for MeshGradient

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for MeshGradient

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for MeshGradient

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.