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


[Register]
[Tag("Math", "Vector")]
[Alias("MagnitudeSquared")]
[Polymorphic(true)]
public class LengthSquared : 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(LengthSquared<>), change);
}


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

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

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