Exemple #1
0
        /// <summary>
        /// Applies 'm_postOp m_postOpValue' to 'valueStr'.
        /// </summary>
        /// <param name="S">Specification of algebra.</param>
        /// <param name="cgd">Not used yet.</param>
        /// <param name="valueStr">The array of value strings to which the postop should be applied</param>
        /// <param name="BL">Not used yet. May be used later on to known what basis blade each valueStr refers to.</param>
        public void ApplyPostOp(Specification S, G25.CG.Shared.CGdata cgd, RefGA.BasisBlade[] BL, String[] valueStr)
        {
            if (m_postOp == null)
            {
                return;
            }

            // TODO: currently only for *= and /=

            // get string of value:
            string postOpValueStr;

            RefGA.Multivector sc = m_postOpValue.ScalarPart();
            if (sc.IsZero())
            {
                postOpValueStr = CodeUtil.ScalarToLangString(S, m_floatType, RefGA.BasisBlade.ZERO);
            }
            else
            {
                postOpValueStr = CodeUtil.ScalarToLangString(S, m_floatType, sc.BasisBlades[0]);
            }

            // apply "m_postOp postOpValueStr" to all valueStr
            for (int i = 0; i < valueStr.Length; i++)
            {
                valueStr[i] = "(" + valueStr[i] + ")" + m_postOp + ((m_mustCast) ? m_floatType.castStr : "") + "(" + postOpValueStr + ")";
            }
        }
Exemple #2
0
        } // end of GetAccessStr()

        /// <summary>
        /// Generates code for returning a scalar value. The input is a scalar-valued multivector.
        /// </summary>
        /// <param name="S">Specification (used for output language).</param>
        /// <param name="FT">Floating point type which must be returned.</param>
        /// <param name="mustCast">Set to true if the returned value must be cast to <c>FT</c>, that is
        /// if you are not sure that the multivector has the same float type as the return type <c>FT</c>.</param>
        /// <param name="value">The symbolic multivector value to be returned.</param>
        /// <returns>Code for returning a scalar value.</returns>
        public static string GenerateScalarReturnCode(Specification S, FloatType FT, bool mustCast, RefGA.Multivector value)
        {
            if (value.IsZero())
            {
                return("return " + FT.DoubleToString(S, 0.0) + ";");
            }
            else
            {
                return("return " +
                       ((mustCast) ? (FT.castStr + "(") : "") +
                       CodeUtil.ScalarToLangString(S, FT, value.BasisBlades[0]) +
                       ((mustCast) ? ")" : "") +
                       ";");
            }
        } // end of GenerateScalarReturnCode()
Exemple #3
0
        /// <summary>
        /// Generates code to assign <c>value</c> to a variable whose coordinate order is specified by <c>BL</c>.
        ///
        /// For example, <c>BL</c> could be <c>[e1, e2, e3]</c> and the multivector value <c>[e1 - 2e3]</c>.
        /// Then the returned array would be <c>["1", "0", "-2"]</c>.
        ///
        /// Parts of <c>value</c> that cannot be assigned to <c>BL</c> are silently ignored.
        ///
        /// Possibly, at some point we would like to generate some kind of warning?
        /// </summary>
        /// <param name="S">Specification of algebra (not used yet).</param>
        /// <param name="FT">Floating point type of assigned variable (used for casting strings).</param>
        /// <param name="mustCast">Set to true if a cast to 'FT' must be performed.</param>
        /// <param name="BL">Basis blades of assigned variable.</param>
        /// <param name="value">Multivector value to assign to the list of basis blades.
        /// Must not contain basis blades inside the symbolic scalars of the RefGA.BasisBlades.</param>
        /// <param name="writeZeros">When true, <c>"0"</c> will be returned when no value should be assigned
        /// to some coordinate. <c>null</c> otherwise.</param>
        /// <returns>An array of strings which tell you what to assign to each coordinate.</returns>
        public static String[] GetAssignmentStrings(Specification S, FloatType FT, bool mustCast, RefGA.BasisBlade[] BL,
                                                    RefGA.Multivector value, bool writeZeros)
        {
            String[] assignedStr = new String[BL.Length];
            int      idx         = 0;

            // for each non-const coord, find out what value is (loop through all entries in value)
            foreach (RefGA.BasisBlade B in BL)
            {
                // find same basisblade in 'value'
                foreach (RefGA.BasisBlade C in value.BasisBlades)
                {
                    if (C.bitmap == B.bitmap) // match found: get assignment string
                    {
                        // compute D = inverse(B) . C;
                        RefGA.BasisBlade Bi = (new RefGA.BasisBlade(B.bitmap, 1.0 / B.scale)).Reverse();
                        RefGA.BasisBlade D  = RefGA.BasisBlade.scp(Bi, C);

                        if (mustCast)
                        {
                            assignedStr[idx] = FT.castStr + "(" + CodeUtil.ScalarToLangString(S, FT, D) + ")";
                        }
                        else
                        {
                            assignedStr[idx] = CodeUtil.ScalarToLangString(S, FT, D);
                        }
                        break;
                    }
                }

                if (writeZeros && (assignedStr[idx] == null)) // has an assignment string been set?
                {
                    // no assignment: simply assign "0"
                    assignedStr[idx] = FT.DoubleToString(S, 0.0);
                }

                idx++;
            }
            return(assignedStr);
        } // end of GetAssignmentStrings()