From 9c040a9d2b6aa0400df868c8a8581a9e168b9d14 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 29 Mar 2021 14:51:54 +0200 Subject: =?UTF-8?q?Move=20around=20test=20cases=20=F0=9F=9A=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/library/base.rs | 65 ---------------------------------------------------- src/library/basic.rs | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/library/mod.rs | 4 ++-- 3 files changed, 67 insertions(+), 67 deletions(-) delete mode 100644 src/library/base.rs create mode 100644 src/library/basic.rs (limited to 'src') diff --git a/src/library/base.rs b/src/library/base.rs deleted file mode 100644 index 48925122..00000000 --- a/src/library/base.rs +++ /dev/null @@ -1,65 +0,0 @@ -use crate::color::{Color, RgbaColor}; -use crate::pretty::pretty; - -use super::*; - -/// `type`: The name of a value's type. -/// -/// # Positional parameters -/// - Any value. -/// -/// # Return value -/// The name of the value's type as a string. -pub fn type_(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { - match args.require::(ctx, "value") { - Some(value) => value.type_name().into(), - None => Value::Error, - } -} - -/// `repr`: The string representation of a value. -/// -/// # Positional parameters -/// - Any value. -/// -/// # Return value -/// The string representation of the value. -pub fn repr(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { - match args.require::(ctx, "value") { - Some(value) => pretty(&value).into(), - None => Value::Error, - } -} - -/// `rgb`: Create an RGB(A) color. -/// -/// # Positional parameters -/// - Red component: of type `float`, between 0.0 and 1.0. -/// - Green component: of type `float`, between 0.0 and 1.0. -/// - Blue component: of type `float`, between 0.0 and 1.0. -/// - Alpha component: optional, of type `float`, between 0.0 and 1.0. -/// -/// # Return value -/// The color with the given components. -pub fn rgb(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { - let r = args.require(ctx, "red component"); - let g = args.require(ctx, "green component"); - let b = args.require(ctx, "blue component"); - let a = args.find(ctx); - - let mut clamp = |component: Option>, default| { - component.map_or(default, |c| { - if c.v < 0.0 || c.v > 1.0 { - ctx.diag(warning!(c.span, "should be between 0.0 and 1.0")); - } - (c.v.max(0.0).min(1.0) * 255.0).round() as u8 - }) - }; - - Value::Color(Color::Rgba(RgbaColor::new( - clamp(r, 0), - clamp(g, 0), - clamp(b, 0), - clamp(a, 255), - ))) -} diff --git a/src/library/basic.rs b/src/library/basic.rs new file mode 100644 index 00000000..48925122 --- /dev/null +++ b/src/library/basic.rs @@ -0,0 +1,65 @@ +use crate::color::{Color, RgbaColor}; +use crate::pretty::pretty; + +use super::*; + +/// `type`: The name of a value's type. +/// +/// # Positional parameters +/// - Any value. +/// +/// # Return value +/// The name of the value's type as a string. +pub fn type_(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { + match args.require::(ctx, "value") { + Some(value) => value.type_name().into(), + None => Value::Error, + } +} + +/// `repr`: The string representation of a value. +/// +/// # Positional parameters +/// - Any value. +/// +/// # Return value +/// The string representation of the value. +pub fn repr(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { + match args.require::(ctx, "value") { + Some(value) => pretty(&value).into(), + None => Value::Error, + } +} + +/// `rgb`: Create an RGB(A) color. +/// +/// # Positional parameters +/// - Red component: of type `float`, between 0.0 and 1.0. +/// - Green component: of type `float`, between 0.0 and 1.0. +/// - Blue component: of type `float`, between 0.0 and 1.0. +/// - Alpha component: optional, of type `float`, between 0.0 and 1.0. +/// +/// # Return value +/// The color with the given components. +pub fn rgb(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { + let r = args.require(ctx, "red component"); + let g = args.require(ctx, "green component"); + let b = args.require(ctx, "blue component"); + let a = args.find(ctx); + + let mut clamp = |component: Option>, default| { + component.map_or(default, |c| { + if c.v < 0.0 || c.v > 1.0 { + ctx.diag(warning!(c.span, "should be between 0.0 and 1.0")); + } + (c.v.max(0.0).min(1.0) * 255.0).round() as u8 + }) + }; + + Value::Color(Color::Rgba(RgbaColor::new( + clamp(r, 0), + clamp(g, 0), + clamp(b, 0), + clamp(a, 255), + ))) +} diff --git a/src/library/mod.rs b/src/library/mod.rs index 9c2a661a..738348ee 100644 --- a/src/library/mod.rs +++ b/src/library/mod.rs @@ -4,7 +4,7 @@ //! definitions. mod align; -mod base; +mod basic; mod font; mod image; mod lang; @@ -17,7 +17,7 @@ mod spacing; pub use self::image::*; pub use align::*; -pub use base::*; +pub use basic::*; pub use font::*; pub use lang::*; pub use markup::*; -- cgit v1.2.3