From f16ac4d258bd0981506d01456bd5f43079e00fa5 Mon Sep 17 00:00:00 2001 From: Matt Fellenz Date: Wed, 19 Apr 2023 10:09:32 -0700 Subject: [PATCH] Add atan2 (#846) --- library/src/compute/calc.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/library/src/compute/calc.rs b/library/src/compute/calc.rs index 3875e3c3c..bba0e3b9c 100644 --- a/library/src/compute/calc.rs +++ b/library/src/compute/calc.rs @@ -20,6 +20,7 @@ pub fn module() -> Module { scope.define("asin", asin); scope.define("acos", acos); scope.define("atan", atan); + scope.define("atan2", atan2); scope.define("sinh", sinh); scope.define("cosh", cosh); scope.define("tanh", tanh); @@ -293,6 +294,29 @@ pub fn atan( Value::Angle(Angle::rad(value.float().atan())) } +/// Calculate the four-quadrant arctangent of a coordinate. +/// +/// The arguments are `(x, y)`, not `(y, x)`. +/// +/// ## Example +/// ```example +/// #calc.atan2(1, 1) \ +/// #calc.atan2(-2, -3) +/// ``` +/// +/// Display: Four-quadrant Arctangent +/// Category: calculate +/// Returns: angle +#[func] +pub fn atan2( + /// The X coordinate. + x: Num, + /// The Y coordinate. + y: Num, +) -> Value { + Value::Angle(Angle::rad(f64::atan2(y.float(), x.float()))) +} + /// Calculate the hyperbolic sine of an angle. /// /// When called with an integer or a float, they will be interpreted as radians.