silk.geometry.corners.
A value for each of the four corners of a box, over any number type.
When to use#
Use Corners for corner radii of a rounded box, such as a card, a button, a shadow, or a
clipped image. silk.geometry.rounded_rect.RoundedRect pairs one with a rectangle.
Details#
A corners value is a Copy struct with public topLeft, topRight, bottomRight, and
bottomLeft fields, generic over its number type T. The names match a y-down space such as
CSS or SVG: top is the minimum y edge and left the minimum x edge. corners + corners adds each
corner, corners * T scales each corner, and &a == &b compares every corner when T: Equal.
Examples#
Fit radii to a small box#
import silk.geometry.corners { Corners }
import silk.geometry.size { Size2 }
pub fn main() -> i32 {
let radii = Corners<f64>.new(4.0, 30.0, 4.0, -2.0) * 2.0
let fitted = radii.clampToSize(Size2<f64>.new(100.0, 40.0))
if fitted.topLeft != 8.0 || fitted.topRight != 20.0 || fitted.bottomLeft != 0.0 {
return 1
}
return 0
}Import as Corners with import silk.geometry.corners { Corners }.
Public declarations: 1.
Corners#
pub struct Corners<T>A value of number type T for each of the four corners of a box, such as corner radii.
When to use#
Use Corners for the radii of a rounded box. Use silk.geometry.insets.Insets for a value per
edge, such as padding or border widths.
Details#
The fields are public. Top is the minimum y edge and left the minimum x edge, as in CSS and SVG.
corners + corners adds each corner, corners * T scales each corner, and &a == &b compares
every corner, when T has the operator.
Field topLeft#
pub topLeft: TThe value at the minimum x, minimum y corner.
Field topRight#
pub topRight: TThe value at the maximum x, minimum y corner.
Field bottomRight#
pub bottomRight: TThe value at the maximum x, maximum y corner.
Field bottomLeft#
pub bottomLeft: TThe value at the minimum x, maximum y corner.
Implementation Copy for Corners<T>#
impl<T: Copy> Copy for Corners<T>Implementation Corners<T>#
impl<T> Corners<T>Associated function new#
pub fn new(topLeft: T, topRight: T, bottomRight: T, bottomLeft: T) -> Corners<T>Returns the corners with topLeft, topRight, bottomRight, and bottomLeft, in the
clockwise order of CSS border-radius.
Method map#
pub fn map<U>(self: Self, transform: mut fn(T) -> U) -> Corners<U>Returns corners whose fields are transform applied to topLeft, topRight, bottomRight,
then bottomLeft.
Implementation Corners<T>#
impl<T: Copy> Corners<T>Associated function uniform#
pub fn uniform(value: T) -> Corners<T>Returns the corners whose four values are all value.
Implementation Corners<T>#
impl<T: Zero> Corners<T>Associated function zero#
pub fn zero() -> Corners<T>Returns the corners whose four values are zero: square corners.
Implementation Corners<T>#
impl<T: Copy + Order> Corners<T>Method max#
pub fn max(self: Self) -> TReturns the largest of the four values.
Gotchas#
For a float type, the comparison follows the IEEE 754 total order of Order: a NaN with the
sign bit clear is above every number.
Implementation Corners<T>#
impl<T: Copy + Order + Zero + One + Add<T, T> + Divide<T, T>> Corners<T>Method clampToSize#
pub fn clampToSize(self: Self, size: Size2<T>) -> Corners<T>Returns the radii limited so that they fit a box of size: each corner is clamped between zero
and half of the smaller of the width and the height.
When to use#
Call it before drawing or hit-testing a rounded box whose radii come from user input or a style, so that no two corner arcs overlap and no radius is negative.
Details#
Each corner is clamped on its own, as GPU quad shaders do, so a fitted corner keeps its radius even when another corner is reduced. CSS instead scales every radius by one shared factor; the two agree whenever no radius exceeds half the smaller side. A negative or zero width or height gives zero radii.
Implementation Add<Corners<T>, Corners<T>> for Corners<T>#
impl<T: Add<T, T>> Add<Corners<T>, Corners<T>> for Corners<T>Operation add#
fn add(left: Self, right: Self) -> SelfImplementation Multiply<T, Corners<T>> for Corners<T>#
impl<T: Copy + Multiply<T, T>> Multiply<T, Corners<T>> for Corners<T>Operation multiply#
fn multiply(left: Self, right: T) -> SelfImplementation Equal for Corners<T>#
impl<T: Equal> Equal for Corners<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, x86_64-pc-windows-msvc, wasm64-unknown-unknown.