pub struct Size2D<T> {
    pub width: T,
    pub height: T,
}
Expand description

A vector describing a two-dimensional size.

Fields

width: Theight: T

Implementations

Create a new Size2D. In most cases you should use the size!() macro instead.

Examples
let size = Size2D::new(20, 50);

// Prefer doing this instead
let size = size!(20, 50);

Returns a new Size2D where width and height are equal.

Prefer using the splat syntax with the size() macro instead of calling this directly.

Examples
// This is acceptable, but...
let size = Size2D::square(200);

// ...this is the preferred way
let size = size!(200; 2);

assert_eq!(size, size!(200, 200));

Gets the area of the size. This is a shorthand for size.width() * size.height()

Examples
let size = size!(100, 200);

assert_eq!(size.area(), 20000);

Casts self into a new Size2D<C> where C is the (usually inferred) input type.

Examples
let a = size!(200.24, 400.90);
let b: Size2D<u32> = a.cast();

assert_eq!(b, size!(200, 400));

Returns a new Bounds2D using self as size, and position as the position.

Examples
let bounds = size!(10i32, 15).with_position(point!(2, 4));

assert_eq!(bounds, bounds!(2, 4, 10, 15));

Compares the width and height components in size and self, creating a new size where the components are the greater values. This is the opposite of shrink()

You can think of this as a one-way operation of expanding a rectangle.

Examples
let inner = size!(500, 700);
let outer = size!(400, 900);

assert_eq!(inner.grow(outer), size!(500, 900));

Compares the width and height components in size and self, creating a new size where the components are the lesser values. This is the opposite of grow()

You can think of this as a one-way operation of collapsing a rectangle.

Examples
let outer = size!(500, 200);
let inner = size!(100, 300);

assert_eq!(outer.shrink(inner), size!(100, 200));

Returns a new size constrained within the min and max. This is a shorthand for self.shrink(max).grow(min)

Examples
let min = size!(200, 300);
let max = size!(500, 500);

assert_eq!(size!(100, 400).constrain(min, max), size!(200, 400));
assert_eq!(size!(600, 300).constrain(min, max), size!(500, 300));

Returns the bigger size area between self and size. If you need to max individual components, use grow()

Examples
let a = size!(200, 400);
let b = size!(100, 300);

assert_eq!(a.max_area(b), size!(200, 400));

Returns the smaller size area between self and size. If you need to min individual components, use shrink()

Examples
let a = size!(100, 300);
let b = size!(200, 600);

assert_eq!(a.min_area(b), size!(100, 300));

Clamps the size area between min and max. If you need to clamp individual components, use constrain()

Examples
let a = size!(200, 600);
let b = size!(100, 200);

assert_eq!(a.clamp_area(b, size!(300, 300)), size!(300, 300));

Trait Implementations

Implements adding two sizes together.

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the += operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Implements dividing two points

The resulting type after applying the / operator.

Performs the / operation. Read more

Performs the /= operation. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

Implements multiplying two points

The resulting type after applying the * operator.

Performs the * operation. Read more

Performs the *= operation. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Implements subtracting two sizes

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Performs the -= operation. Read more

Creates a new Size2D from self Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.