RoundUp


Node Information
Rounds the value to the next multiple of the specified factor.
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 TRUE
Factor IN Int32 ONE FALSE TRUE
Result OUT Int32 MULTIPLE FALSE FALSE

Source
namespace Korduene.KGraph.Nodes.Math
{
    [IsNode("RoundUp")]
    public class MathRoundUp : Node
    {
        Port val = new Port(PortType.IN, typeof(int), AcceptsLinks.ONE, "Value");
        Port fact = new Port(PortType.IN, typeof(int), AcceptsLinks.ONE, "Factor");
        Port res = new Port(PortType.OUT, typeof(int), AcceptsLinks.MULTIPLE, "Result");
        public MathRoundUp()
        {
            NodeType = KGraph.NodeType.Function;
            ReturnType = typeof(int);
            val.Value = "0";
            fact.Value = "0";
            res.Value = "0";
            this.Name = "RoundUp";
            this.AddPort(val);
            this.AddPort(fact);
            this.AddPort(res);
            val.CustomAcception = Accepts;
            fact.CustomAcception = Accepts;
            Information = "Rounds the value to the next multiple of the specified factor.";
        }
        private bool Accepts(Port port)
        {
            if (port == null)
            {
                return false;
            }
            if (val.IsConnected || fact.IsConnected || res.IsConnected)
            {
                if (port.DataType == val.DataType)
                {
                    return true;
                }
            }
            else if (GraphCore.IsNumeric(port.DataType))
            {
                ReturnType = port.DataType;
                val.DataType = port.DataType;
                val.Refresh();
                fact.DataType = port.DataType;
                fact.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 ff = GetValue(fact);
            return "var d = (" + vv + " % " + ff + "); return d == 0 ? " + vv + " : " + vv + "< 0="" "="" +="" vv="" +="" "="" -="" d="" :="" "="" +="" vv="" +="" "="" +="" ("="" +="" ff="" +="" "="" -="" d);";="" }="" }="" }="">