Switch to N64 type alias
This commit is contained in:
parent
9e0a34c80f
commit
b886ced408
@ -1,4 +1,4 @@
|
||||
use decorum::NotNan;
|
||||
use decorum::N64;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::*;
|
||||
@ -9,13 +9,13 @@ use super::*;
|
||||
#[serde(transparent)]
|
||||
pub struct Length {
|
||||
/// The length in raw units.
|
||||
raw: NotNan<f64>,
|
||||
raw: N64,
|
||||
}
|
||||
|
||||
impl Length {
|
||||
/// The zero length.
|
||||
pub fn zero() -> Self {
|
||||
Self { raw: 0.0.into() }
|
||||
Self { raw: N64::from(0.0) }
|
||||
}
|
||||
|
||||
/// Create a length from a number of points.
|
||||
@ -40,7 +40,7 @@ impl Length {
|
||||
|
||||
/// Create a length from a number of raw units.
|
||||
pub fn raw(raw: f64) -> Self {
|
||||
Self { raw: raw.into() }
|
||||
Self { raw: N64::from(raw) }
|
||||
}
|
||||
|
||||
/// Convert this to a number of points.
|
||||
@ -70,7 +70,7 @@ impl Length {
|
||||
|
||||
/// Create a length from a value in a unit.
|
||||
pub fn with_unit(val: f64, unit: LengthUnit) -> Self {
|
||||
Self { raw: (val * unit.raw_scale()).into() }
|
||||
Self { raw: N64::from(val * unit.raw_scale()) }
|
||||
}
|
||||
|
||||
/// Get the value of this length in unit.
|
||||
|
@ -1,4 +1,4 @@
|
||||
use decorum::NotNan;
|
||||
use decorum::N64;
|
||||
|
||||
use super::*;
|
||||
|
||||
@ -7,22 +7,22 @@ use super::*;
|
||||
/// _Note_: `50%` is represented as `0.5` here, but stored as `50.0` in the
|
||||
/// corresponding [literal](crate::syntax::Expr::Percent).
|
||||
#[derive(Default, Copy, Clone, PartialEq, PartialOrd, Hash)]
|
||||
pub struct Relative(NotNan<f64>);
|
||||
pub struct Relative(N64);
|
||||
|
||||
impl Relative {
|
||||
/// A ratio of `0%` represented as `0.0`.
|
||||
pub fn zero() -> Self {
|
||||
Self(0.0.into())
|
||||
Self(N64::from(0.0))
|
||||
}
|
||||
|
||||
/// A ratio of `100%` represented as `1.0`.
|
||||
pub fn one() -> Self {
|
||||
Self(1.0.into())
|
||||
Self(N64::from(1.0))
|
||||
}
|
||||
|
||||
/// Create a new relative value.
|
||||
pub fn new(ratio: f64) -> Self {
|
||||
Self(ratio.into())
|
||||
Self(N64::from(ratio))
|
||||
}
|
||||
|
||||
/// Get the underlying ratio.
|
||||
|
@ -20,7 +20,7 @@ use std::any::Any;
|
||||
use std::fmt::{self, Debug, Formatter};
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
use decorum::NotNan;
|
||||
use decorum::N64;
|
||||
use fxhash::FxHasher64;
|
||||
|
||||
use crate::cache::{Cache, FramesEntry};
|
||||
@ -257,7 +257,7 @@ impl Regions {
|
||||
}
|
||||
|
||||
/// Shrink `current` to ensure that the aspect ratio can be satisfied.
|
||||
pub fn apply_aspect_ratio(&mut self, aspect: NotNan<f64>) {
|
||||
pub fn apply_aspect_ratio(&mut self, aspect: N64) {
|
||||
let width = self.current.width.min(aspect.into_inner() * self.current.height);
|
||||
let height = width / aspect.into_inner();
|
||||
self.current = Size::new(width, height);
|
||||
|
@ -1,4 +1,4 @@
|
||||
use decorum::NotNan;
|
||||
use decorum::N64;
|
||||
|
||||
use super::*;
|
||||
|
||||
@ -13,7 +13,7 @@ pub struct StackNode {
|
||||
/// The fixed aspect ratio between width and height, if any.
|
||||
///
|
||||
/// The resulting frames will satisfy `width = aspect * height`.
|
||||
pub aspect: Option<NotNan<f64>>,
|
||||
pub aspect: Option<N64>,
|
||||
/// The nodes to be stacked.
|
||||
pub children: Vec<StackChild>,
|
||||
}
|
||||
@ -58,7 +58,7 @@ impl From<StackNode> for AnyNode {
|
||||
|
||||
struct StackLayouter {
|
||||
dirs: Gen<Dir>,
|
||||
aspect: Option<NotNan<f64>>,
|
||||
aspect: Option<N64>,
|
||||
main: SpecAxis,
|
||||
regions: Regions,
|
||||
finished: Vec<Frame>,
|
||||
@ -69,7 +69,7 @@ struct StackLayouter {
|
||||
}
|
||||
|
||||
impl StackLayouter {
|
||||
fn new(dirs: Gen<Dir>, aspect: Option<NotNan<f64>>, mut regions: Regions) -> Self {
|
||||
fn new(dirs: Gen<Dir>, aspect: Option<N64>, mut regions: Regions) -> Self {
|
||||
if let Some(aspect) = aspect {
|
||||
regions.apply_aspect_ratio(aspect);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::f64::consts::SQRT_2;
|
||||
|
||||
use decorum::NotNan;
|
||||
use decorum::N64;
|
||||
|
||||
use super::*;
|
||||
use crate::color::Color;
|
||||
@ -49,14 +49,14 @@ pub fn square(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||
let height = width.is_none().then(|| args.eat_named(ctx, "height")).flatten();
|
||||
let fill = args.eat_named(ctx, "fill");
|
||||
let body = args.eat::<TemplateValue>(ctx).unwrap_or_default();
|
||||
rect_impl("square", width, height, Some(1.0.into()), fill, body)
|
||||
rect_impl("square", width, height, Some(N64::from(1.0)), fill, body)
|
||||
}
|
||||
|
||||
fn rect_impl(
|
||||
name: &str,
|
||||
width: Option<Linear>,
|
||||
height: Option<Linear>,
|
||||
aspect: Option<NotNan<f64>>,
|
||||
aspect: Option<N64>,
|
||||
fill: Option<Color>,
|
||||
body: TemplateValue,
|
||||
) -> Value {
|
||||
@ -121,14 +121,14 @@ pub fn circle(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||
let height = width.is_none().then(|| args.eat_named(ctx, "height")).flatten();
|
||||
let fill = args.eat_named(ctx, "fill");
|
||||
let body = args.eat::<TemplateValue>(ctx).unwrap_or_default();
|
||||
ellipse_impl("circle", width, height, Some(1.0.into()), fill, body)
|
||||
ellipse_impl("circle", width, height, Some(N64::from(1.0)), fill, body)
|
||||
}
|
||||
|
||||
fn ellipse_impl(
|
||||
name: &str,
|
||||
width: Option<Linear>,
|
||||
height: Option<Linear>,
|
||||
aspect: Option<NotNan<f64>>,
|
||||
aspect: Option<N64>,
|
||||
fill: Option<Color>,
|
||||
body: TemplateValue,
|
||||
) -> Value {
|
||||
|
Loading…
x
Reference in New Issue
Block a user