private static void WriteCoordSetFunction(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT, string gmvTypeName, int groupIdx, int elementIdx, int groupSize, RefGA.BasisBlade B) { StringBuilder declSB = cgd.m_declSB; StringBuilder defSB = (S.m_inlineSet) ? cgd.m_inlineDefSB : cgd.m_defSB; String bladeName = B.ToLangString(S.m_basisVectorNames); string varName = "A"; string coordName = bladeName + "_coord"; // do we inline this func? string inlineStr = G25.CG.Shared.Util.GetInlineString(S, S.m_inlineSet, " "); string funcName = gmvTypeName + "_set_" + bladeName; string funcDecl = inlineStr + "void " + funcName + "(" + gmvTypeName + " *" + varName + ", " + FT.type + " " + coordName + ")"; declSB.AppendLine("/** Sets the " + B.ToString(S.m_basisVectorNames) + " coordinate of '" + varName + "' */"); declSB.Append(funcDecl); declSB.AppendLine(";"); defSB.AppendLine(""); defSB.Append(funcDecl); defSB.AppendLine(" {"); defSB.AppendLine("\t" + gmvTypeName + "_reserveGroup_" + groupIdx + "(" + varName + ");"); defSB.AppendLine("\t" + varName + "->c[" + S.m_namespace + "_mvSize[" + varName + "->gu & " + ((1 << groupIdx) - 1) + "] + " + elementIdx + "] = " + coordName + ";"); defSB.AppendLine("}"); }
/// <summary> /// Converts scalar part of 'value' to ouput language dependent string. /// </summary> private static string ScalarOpValueToLangString(G25.Specification S, G25.FloatType FT, RefGA.Multivector value) { if (!value.IsScalar()) throw new Exception("G25.CG.Shared.BasisBlade.ScalarOpValueToLangString(): value should be scalar, found: " + value.ToString(S.m_basisVectorNames)); if (value.IsZero()) return ScalarToLangString(S, FT, RefGA.BasisBlade.ZERO); else return ScalarToLangString(S, FT, value.BasisBlades[0]); }
private static void WriteCoordExtractFunction(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT, string gmvTypeName, int groupIdx, int elementIdx, RefGA.BasisBlade B) { StringBuilder declSB = cgd.m_declSB; StringBuilder defSB = (S.m_inlineSet) ? cgd.m_inlineDefSB : cgd.m_defSB; String bladeName = B.ToLangString(S.m_basisVectorNames); string varName = "A"; // do we inline this func? string inlineStr = G25.CG.Shared.Util.GetInlineString(S, S.m_inlineSet, " "); string funcName = gmvTypeName + "_" + bladeName; string funcDecl = inlineStr + FT.type + " " + funcName + "(const " + gmvTypeName + " *" + varName + ")"; string comment = "/** Returns the " + B.ToString(S.m_basisVectorNames) + " coordinate of '" + varName + "' */"; // declSB.AppendLine("/* group : " + groupIdx + " element: " + elementIdx + "*/"); declSB.AppendLine(comment); declSB.Append(funcDecl); declSB.AppendLine(";"); defSB.AppendLine(""); defSB.Append(funcDecl); defSB.AppendLine(" {"); defSB.AppendLine("\treturn (" + varName + "->gu & " + (1 << groupIdx) + ") ? " + varName + "->c[" + S.m_namespace + "_mvSize[" + varName + "->gu & " + ((1 << groupIdx) - 1) + "] + " + elementIdx + "] : " + FT.DoubleToString(S, 0.0) + ";"); defSB.AppendLine("}"); // add extract coord extract function for scalar if (B.Grade() == 0) { string floatFuncName = gmvTypeName + "_" + FT.type; string floatFuncDecl = inlineStr + FT.type + " " + floatFuncName + "(const " + gmvTypeName + " *" + varName + ")"; declSB.AppendLine(comment); declSB.Append(floatFuncDecl); declSB.AppendLine(";"); defSB.Append(floatFuncDecl); defSB.AppendLine(" {"); defSB.AppendLine("\treturn " + funcName + "(" + varName + ");"); defSB.AppendLine("}"); } }
/// <summary> /// Converts a RefGA.BasisBlade to a string for printout in the specification. /// The blade should have positive or negative 1 scale. A scalar basis blade /// is transformed into "scalar" or "-scalar". /// </summary> protected static string BasisBladeToString(RefGA.BasisBlade B, string[] bvNames) { String bbStr = B.ToString(bvNames); // convert "-1*" to "-", otherwise the string cannot be parsed back in again if (bbStr.StartsWith("-1*")) bbStr = "-" + bbStr.Substring(3); if (bbStr == "1") bbStr = "scalar"; if (bbStr == "-1") bbStr = "-scalar"; return bbStr; }