コード例 #1
0
        private IElement ConvertToVector(IElement E)
        {
            if (this.nullCheck && E.AssociatedObjectValue is null)
            {
                return(E);
            }

            if (E is IVectorSpaceElement)
            {
                return(E);
            }

            if (E is IVector V)
            {
                return(VectorDefinition.Encapsulate(V.VectorElements, false, this));
            }

            if (E is ISet S)
            {
                return(VectorDefinition.Encapsulate(S.ChildElements, false, this));
            }

            if (this.nullCheck && E.AssociatedObjectValue is null)
            {
                return(E);
            }

            return(VectorDefinition.Encapsulate(new IElement[] { E }, false, this));
        }
コード例 #2
0
ファイル: ToVector.cs プロジェクト: xiaguoli/IoTGateway
        /// <summary>
        /// Evaluates the node, using the variables provided in the <paramref name="Variables"/> collection.
        /// </summary>
        /// <param name="Variables">Variables collection.</param>
        /// <returns>Result.</returns>
        public override IElement Evaluate(Variables Variables)
        {
            IElement E = this.op.Evaluate(Variables);

            if (E is IVectorSpaceElement)
            {
                return(E);
            }

            IVector V = E as IVector;

            if (V != null)
            {
                return(VectorDefinition.Encapsulate(V.VectorElements, false, this));
            }

            ISet S = E as ISet;

            if (S != null)
            {
                return(VectorDefinition.Encapsulate(S.ChildElements, false, this));
            }

            return(VectorDefinition.Encapsulate(new IElement[] { E }, false, this));
        }
コード例 #3
0
        /// <summary>
        /// Evaluates the operator on vector operands.
        /// </summary>
        /// <param name="Left">Left value.</param>
        /// <param name="Right">Right value.</param>
        /// <returns>Result</returns>
        public override IElement EvaluateVector(IVector Left, IVector Right)
        {
            if (Left.Dimension != Right.Dimension)
            {
                throw new ScriptRuntimeException("Vectors of different dimensions.", this);
            }

            LinkedList <IElement>  Elements = new LinkedList <IElement>();
            IEnumerator <IElement> e1       = Left.VectorElements.GetEnumerator();
            IEnumerator <IElement> e2       = Right.VectorElements.GetEnumerator();
            IElement v1;

            while (e1.MoveNext())
            {
                v1 = e1.Current;
                while (e2.MoveNext())
                {
                    Elements.AddLast(VectorDefinition.Encapsulate(new IElement[] { v1, e2.Current }, false, this));
                }

                e2.Reset();
            }

            return(VectorDefinition.Encapsulate(Elements, false, this));
        }
コード例 #4
0
        /// <summary>
        /// Evaluates the operator on vector operands.
        /// </summary>
        /// <param name="Left">Left value.</param>
        /// <param name="Right">Right value.</param>
        /// <returns>Result</returns>
        public override IElement EvaluateVector(IVector Left, IVector Right)
        {
            if (Left.Dimension != 3 || Right.Dimension != 3)
            {
                throw new ScriptRuntimeException("Cross product works on vectors of dimesion 3.", this);
            }

            if (Left is DoubleVector dv1 && Right is DoubleVector dv2)
            {
                double[] d1 = dv1.Values;
                double[] d2 = dv2.Values;

                return(new DoubleVector(new double[] { d1[1] * d2[2] - d1[2] * d2[1], d1[2] * d2[0] - d1[0] * d2[2], d1[0] * d2[1] - d1[1] * d2[0] }));
            }

            IElement[] v1 = new IElement[3];
            Left.VectorElements.CopyTo(v1, 0);

            IElement[] v2 = new IElement[3];
            Right.VectorElements.CopyTo(v2, 0);

            return(VectorDefinition.Encapsulate(new IElement[]
            {
                Operators.Arithmetics.Subtract.EvaluateSubtraction(
                    Operators.Arithmetics.Multiply.EvaluateMultiplication(v1[1], v2[2], this),
                    Operators.Arithmetics.Multiply.EvaluateMultiplication(v1[2], v2[1], this), this),
                Operators.Arithmetics.Subtract.EvaluateSubtraction(
                    Operators.Arithmetics.Multiply.EvaluateMultiplication(v1[2], v2[0], this),
                    Operators.Arithmetics.Multiply.EvaluateMultiplication(v1[0], v2[2], this), this),
                Operators.Arithmetics.Subtract.EvaluateSubtraction(
                    Operators.Arithmetics.Multiply.EvaluateMultiplication(v1[0], v2[1], this),
                    Operators.Arithmetics.Multiply.EvaluateMultiplication(v1[1], v2[0], this), this)
            }, false, this));
        }
コード例 #5
0
        /// <summary>
        /// Evaluates the node, using the variables provided in the <paramref name="Variables"/> collection.
        /// </summary>
        /// <param name="Variables">Variables collection.</param>
        /// <returns>Result.</returns>
        public override IElement Evaluate(Variables Variables)
        {
            IEnumerable <IElement> VectorElements;
            bool CanEncapsulateAsMatrix;

            if (this.right is null)
            {
                VectorElements         = null;
                CanEncapsulateAsMatrix = true;
            }
            else
            {
                IElement E = this.right.Evaluate(Variables);
                CanEncapsulateAsMatrix = (E is IMatrix);
                VectorElements         = ImplicitSet.GetSetMembers(E);

                if (VectorElements is null)
                {
                    throw new ScriptRuntimeException("Unable to evaluate vector elements.", this.right);
                }
            }

            IEnumerable <IElement> Elements = ImplicitSet.CalculateElements(this.left, VectorElements,
                                                                            this.setConditions, this.otherConditions, Variables);

            if (!(Elements is ICollection <IElement> Elements2))
            {
                Elements2 = new List <IElement>();

                foreach (IElement E in Elements)
                {
                    Elements2.Add(E);
                }
            }

            return(VectorDefinition.Encapsulate(Elements2, CanEncapsulateAsMatrix, this));
        }
コード例 #6
0
 /// <summary>
 /// Encapsulates the calculated elements.
 /// </summary>
 /// <param name="Elements">Elements to encapsulate.</param>
 /// <returns>Encapsulated element.</returns>
 protected virtual IElement Encapsulate(LinkedList <IElement> Elements)
 {
     return(VectorDefinition.Encapsulate(Elements, true, this));
 }