# Struct emath::ts_transform::TSTransform

``````#[repr(C)]pub struct TSTransform {
pub scaling: f32,
pub translation: Vec2,
}``````
Expand description

Linearly transforms positions via a translation, then a scaling.

`TSTransform` first scales points with the scaling origin at `0, 0` (the top left corner), then translates them.

## Fields§

§`scaling: f32`

Scaling applied first, scaled around (0, 0).

§`translation: Vec2`

Translation amount, applied after scaling.

## Implementations§

source§

### impl TSTransform

source

source

#### pub fn new(translation: Vec2, scaling: f32) -> Self

Creates a new translation that first scales points around `(0, 0)`, then translates them.

source

source

source

#### pub fn inverse(&self) -> Self

Inverts the transform.

``````let p1 = pos2(2.0, 3.0);
let p2 = pos2(12.0, 5.0);
let ts = TSTransform::new(vec2(2.0, 3.0), 2.0);
let inv = ts.inverse();
assert_eq!(inv.mul_pos(p1), pos2(0.0, 0.0));
assert_eq!(inv.mul_pos(p2), pos2(5.0, 1.0));

assert_eq!(ts.inverse().inverse(), ts);``````
source

#### pub fn mul_pos(&self, pos: Pos2) -> Pos2

Transforms the given coordinate.

``````let p1 = pos2(0.0, 0.0);
let p2 = pos2(5.0, 1.0);
let ts = TSTransform::new(vec2(2.0, 3.0), 2.0);
assert_eq!(ts.mul_pos(p1), pos2(2.0, 3.0));
assert_eq!(ts.mul_pos(p2), pos2(12.0, 5.0));``````
source

#### pub fn mul_rect(&self, rect: Rect) -> Rect

Transforms the given rectangle.

``````let rect = Rect::from_min_max(pos2(5.0, 5.0), pos2(15.0, 10.0));
let ts = TSTransform::new(vec2(1.0, 0.0), 3.0);
let transformed = ts.mul_rect(rect);
assert_eq!(transformed.min, pos2(16.0, 15.0));
assert_eq!(transformed.max, pos2(46.0, 30.0));``````

## Trait Implementations§

source§

### impl Clone for TSTransform

source§

#### fn clone(&self) -> TSTransform

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 Debug for TSTransform

source§

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

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

### impl Default for TSTransform

source§

#### fn default() -> Self

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

### impl Mul<Pos2> for TSTransform

Transforms the position.

§

#### type Output = Pos2

The resulting type after applying the `*` operator.
source§

#### fn mul(self, pos: Pos2) -> Pos2

Performs the `*` operation. Read more
source§

### impl Mul<Rect> for TSTransform

Transforms the rectangle.

§

#### type Output = Rect

The resulting type after applying the `*` operator.
source§

#### fn mul(self, rect: Rect) -> Rect

Performs the `*` operation. Read more
source§

### impl Mul for TSTransform

source§

#### fn mul(self, rhs: Self) -> Self::Output

Applies the right hand side transform, then the left hand side.

``````let ts1 = TSTransform::new(vec2(1.0, 0.0), 2.0);
let ts2 = TSTransform::new(vec2(-1.0, -1.0), 3.0);
let ts_combined = TSTransform::new(vec2(2.0, -1.0), 6.0);
assert_eq!(ts_combined, ts2 * ts1);``````
§

#### type Output = TSTransform

The resulting type after applying the `*` operator.
source§

### impl PartialEq for TSTransform

source§

#### fn eq(&self, other: &TSTransform) -> 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.
source§

source§

source§

source§

source§

source§

§

§

§

§

§

§

## 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> CheckedBitPattern for Twhere T: AnyBitPattern,

§

#### type Bits = T

`Self` must have the same layout as the specified `Bits` except for the possible invalid bit patterns being checked during `is_valid_bit_pattern`.
source§

#### fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret `bits` as `&Self`.
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.
source§

source§