summaryrefslogtreecommitdiff
path: root/library/src/compute
diff options
context:
space:
mode:
authorMatt Fellenz <matt@felle.nz>2023-04-19 10:09:32 -0700
committerGitHub <noreply@github.com>2023-04-19 19:09:32 +0200
commitf16ac4d258bd0981506d01456bd5f43079e00fa5 (patch)
treee934c7bf4085cf2b73fa615a282f80e32a2dda33 /library/src/compute
parentb285bea41de7bea0ea33878d812fd4a046913128 (diff)
Add atan2 (#846)
Diffstat (limited to 'library/src/compute')
-rw-r--r--library/src/compute/calc.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/library/src/compute/calc.rs b/library/src/compute/calc.rs
index 3875e3c3..bba0e3b9 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.