silk.geometry.size.
Two-dimensional extents over any number type.
When to use#
Use Size2 for a width and a height with no position, such as a viewport, an image, or the
measured size of a layout box. Use silk.geometry.rect.Rect when the extent also has a
position.
Details#
A size is a Copy struct with public width and height fields, generic over its number type
T. size + size adds extents, size * T and size / T scale them, and &a == &b compares
both fields when T: Equal. Methods appear only when T has the operations they need.
Examples#
Scale a viewport and test it#
import silk.geometry.size { Size2 }
pub fn main() -> i32 {
let viewport = Size2<f64>.new(800.0, 600.0) * 0.5
if viewport.area() != 120000.0 || viewport.isEmpty() {
return 1
}
return 0
}Import as Size2 with import silk.geometry.size { Size2 }.
Public declarations: 1.
Size2#
pub struct Size2<T>A width and a height of number type T, with no position.
When to use#
Use Size2 for an extent alone. Use silk.geometry.rect.Rect for an extent at a position.
Details#
The fields are public. size + size adds both fields, size * T and size / T scale them, and
&a == &b compares them, when T has the operator. A size can be negative; isEmpty is
true for a negative or zero extent.
Field width#
pub width: TThe extent along the x axis.
Field height#
pub height: TThe extent along the y axis.
Implementation Copy for Size2<T>#
impl<T: Copy> Copy for Size2<T>Implementation Size2<T>#
impl<T> Size2<T>Associated function new#
pub fn new(width: T, height: T) -> Size2<T>Returns the size with width and height.
Method map#
pub fn map<U>(self: Self, transform: mut fn(T) -> U) -> Size2<U>Returns a size whose fields are transform applied to width, then to height.
Method toVector#
pub fn toVector(self: Self) -> Vector2<T>Returns the vector (width, height), the offset from a box's minimum corner to its maximum.
Implementation Size2<T>#
impl<T: Zero> Size2<T>Associated function zero#
pub fn zero() -> Size2<T>Returns the size whose width and height are zero.
Implementation Size2<T>#
impl<T: Copy + Multiply<T, T>> Size2<T>Method area#
pub fn area(self: Self) -> TReturns width * height.
Implementation Size2<T>#
impl<T: Zero + Order> Size2<T>Method isEmpty#
pub fn isEmpty(self: &Self) -> boolReturns true when the width or the height is zero or negative.
Gotchas#
For a float type, the comparison follows the IEEE 754 total order of Order: negative zero is
below positive zero, and a NaN with the sign bit clear is above every number.
Implementation Add<Size2<T>, Size2<T>> for Size2<T>#
impl<T: Add<T, T>> Add<Size2<T>, Size2<T>> for Size2<T>Operation add#
fn add(left: Self, right: Self) -> SelfImplementation Multiply<T, Size2<T>> for Size2<T>#
impl<T: Copy + Multiply<T, T>> Multiply<T, Size2<T>> for Size2<T>Operation multiply#
fn multiply(left: Self, right: T) -> SelfImplementation Divide<T, Size2<T>> for Size2<T>#
impl<T: Copy + Divide<T, T>> Divide<T, Size2<T>> for Size2<T>Operation divide#
fn divide(left: Self, right: T) -> SelfImplementation Equal for Size2<T>#
impl<T: Equal> Equal for Size2<T>Operation equals#
fn equals(left: &Self, right: &Self) -> boolCategory: Geometry.
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2.