diff --git a/node-graph/gcore/src/ops.rs b/node-graph/gcore/src/ops.rs index 6f052646..a88afc73 100644 --- a/node-graph/gcore/src/ops.rs +++ b/node-graph/gcore/src/ops.rs @@ -219,23 +219,35 @@ fn cosine_inverse(_: impl Ctx, #[implementations(f6 if radians { value.acos() } else { value.acos().to_degrees() } } -/// The inverse tangent trigonometric function (atan) calculates the angle whose tangent is the specified value. +/// The inverse tangent trigonometric function (atan or atan2, depending on input type) calculates: +/// atan: the angle whose tangent is the specified scalar number. +/// atan2: the angle of a ray from the origin to the specified vector2 point. #[node_macro::node(category("Math: Trig"))] -fn tangent_inverse(_: impl Ctx, #[implementations(f64, f32)] value: U, radians: bool) -> U { - if radians { value.atan() } else { value.atan().to_degrees() } +fn tangent_inverse(_: impl Ctx, #[implementations(f64, f32, DVec2)] value: U, radians: bool) -> U::Output { + value.atan(radians) } -/// The inverse tangent trigonometric function (atan2) calculates the angle whose tangent is the ratio of the two specified values. -#[node_macro::node(name("Tangent Inverse 2-Argument"), category("Math: Trig"))] -fn tangent_inverse_2_argument( - _: impl Ctx, - #[implementations(f64, f32)] y: U, - #[expose] - #[implementations(f64, f32)] - x: U, - radians: bool, -) -> U { - if radians { y.atan2(x) } else { y.atan2(x).to_degrees() } +pub trait TangentInverse { + type Output: num_traits::float::Float; + fn atan(self, radians: bool) -> Self::Output; +} +impl TangentInverse for f32 { + type Output = f32; + fn atan(self, radians: bool) -> Self::Output { + if radians { self.atan() } else { self.atan().to_degrees() } + } +} +impl TangentInverse for f64 { + type Output = f64; + fn atan(self, radians: bool) -> Self::Output { + if radians { self.atan() } else { self.atan().to_degrees() } + } +} +impl TangentInverse for glam::DVec2 { + type Output = f64; + fn atan(self, radians: bool) -> Self::Output { + if radians { self.y.atan2(self.x) } else { self.y.atan2(self.x).to_degrees() } + } } /// The random function (rand) converts a seed into a random number within the specified range, inclusive of the minimum and exclusive of the maximum. The minimum and maximum values are automatically swapped if they are reversed.