style: Add experimental support for "e", "pi", and various trigonometric functions in calc()

I'll add some tests before enabling. Also, WebKit folks (who have
implemented cos() / tan() / sin()) said they will upstream their tests
to WPT, so I'll extend those with the inverse functions before landing
as well.

Differential Revision: https://phabricator.services.mozilla.com/D124990
This commit is contained in:
Emilio Cobos Álvarez 2023-05-27 07:12:22 +02:00 committed by Oriol Brufau
parent 4f193fbf49
commit 4522e7f94a
2 changed files with 93 additions and 8 deletions

View file

@ -130,6 +130,15 @@ impl Angle {
}
}
/// Creates an angle with the given value in radians.
#[inline]
pub fn from_radians(value: CSSFloat) -> Self {
Angle {
value: AngleDimension::Rad(value),
was_calc: false,
}
}
/// Return `0deg`.
pub fn zero() -> Self {
Self::from_degrees(0.0, false)
@ -141,6 +150,13 @@ impl Angle {
self.value.degrees()
}
/// Returns the value of the angle in radians.
#[inline]
pub fn radians(&self) -> CSSFloat {
const RAD_PER_DEG: f32 = PI / 180.0;
self.value.degrees() * RAD_PER_DEG
}
/// Whether this specified angle came from a `calc()` expression.
#[inline]
pub fn was_calc(&self) -> bool {