/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//! Computed type for the `corner-shape` family of properties.
usecrate::derives::*; usecrate::values::animated::{Animate, Procedure, ToAnimatedZero}; usecrate::values::distance::{ComputeSquaredDistance, SquaredDistance}; usecrate::values::generics::border::GenericCornerShapeRect; use std::fmt::{self, Write}; use style_traits::{CssWriter, ToCss};
/// The computed value for a single corner shape. /// /// Per the spec, the computed value is always `superellipse(K)` where `K` may /// be any real value, including +infinity (for `square`) and -infinity /// (for `notch`). #[derive(
Clone, Copy, Debug, MallocSizeOf, PartialEq, ToShmem, ToTyped, ToAnimatedValue, ToResolvedValue,
)] #[repr(C)] #[typed(todo_derive_fields)] pubstruct CornerShape { /// The K parameter from the `superellipse()` function. pub k: f32,
}
/// Compute the "normalized superellipse half corner" for a superellipse /// parameter `s`, per /// <https://drafts.csswg.org/css-borders-4/#corner-shape-interpolation>. fn s_to_interpolation_value(s: f32) -> f32 { if s == f32::NEG_INFINITY { return0.0;
} if s == f32::INFINITY { return1.0;
} let k = 0.5f32.powf(s.abs()); let convex_half_corner = 0.5f32.powf(k); if s < 0.0 { 1.0 - convex_half_corner
} else {
convex_half_corner
}
}
/// Inverse of `s_to_interpolation_value`. fn interpolation_value_to_s(v: f32) -> f32 { if v <= 0.0 { return f32::NEG_INFINITY;
} if v >= 1.0 { return f32::INFINITY;
} let convex_half_corner = if v < 0.5 { 1.0 - v } else { v }; let k = 0.5f32.ln() / convex_half_corner.ln(); let s = k.log2(); if v < 0.5 {
-s
} else {
s
}
}
impl Animate for CornerShape { fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> { let a = s_to_interpolation_value(self.k); let b = s_to_interpolation_value(other.k); let interp = a.animate(&b, procedure)?;
Ok(CornerShape {
k: interpolation_value_to_s(interp),
})
}
}
impl ComputeSquaredDistance for CornerShape { fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> { let a = s_to_interpolation_value(self.k); let b = s_to_interpolation_value(other.k);
a.compute_squared_distance(&b)
}
}
/// The four computed corner shapes for an element. pubtype CornerShapeRect = GenericCornerShapeRect<CornerShape>;
impl CornerShapeRect { /// Initial value: `round` on every corner. #[inline] pubfn round_all() -> Self { Self::all(CornerShape::round())
}
}
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.1Bemerkung:
(vorverarbeitet am 2026-08-25)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.