mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 21:38:38 +00:00
Nodes - Added numeric subtract node
This commit is contained in:
parent
ff633f7e8e
commit
0a3e822d03
@ -432,5 +432,30 @@ public static class NumericExtensions
|
||||
return new Numeric(sum);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts the numerics in the provided collection
|
||||
/// </summary>
|
||||
/// <returns>The remainder of all numerics subtracted from one another in the collection</returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public static Numeric Subtract(this IEnumerable<Numeric> 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
|
||||
}
|
||||
@ -26,6 +26,8 @@ public sealed class InputPin<T> : Pin
|
||||
{
|
||||
if (ConnectedTo.Count > 0 && ConnectedTo[0].PinValue is T value)
|
||||
Value = value;
|
||||
else
|
||||
Value = default;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -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<Numeric>("Values", 2);
|
||||
Remainder = CreateOutputPin<Numeric>("Remainder");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public override void Evaluate()
|
||||
{
|
||||
Remainder.Value = Values.Values.Subtract();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties & Fields
|
||||
|
||||
public InputPinCollection<Numeric> Values { get; }
|
||||
|
||||
public OutputPin<Numeric> Remainder { get; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user