summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-01-13 14:11:23 +0100
committerLaurenz <laurmaedje@gmail.com>2022-01-13 14:14:00 +0100
commitc7f52ed0489de0c144d4684a26f557b7a6ee182e (patch)
treef775d85bbad3c7b6e99b3b11049371ca1f24435d /src/library
parente74ae6ce70d4c6ca006613eadf07f920951789e3 (diff)
Add `even` and `odd` functions
Diffstat (limited to 'src/library')
-rw-r--r--src/library/mod.rs2
-rw-r--r--src/library/shape.rs2
-rw-r--r--src/library/utility.rs10
3 files changed, 13 insertions, 1 deletions
diff --git a/src/library/mod.rs b/src/library/mod.rs
index cb117702..c4ec2988 100644
--- a/src/library/mod.rs
+++ b/src/library/mod.rs
@@ -129,6 +129,8 @@ pub fn new() -> Scope {
std.def_func("abs", abs);
std.def_func("min", min);
std.def_func("max", max);
+ std.def_func("even", even);
+ std.def_func("odd", odd);
std.def_func("range", range);
std.def_func("rgb", rgb);
std.def_func("lower", lower);
diff --git a/src/library/shape.rs b/src/library/shape.rs
index 32e39b6a..12126ab4 100644
--- a/src/library/shape.rs
+++ b/src/library/shape.rs
@@ -22,7 +22,7 @@ impl<S: ShapeKind> ShapeNode<S> {
pub const STROKE: Smart<Option<Paint>> = Smart::Auto;
/// The stroke's thickness.
pub const THICKNESS: Length = Length::pt(1.0);
- /// The How much to pad the shape's content.
+ /// How much to pad the shape's content.
pub const PADDING: Linear = Linear::zero();
fn construct(_: &mut EvalContext, args: &mut Args) -> TypResult<Node> {
diff --git a/src/library/utility.rs b/src/library/utility.rs
index 6cc17449..10c5980a 100644
--- a/src/library/utility.rs
+++ b/src/library/utility.rs
@@ -135,6 +135,16 @@ pub fn max(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
minmax(args, Ordering::Greater)
}
+/// Whether an integer is even.
+pub fn even(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
+ Ok(Value::Bool(args.expect::<i64>("integer")? % 2 == 0))
+}
+
+/// Whether an integer is odd.
+pub fn odd(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
+ Ok(Value::Bool(args.expect::<i64>("integer")? % 2 != 0))
+}
+
/// Find the minimum or maximum of a sequence of values.
fn minmax(args: &mut Args, goal: Ordering) -> TypResult<Value> {
let mut extremum = args.expect::<Value>("value")?;