コード例 #1
0
ファイル: EqnNode.cs プロジェクト: polytronicgr/netrix
 /// <summary>
 /// Creates a new Variable EqnNode with the number of the variable stored in the value field.
 /// </summary>
 /// <param name="Owner">the Owner-Shape</param>
 /// <param name="variable">the Variablenumber</param>
 public EqnNode(CommonShapeElement Owner, int variable)
 {
     owner = Owner;
     type  = EqnNodeType.Variable;
     val   = variable;
 }
コード例 #2
0
ファイル: EqnNode.cs プロジェクト: polytronicgr/netrix
 /// <summary>
 /// Creates a Undefined EqnNode
 /// </summary>
 /// <param name="Owner">the Owner-Shape</param>
 public EqnNode(CommonShapeElement Owner)
 {
     owner = Owner;
     type  = EqnNodeType.Undefined;
 }
コード例 #3
0
ファイル: EqnNode.cs プロジェクト: polytronicgr/netrix
 /// <summary>
 /// Creates a new Constant EqnNode with the value constant.
 /// </summary>
 /// <param name="Owner">the Owner-Shape</param>
 /// <param name="constant">the value for this EqnNode</param>
 public EqnNode(CommonShapeElement Owner, double constant)
 {
     owner = Owner;
     type  = EqnNodeType.Constant;
     val   = constant;
 }
コード例 #4
0
ファイル: EqnNode.cs プロジェクト: polytronicgr/netrix
        /// <summary>
        /// Parses the Eqn_string
        /// </summary>
        /// <param name="eqn">the Eqn</param>
        /// <returns>returns the unparsed part of the Eqn-String</returns>
        /// <remarks>This function is used recursive until the whole string is parsed</remarks>
        public string Parse(string eqn)
        {
            int    len = 0;
            string ret = null;

            // check for last token
            if (eqn == null)
            {
                throw new EqnParserException("Parse an eqn of null not possible!");
            }

            // split the tokens
            string[] token = eqn.Split(new char[] { ' ' }, 2);

            // switch operator
            type = EqnNodeType.Expression;
            switch (token[0].ToLower())
            {
            case "val":
                op  = Operation.Val;
                len = 1;
                break;

            case "sum":
                op  = Operation.Sum;
                len = 3;
                break;

            case "product":
                op  = Operation.Product;
                len = 3;
                break;

            case "mid":
                op  = Operation.Mid;
                len = 2;
                break;

            case "abs":
                op  = Operation.Abs;
                len = 2;
                break;

            case "min":
                op  = Operation.Min;
                len = 2;
                break;

            case "max":
                op  = Operation.Max;
                len = 2;
                break;

            case "if":
                op  = Operation.If;
                len = 3;
                break;

            case "mod":
                op  = Operation.Mod;
                len = 3;
                break;

            case "atan2":
                op  = Operation.Atan2;
                len = 2;
                break;

            case "sin":
                op  = Operation.Sin;
                len = 2;
                break;

            case "cos":
                op  = Operation.Cos;
                len = 2;
                break;

            case "cosatan2":
                op  = Operation.Cosatan2;
                len = 3;
                break;

            case "sinatan2":
                op  = Operation.Sinatan2;
                len = 3;
                break;

            case "sqrt":
                op  = Operation.Sqrt;
                len = 1;
                break;

            case "sumangle":
                op  = Operation.Sumangle;
                len = 3;
                break;

            case "ellipse":
                op  = Operation.Ellipse;
                len = 3;
                break;

            case "tan":
                op  = Operation.Tan;
                len = 2;
                break;

            default:
                if (token[0].StartsWith("@"))
                {
                    type = EqnNodeType.Equation;
                    val  = Convert.ToInt32(token[0].Trim('@'));
                }
                else if (token[0].StartsWith("#"))
                {
                    type = EqnNodeType.Adjustment;
                    val  = Convert.ToInt32(token[0].Trim('#'));
                }
                else
                {
                    type = EqnNodeType.Constant;
                    val  = Convert.ToDouble(token[0]);
                }
                break;
            }
            if (token.Length > 1)
            {
                ret = token[1].Trim();
            }
            if (len > 0)
            {
                param = new EqnNode[len];
                for (int i = 0; i < len; i++)
                {
                    param[i] = new EqnNode(this.owner);
                    ret      = param[i].Parse(ret);
                }
            }
            return(ret);
        }