diff --git a/src/Artemis.Core/Utilities/Numeric.cs b/src/Artemis.Core/Utilities/Numeric.cs index 8fda4c66b..06c2ca7fd 100644 --- a/src/Artemis.Core/Utilities/Numeric.cs +++ b/src/Artemis.Core/Utilities/Numeric.cs @@ -432,5 +432,30 @@ public static class NumericExtensions return new Numeric(sum); } + /// + /// Subtracts the numerics in the provided collection + /// + /// The remainder of all numerics subtracted from one another in the collection + /// + public static Numeric Subtract(this IEnumerable source) + { + if (source == null) throw new ArgumentNullException(nameof(source)); + + float subtraction = 0f; + bool first = true; + foreach (float v in source) + { + if (first) + { + subtraction = v; + first = false; + } + else + subtraction -= v; + } + + return new Numeric(subtraction); + } + #endregion } \ No newline at end of file diff --git a/src/Artemis.Core/VisualScripting/Pins/InputPin.cs b/src/Artemis.Core/VisualScripting/Pins/InputPin.cs index 90933f31b..8addc4627 100644 --- a/src/Artemis.Core/VisualScripting/Pins/InputPin.cs +++ b/src/Artemis.Core/VisualScripting/Pins/InputPin.cs @@ -26,6 +26,8 @@ public sealed class InputPin : Pin { if (ConnectedTo.Count > 0 && ConnectedTo[0].PinValue is T value) Value = value; + else + Value = default; } #endregion diff --git a/src/Artemis.VisualScripting/Nodes/Mathematics/SubtractNode.cs b/src/Artemis.VisualScripting/Nodes/Mathematics/SubtractNode.cs new file mode 100644 index 000000000..baaf4147a --- /dev/null +++ b/src/Artemis.VisualScripting/Nodes/Mathematics/SubtractNode.cs @@ -0,0 +1,34 @@ +using Artemis.Core; + +namespace Artemis.VisualScripting.Nodes.Mathematics; + +[Node("Subtract", "Subtracts the connected numeric values.", "Mathematics", InputType = typeof(Numeric), OutputType = typeof(Numeric))] +public class SubtractNumericsNode : Node +{ + #region Constructors + + public SubtractNumericsNode() + { + Values = CreateInputPinCollection("Values", 2); + Remainder = CreateOutputPin("Remainder"); + } + + #endregion + + #region Methods + + public override void Evaluate() + { + Remainder.Value = Values.Values.Subtract(); + } + + #endregion + + #region Properties & Fields + + public InputPinCollection Values { get; } + + public OutputPin Remainder { get; } + + #endregion +} \ No newline at end of file