Struct druid::Affine

pub struct Affine(_);
Expand description

A 2D affine transform.

Implementations§

§

impl Affine

pub const IDENTITY: Affine = Affine::scale(1.0)

The identity transform.

pub const FLIP_Y: Affine = Affine::new([1.0, 0., 0., -1.0, 0., 0.])

A transform that is flipped on the y-axis. Useful for converting between y-up and y-down spaces.

pub const FLIP_X: Affine = Affine::new([-1.0, 0., 0., 1.0, 0., 0.])

A transform that is flipped on the x-axis.

pub const fn new(c: [f64; 6]) -> Affine

Construct an affine transform from coefficients.

If the coefficients are (a, b, c, d, e, f), then the resulting transformation represents this augmented matrix:

| a c e |
| b d f |
| 0 0 1 |

Note that this convention is transposed from PostScript and Direct2D, but is consistent with the Wikipedia formulation of affine transformation as augmented matrix. The idea is that (A * B) * v == A * (B * v), where * is the Mul trait.

pub const fn scale(s: f64) -> Affine

An affine transform representing uniform scaling.

pub const fn scale_non_uniform(s_x: f64, s_y: f64) -> Affine

An affine transform representing non-uniform scaling with different scale values for x and y

pub fn rotate(th: f64) -> Affine

An affine transform representing rotation.

The convention for rotation is that a positive angle rotates a positive X direction into positive Y. Thus, in a Y-down coordinate system (as is common for graphics), it is a clockwise rotation, and in Y-up (traditional for math), it is anti-clockwise.

The angle, th, is expressed in radians.

pub fn translate<V>(p: V) -> Affinewhere V: Into<Vec2>,

An affine transform representing translation.

pub fn map_unit_square(rect: Rect) -> Affine

Creates an affine transformation that takes the unit square to the given rectangle.

Useful when you want to draw into the unit square but have your output fill any rectangle. In this case push the Affine onto the transform stack.

pub fn as_coeffs(self) -> [f64; 6]

Get the coefficients of the transform.

pub fn determinant(self) -> f64

Compute the determinant of this transform.

pub fn inverse(self) -> Affine

Compute the inverse transform.

Produces NaN values when the determinant is zero.

pub fn transform_rect_bbox(self, rect: Rect) -> Rect

Compute the bounding box of a transformed rectangle.

Returns the minimal Rect that encloses the given Rect after affine transformation. If the transform is axis-aligned, then this bounding box is “tight”, in other words the returned Rect is the transformed rectangle.

The returned rectangle always has non-negative width and height.

pub fn is_finite(&self) -> bool

Is this map finite?

pub fn is_nan(&self) -> bool

Is this map NaN?

Trait Implementations§

§

impl Clone for Affine

§

fn clone(&self) -> Affine

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
source§

impl Data for Affine

source§

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

Determine whether two values are the same. Read more
§

impl Debug for Affine

§

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

Formats the value using the given formatter. Read more
§

impl Default for Affine

§

fn default() -> Affine

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

impl From<TranslateScale> for Affine

§

fn from(ts: TranslateScale) -> Affine

Converts to this type from the input type.
§

impl<'a> Mul<&'a BezPath> for Affine

§

type Output = BezPath

The resulting type after applying the * operator.
§

fn mul(self, other: &BezPath) -> BezPath

Performs the * operation. Read more
§

impl Mul<Affine> for Affine

§

type Output = Affine

The resulting type after applying the * operator.
§

fn mul(self, other: Affine) -> Affine

Performs the * operation. Read more
§

impl Mul<BezPath> for Affine

§

type Output = BezPath

The resulting type after applying the * operator.
§

fn mul(self, other: BezPath) -> BezPath

Performs the * operation. Read more
§

impl Mul<Circle> for Affine

§

type Output = Ellipse

The resulting type after applying the * operator.
§

fn mul(self, other: Circle) -> <Affine as Mul<Circle>>::Output

Performs the * operation. Read more
§

impl Mul<CubicBez> for Affine

§

type Output = CubicBez

The resulting type after applying the * operator.
§

fn mul(self, c: CubicBez) -> CubicBez

Performs the * operation. Read more
§

impl Mul<Ellipse> for Affine

§

type Output = Ellipse

The resulting type after applying the * operator.
§

fn mul(self, other: Ellipse) -> <Affine as Mul<Ellipse>>::Output

Performs the * operation. Read more
§

impl Mul<Line> for Affine

§

type Output = Line

The resulting type after applying the * operator.
§

fn mul(self, other: Line) -> Line

Performs the * operation. Read more
§

impl Mul<PathEl> for Affine

§

type Output = PathEl

The resulting type after applying the * operator.
§

fn mul(self, other: PathEl) -> PathEl

Performs the * operation. Read more
§

impl Mul<PathSeg> for Affine

§

type Output = PathSeg

The resulting type after applying the * operator.
§

fn mul(self, other: PathSeg) -> PathSeg

Performs the * operation. Read more
§

impl Mul<Point> for Affine

§

type Output = Point

The resulting type after applying the * operator.
§

fn mul(self, other: Point) -> Point

Performs the * operation. Read more
§

impl Mul<QuadBez> for Affine

§

type Output = QuadBez

The resulting type after applying the * operator.
§

fn mul(self, other: QuadBez) -> QuadBez

Performs the * operation. Read more
§

impl MulAssign<Affine> for Affine

§

fn mul_assign(&mut self, other: Affine)

Performs the *= operation. Read more
§

impl PartialEq<Affine> for Affine

§

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

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

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

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

impl Copy for Affine

§

impl StructuralPartialEq for Affine

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> AnyEq for Twhere T: Any + PartialEq<T>,

source§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

source§

fn as_any(&self) -> &(dyn Any + 'static)

source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

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

const: unstable · 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> IsDefault for Twhere T: Default + PartialEq<T> + Copy,

source§

fn is_default(&self) -> bool

Checks that type has a default value.
§

impl<T> RoundFrom<T> for T

§

fn round_from(x: T) -> T

Performs the conversion.
§

impl<T, U> RoundInto<U> for Twhere U: RoundFrom<T>,

§

fn round_into(self) -> U

Performs the conversion.
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
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.
const: unstable · 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.
const: unstable · source§

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

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more