Clamp


Node Information
Returns the larger of the two numbers.
General Information
• This node doesn't have other available options.
• Some of the ports of this node can change their types and accept types automatically.
Visual
Visual

Ports
Text Type DataType Accepts IsList CustomAcception
Value IN Int32 ONE FALSE FALSE
A IN Int32 ONE FALSE TRUE
B IN Int32 ONE FALSE TRUE
Result OUT Int32 MULTIPLE FALSE FALSE

Source
namespace Korduene.KGraph.Nodes.Math
{
    [IsNode("Clamp")]
    public class MathClamp : Node
    {
        Port val = new Port(PortType.IN, typeof(int), AcceptsLinks.ONE, "Value");
        Port a = new Port(PortType.IN, typeof(int), AcceptsLinks.ONE, "A");
        Port b = new Port(PortType.IN, typeof(int), AcceptsLinks.ONE, "B");
        Port res = new Port(PortType.OUT, typeof(int), AcceptsLinks.MULTIPLE, "Result");
        public MathClamp()
        {
            NodeType = NodeType.Function;
            ReturnType = typeof(int);
            a.Value = "0";
            b.Value = "0";
            res.Value = "0";
            this.Name = "Clamp";
            AddPort(val);
            this.AddPort(a);
            this.AddPort(b);
            this.AddPort(res);
            Information = "Returns the larger of the two numbers.";
            a.CustomAcception = Accepts;
            b.CustomAcception = Accepts;
        }
        private bool Accepts(Port port)
        {
            if (port == null)
            {
                return false;
            }
            if (a.IsConnected || b.IsConnected || res.IsConnected)
            {
                if (port.DataType == a.DataType)
                {
                    return true;
                }
            }
            else if (GraphCore.IsNumeric(port.DataType))
            {
                ReturnType = port.DataType;
                a.DataType = port.DataType;
                a.Refresh();
                b.DataType = port.DataType;
                b.Refresh();
                res.DataType = port.DataType;
                res.Refresh();
                return true;
            }
            if (GraphCore.CanConvert(port.DataType, res.DataType))
            {
                return true;
            }
            return false;
        }
        public override string Code()
        {
            string vv = GetValue(val);
            string aa = GetValue(a);
            string bb = GetValue(b);
            return "return " + aa + "< "="" +="" bb="" +="" "="" system.math.min(system.math.max("="" +="" vv="" +="" ","="" +="" aa="" +="" "),="" "="" +="" bb="" +="" ")="" :="" system.math.max(system.math.min("="" +="" vv="" +="" ",="" "="" +="" aa="" +="" "),="" "="" +="" bb="" +="" ");";="" }="" }="" }="">