Nodes/Math/Vector/Length.cs
namespace Nodebox.Nodes;


[Register]
[Tag("Math", "Vector")]
[Alias("Magnitude")]
[Polymorphic(true)]
public class Length : Node
{   
	public override (Pin[] In, Pin[] Out) InitialPins => (
        new Pin[] {
            Pin.New<Polymorphic>("V"),
        },
        
        new Pin[] {
            Pin.New<float>("|V|")
        }
    );

	public override Node Polymorph(PinWireChange change) =>
        PolymorphHelpers.ToConnectedTypeIfRegistered(typeof(Length<>), change);
}


[Register(typeof(Library.FloatVector))]
[Polymorphic(typeof(Length))]
public class Length<T> : Length
{
	public override (Pin[] In, Pin[] Out) InitialPins => base.InitialPins.SubstitutePolymorphic<T>();

	public override Node Polymorph(PinWireChange change) =>
        PolymorphHelpers.ToNonGenericIfAllDisconnected<Length>(change);

    public override void Evaluate() {
        var t = typeof(T);
        
        if (t == typeof(Vector2)) { SetOutput(0, GetInput<Vector2>(0).Length); return; }
        if (t == typeof(Vector3)) { SetOutput(0, GetInput<Vector3>(0).Length); return; }
        if (t == typeof(Vector4)) { SetOutput(0, GetInput<Vector4>(0).Length); return; }
        
        throw new NotImplementedException();
    }
}