public Example1() : base() { try { Debug.WriteLine("--> Entered", this.m_Name + ".Example1()"); this.m_UPS = null; this.m_Scope = null; this.SetAttributeConfigDefaults(); this.m_SpeedOfLight = 299792458.0; this.m_SpacecraftMass = 1764.17; this.m_BusTerm = 0.0; this.m_SA_Term = 0.0; this.m_BP1Term = 0.0; this.m_BP2Term = 0.0; this.m_MsgCntr = -1; this.m_EvalMsgsOn = false; this.m_SunlightSRP = new Tuple3(0.0, 0.0, 0.0); } finally { Debug.WriteLine("<-- Exited", this.m_Name + ".Example1()"); } }
public static List <Tuple2 <Tuple3 <int> > > MakeSpace(Tuple3 <int> from, Tuple3 <int> to, Maze m, bool[, ,] map) { List <Tuple2 <Tuple3 <int> > > moves = new List <Tuple2 <Tuple3 <int> > > (); // Get space neighbours of offending block List <Tuple3 <int> > spaceNeighbours = m.GetSpaceNeighbours(to, map); if (spaceNeighbours.Count > 0) { // Move offending block into space Util.Move(to, spaceNeighbours [0], map); moves.Add(new Tuple2 <Tuple3 <int> > (to, spaceNeighbours [0])); return(moves); } else { // Recurse through block neighbours to get least amount of moves List <Tuple2 <Tuple3 <int> > > possibleMoves; int min = -1; List <Tuple3 <int> > blockNeighbours = m.GetBlockNeighbours(to, map); for (int i = 0; i < blockNeighbours.Count; ++i) { possibleMoves = MakeSpace(to, blockNeighbours [i], m, map); if (possibleMoves.Count < min || min == -1) { min = possibleMoves.Count; moves = possibleMoves; } } return(moves); } }
// Use this for initialization void Start() { _mazeReady = false; _mazeGraphReady = false; _maze = null; _currentPos = new Tuple3 <int> (0, 0, 0); }
private Access ParseAccess(out bool success) { var reskey = new Tuple2<int, string>(position, "Access"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as Access; } int errorCount = Errors.Count; Access access = null; access = ParseNameAccess(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(access, success, position);return access; } access = ParseKeyAccess(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(access, success, position);return access; } access = ParseMethodCall(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(access, success, position);return access; } access = ParseFunctionCall(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(access, success, position);return access; } return access; }
public TreeNode(T value, TreeNode <T> parent = null, Tuple3 <int> changeFrom = null, Tuple3 <int> changeTo = null) { this.value = value; this.parent = parent; this.level = parent == null ? 0 : parent.level + 1; this.changeFrom = changeFrom; this.changeTo = changeTo; }
public void setStartAndEndInfo(Tuple3 <Pos, WayReference, Vector3> startInfo, Tuple3 <Pos, WayReference, Vector3> endInfo, Setup.PersonSetup personality, Pos targetPos) { setWaypointsInfo(personality); path = Game.calculateCurrentPaths(startInfo.First, endInfo.First, null, wayPoints, false, true); walkPath = Misc.posToVector3(path); this.targetPos = targetPos; InformationHuman informationHuman = GetComponent <InformationHuman> (); PubSub.publish("TargetPOI(" + targetPos.Id + "):Add", informationHuman); if (path.Count == 1) { Destroy(gameObject); return; } // Rotate human... Pos pos1 = path [0]; Pos pos2 = path [1]; Pos lastPos = path [path.Count - 1]; Pos secondToLastPos = path [path.Count - 2]; WayReference startWay = startInfo.Second; if (personality != null && personality.startVector != null || startWay.hasNodes(pos1, pos2)) { walkPath.RemoveAt(0); path.RemoveAt(0); } walkPath.Insert(0, startInfo.Third); path.Insert(0, Game.createTmpPos(startInfo.Third)); endWay = endInfo.Second; if (endWay.hasNodes(secondToLastPos, lastPos)) { walkPath.RemoveAt(walkPath.Count - 1); path.RemoveAt(path.Count - 1); } walkPath.Add(endInfo.Third); path.Add(Game.createTmpPos(endInfo.Third)); // Adjust position to side of bigger ways adjustPositionsOnBiggerWays(path, walkPath, startWay, endWay); DebugFn.DebugPath(walkPath); Vector3 vec1 = walkPath [0]; Vector3 vec2 = walkPath [1]; positionHuman(vec1); rotateHuman(vec2, vec1); walkPath.RemoveAt(0); }
// Get's all neighbours that are blocks public List <Tuple3 <int> > GetBlockNeighbours(Tuple3 <int> location, bool[, ,] givenMap = null) { bool[, ,] checkMap; if (givenMap != null) { checkMap = givenMap; } else { checkMap = _blockMap; } int x = location.first; int y = location.second; int z = location.third; List <Tuple3 <int> > neighbours = new List <Tuple3 <int> > (); // Top if (y + 2 < mazeDimensions.second && !checkMap [x, y + 2, z]) { neighbours.Add(new Tuple3 <int>(x, y + 2, z)); } // Front if (z + 2 < mazeDimensions.third && !checkMap [x, y, z + 2]) { neighbours.Add(new Tuple3 <int>(x, y, z + 2)); } // Bottom if (y - 2 >= 0 && !checkMap [x, y - 2, z]) { neighbours.Add(new Tuple3 <int>(x, y - 2, z)); } // Left if (x - 2 >= 0 && !checkMap [x - 2, y, z]) { neighbours.Add(new Tuple3 <int>(x - 2, y, z)); } // Right if (x + 2 < mazeDimensions.first && !checkMap [x + 2, y, z]) { neighbours.Add(new Tuple3 <int>(x + 2, y, z)); } // Back if (z - 2 >= 0 && !checkMap [x, y, z - 2]) { neighbours.Add(new Tuple3 <int>(x, y, z - 2)); } return(neighbours); }
public static bool Move(Tuple3 <int> from, Tuple3 <int> to, bool[, ,] map) { if (map [from.first, from.second, from.third] != true || map [to.first, to.second, to.third] != false) { Console.Write("Error in boolean map moving"); return(false); } map [from.first, from.second, from.third] = true; map [to.first, to.second, to.third] = false; return(true); }
public override bool Equals(object obj) { // Check for null values and compare run-time types. if (obj == null || GetType() != obj.GetType()) { return(false); } Tuple3 <T> t = (Tuple3 <T>)obj; return(EqualityComparer <T> .Default.Equals(first, t.first) && EqualityComparer <T> .Default.Equals(second, t.second) && EqualityComparer <T> .Default.Equals(third, t.third)); }
double normalize(ref Tuple3 a) { double mag = magnitude(a); if (mag > 0.0) { a.x /= mag; a.y /= mag; a.z /= mag; } return(mag); }
// Maze Generation Algorithms public static void GrowingTree(Maze m) { List <Tuple3 <int> > blockList = new List <Tuple3 <int> >(); blockList.Add(new Tuple3 <int> (m.startingPosition.first, m.startingPosition.second, m.startingPosition.third)); Tuple3 <int> currentCell; int x, y, z; while (blockList.Count > 0) { currentCell = blockList [blockList.Count - 1]; x = currentCell.first; y = currentCell.second; z = currentCell.third; // Define true as empty space, false default as block m.Carve(x, y, z); // Get Unvisited Valid Neighbours List <Tuple3 <int> > neighbours = m.GetPotentialNeighbours(currentCell); // If no neighbours, remove cell if (neighbours.Count == 0) { //blockList.Remove (currentCell); for (int i = 0; i < blockList.Count; ++i) { if (blockList [i].first == currentCell.first && blockList[i].second == currentCell.second && blockList[i].third == currentCell.third) { blockList.RemoveAt(i); break; } } continue; } // Pick a (random) neighbour Random rand = new Random(); Tuple3 <int> newCell = neighbours[rand.Next(0, neighbours.Count)]; // Carve to it m.CarveTo(currentCell, newCell); // Add it to cell list blockList.Add(newCell); } // Carve out full faces for nicer maze // while(m.CarveFullFaces() > 0) {} }
// Get all potential neighbours to carve to, ie. it has no neighbouring cells that are already carved public List <Tuple3 <int> > GetPotentialNeighbours(Tuple3 <int> from) { List <Tuple3 <int> > neighbours = GetBlockNeighbours(from); // Check if neighbours are valid, ie. it has no neighbouring cells that are already carved for (int i = 0; i < neighbours.Count; ++i) { Tuple3 <int> n = neighbours [i]; if (HasSpaceNeighbours(from, n)) { neighbours.RemoveAt(i--); } } return(neighbours); }
private ShuffleAlgorithmMode _shuffleAlgorithmMode; // Shuffle Algorithm Mode set // Constructor public Maze(GameObject mazeParent, GameObject[] blockTypes, Tuple3 <int> dimensions, Tuple3 <int> startingPosition, MazeAlgorithmMode mazeAlgo = MazeAlgorithmMode.GrowingTree, ShuffleAlgorithmMode shuffleAlgo = ShuffleAlgorithmMode.AStar) { parent = mazeParent; parent.tag = "Maze"; rotating = false; mazeDimensions = dimensions; this.startingPosition = startingPosition; _blockTypes = blockTypes; _blockMaze = new Block[mazeDimensions.first, mazeDimensions.second, mazeDimensions.third]; _blockMap = new bool[mazeDimensions.first, mazeDimensions.second, mazeDimensions.third]; SetAlgorithm(mazeAlgo); SetShuffle(shuffleAlgo); }
private List<Expr> ParseArgList(out bool success) { var reskey = new Tuple2<int, string>(position, "ArgList"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as List<Expr>; } int errorCount = Errors.Count; List<Expr> list_Expr = new List<Expr>(); int start_position = position; MatchTerminal('(', out success); if (!success) { position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(list_Expr, success, position);return list_Expr; } ParseSpOpt(out success); while (true) { int seq_start_position1 = position; list_Expr = ParseExprList(out success); if (!success) { break; } ParseSpOpt(out success); break; } success = true; MatchTerminal(')', out success); if (!success) { Error("Failed to parse ')' of ArgList."); position = start_position; } if (success) { ClearError(errorCount); } ParsingResults[reskey] = new Tuple3<object, bool, int>(list_Expr, success, position); return list_Expr; }
// Returns true if the location has neighbours that are spaces public bool HasSpaceNeighbours(Tuple3 <int> from, Tuple3 <int> location) { int x = location.first; int y = location.second; int z = location.third; // Top if (y + 2 < mazeDimensions.second && _blockMap [x, y + 2, z] && !from.Equals(new Tuple3 <int>(x, y + 2, z))) { return(true); } // Front if (z + 2 < mazeDimensions.third && _blockMap [x, y, z + 2] && !from.Equals(new Tuple3 <int>(x, y, z + 2))) { return(true); } // Bottom if (y - 2 >= 0 && _blockMap [x, y - 2, z] && !from.Equals(new Tuple3 <int>(x, y - 2, z))) { return(true); } // Left if (x - 2 >= 0 && _blockMap [x - 2, y, z] && !from.Equals(new Tuple3 <int>(x - 2, y, z))) { return(true); } // Right if (x + 2 < mazeDimensions.first && _blockMap [x + 2, y, z] && !from.Equals(new Tuple3 <int>(x + 2, y, z))) { return(true); } // Back if (z - 2 >= 0 && _blockMap [x, y, z - 2] && !from.Equals(new Tuple3 <int>(x, y, z - 2))) { return(true); } return(false); }
// Carve to a location (Since 1 block thickness between each carveable block) public bool CarveTo(Tuple3 <int> from, Tuple3 <int> to) { int xdiff = to.first - from.first; int ydiff = to.second - from.second; int zdiff = to.third - from.third; if (xdiff != 0) { if (xdiff > 0) //To the right { _blockMap[from.first + 1, from.second, from.third] = true; } else //To the left { _blockMap[from.first - 1, from.second, from.third] = true; } } else if (ydiff != 0) { if (ydiff > 0) //Up { _blockMap[from.first, from.second + 1, from.third] = true; } else //Down { _blockMap [from.first, from.second - 1, from.third] = true; } } else //if (zdiff != 0) { { if (zdiff > 0) //Towards screen { _blockMap[from.first, from.second, from.third + 1] = true; } else //Away { _blockMap[from.first, from.second, from.third - 1] = true; } } _blockMap [to.first, to.second, to.third] = true; return(true); }
private static Tuple3 <Pos, WayReference, Vector3> GetHumanSpawnInfo(long nodeId) { Pos spawnPos = nodes [nodeId]; // Position to spawn/despawn Pos spawnNode; WayReference closestWay = null; Vector3 closestPoint = Vector3.zero; if (NodeIndex.nodeWayWalkPathIndex.ContainsKey(spawnPos.Id)) { // Spawn in a node spawnNode = spawnPos; closestWay = NodeIndex.nodeWayWalkPathIndex [spawnPos.Id] [0]; closestPoint = Game.getCameraPosition(spawnNode); } else { // Calculate which node is closest spawnNode = PosHelper.getClosestNode(spawnPos, NodeIndex.walkNodes); // Pick closest wayReference Vector3 spawnPosVector = Game.getCameraPosition(spawnPos); float closestDistance = float.MaxValue; List <WayReference> ways = NodeIndex.nodeWayIndex [spawnNode.Id]; foreach (WayReference way in ways) { Vector3 wayStart = Game.getCameraPosition(way.node1); Vector3 wayEnd = Game.getCameraPosition(way.node2); Vector3 projectedPoint = Math3d.ProjectPointOnLineSegment(wayStart, wayEnd, spawnPosVector); float distance = PosHelper.getVectorDistance(spawnPosVector, projectedPoint); if (distance < closestDistance) { closestDistance = distance; closestWay = way; closestPoint = projectedPoint; } } // DebugFn.arrow (spawnPosVector, closestPoint); } // DebugFn.square (closestPoint); return(Tuple3.New(spawnNode, closestWay, closestPoint)); }
public void setMetaData(Tuple3 <string, string, int> achievementData, string type) { // Update achievement label Transform labelTransform = Misc.FindDeepChild(transform, "Label"); Text labelText = labelTransform.GetComponent <Text> (); labelText.text = achievementData.First; // Update achievement sublabel Transform subLabelTransform = Misc.FindDeepChild(transform, "SubLabel"); Text subLabelText = subLabelTransform.GetComponent <Text> (); subLabelText.text = achievementData.Second; // Update achievement points Transform pointsTransform = Misc.FindDeepChild(transform, "Points"); Text pointsText = pointsTransform.GetComponentInChildren <Text> (); pointsText.text = "" + achievementData.Third; switch (type) { case "unfulfilled": labelText.color = unfulfilledColor; subLabelText.color = unfulfilledColor; pointsText.color = unfulfilledColor; break; case "secret": labelText.color = secretColor; subLabelText.color = secretColor; pointsText.color = secretColor; break; case "fulfilled": default: labelText.color = fulfilledColor; subLabelText.color = fulfilledColor; pointsText.color = fulfilledColor; break; } }
private BoolLiteral ParseBoolLiteral(out bool success) { var reskey = new Tuple2<int, string>(position, "BoolLiteral"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as BoolLiteral; } int errorCount = Errors.Count; ErrorStatck.Push(errorCount); errorCount = Errors.Count; BoolLiteral boolLiteral = new BoolLiteral(); while (true) { boolLiteral.Text = MatchTerminalString("true", out success); if (success) { ClearError(errorCount); break; } boolLiteral.Text = MatchTerminalString("false", out success); if (success) { ClearError(errorCount); break; } break; } errorCount = ErrorStatck.Pop(); if (success) { ClearError(errorCount); } else { Error("Failed to parse Text of BoolLiteral."); } ParsingResults[reskey] = new Tuple3<object, bool, int>(boolLiteral, success, position); return boolLiteral; }
private VariableArg ParseVariableArg(out bool success) { var reskey = new Tuple2<int, string>(position, "VariableArg"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as VariableArg; } int errorCount = Errors.Count; VariableArg variableArg = new VariableArg(); variableArg.Name = MatchTerminalString("...", out success); if (success) { ClearError(errorCount); } else { Error("Failed to parse Name of VariableArg."); } ParsingResults[reskey] = new Tuple3<object, bool, int>(variableArg, success, position); return variableArg; }
private string ParseUnaryOperator(out bool success) { var reskey = new Tuple2<int, string>(position, "UnaryOperator"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as string; } int errorCount = Errors.Count; StringBuilder text = new StringBuilder(); char ch = MatchTerminal('#', out success); if (success) { ClearError(errorCount); text.Append(ch); ParsingResults[reskey] = new Tuple3<object, bool, int>(text.ToString(), success, position);return text.ToString(); } ch = MatchTerminal('-', out success); if (success) { ClearError(errorCount); text.Append(ch); ParsingResults[reskey] = new Tuple3<object, bool, int>(text.ToString(), success, position);return text.ToString(); } string str = MatchTerminalString("not", out success); if (success) { ClearError(errorCount); text.Append(str); ParsingResults[reskey] = new Tuple3<object, bool, int>(text.ToString(), success, position);return text.ToString(); } return text.ToString(); }
private TableConstructor ParseTableConstructor(out bool success) { var reskey = new Tuple2<int, string>(position, "TableConstructor"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as TableConstructor; } int errorCount = Errors.Count; TableConstructor tableConstructor = new TableConstructor(); int start_position = position; MatchTerminal('{', out success); if (!success) { position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(tableConstructor, success, position);return tableConstructor; } ParseSpOpt(out success); tableConstructor.FieldList = ParseFieldList(out success); success = true; MatchTerminal('}', out success); if (!success) { Error("Failed to parse '}' of TableConstructor."); position = start_position; } if (success) { ClearError(errorCount); } ParsingResults[reskey] = new Tuple3<object, bool, int>(tableConstructor, success, position); return tableConstructor; }
public static Vector3 TupleToVector(Tuple3 <int> t) { return(new Vector3(t.first, t.second, t.third)); }
private Field ParseField(out bool success) { var reskey = new Tuple2<int, string>(position, "Field"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as Field; } int errorCount = Errors.Count; Field field = null; field = ParseKeyValue(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(field, success, position);return field; } field = ParseNameValue(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(field, success, position);return field; } field = ParseItemValue(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(field, success, position);return field; } return field; }
private ElseifBlock ParseElseifBlock(out bool success) { var reskey = new Tuple2<int, string>(position, "ElseifBlock"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as ElseifBlock; } int errorCount = Errors.Count; ElseifBlock elseifBlock = new ElseifBlock(); int start_position = position; MatchTerminalString("elseif", out success); if (!success) { position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(elseifBlock, success, position);return elseifBlock; } ParseSpReq(out success); if (!success) { Error("Failed to parse SpReq of ElseifBlock."); position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(elseifBlock, success, position);return elseifBlock; } elseifBlock.Condition = ParseExpr(out success); if (!success) { Error("Failed to parse Condition of ElseifBlock."); position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(elseifBlock, success, position);return elseifBlock; } MatchTerminalString("then", out success); if (!success) { Error("Failed to parse 'then' of ElseifBlock."); position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(elseifBlock, success, position);return elseifBlock; } ParseSpReq(out success); if (!success) { Error("Failed to parse SpReq of ElseifBlock."); position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(elseifBlock, success, position);return elseifBlock; } elseifBlock.ThenBlock = ParseChunk(out success); if (!success) { Error("Failed to parse ThenBlock of ElseifBlock."); position = start_position; } if (success) { ClearError(errorCount); } ParsingResults[reskey] = new Tuple3<object, bool, int>(elseifBlock, success, position); return elseifBlock; }
public bool HasBlock(Tuple3 <int> t) { return(HasBlock(t.first, t.second, t.third)); }
double magnitude(Tuple3 a) { double mag = Math.Sqrt(dotProduct(a, a)); return(mag); }
double dotProduct(Tuple3 a, Tuple3 b) { double dotp = a.x * b.x + a.y * b.y + a.z * b.z; return(dotp); }
public Block GetBlock(Tuple3 <int> t) { return(_blockMaze [t.first, t.second, t.third]); }
private void computeSRP(double illum, double cr, double solarFlux, Tuple3 pos, Tuple3 vel, Tuple3 sunPos, ref Tuple3 sunlightSRP, ref Tuple3 sailingSRP) { // // Begin computation of SRP using the Pechenick model // // Compute some reference vectors Tuple3 w = new Tuple3(); // compute unit_w crossProduct(pos, vel, ref w); normalize(ref w); // compute unit_r Tuple3 r = new Tuple3(pos); normalize(ref r); // compute unit_k Tuple3 k = new Tuple3(sunPos); double distance_SunToSat = normalize(ref k); k.scaleBy(-1.0); //DebugMsg("DistSun "+distance_SunToSat); //DebugMsg("k : ("+k.x+", "+k.y+", "+k.z+")"); // compute unit_c Tuple3 c = new Tuple3(); crossProduct(w, k, ref c); normalize(ref c); // unit vector in orbit plane in plane of solar array (c_hat) // compute unit_n Tuple3 n = new Tuple3(); crossProduct(w, c, ref n); normalize(ref n); // unit vector in orbit plane normal to solar panel face towards sun // (solar panel faces sun_to_sat direction) //DebugMsg("n : ("+n.x+", "+n.y+", "+n.z+")"); // compute unit_m Tuple3 m = new Tuple3(r); double dotP = dotProduct(r, k); if (dotP >= 0.0) { dotP = -1.0; } else { dotP = 1.0; } m.scaleBy(dotP); //DebugMsg("m : ("+m.x+", "+m.y+", "+m.z+")"); Tuple3 temp = new Tuple3(); // temp vector //compute k x (k x n) Tuple3 kkn = new Tuple3(); crossProduct(k, n, ref temp); crossProduct(k, temp, ref kkn); //DebugMsg("kkn : ("+kkn.x+", "+kkn.y+", "+kkn.z+")"); //compute k x (k x m) Tuple3 kkm = new Tuple3(); crossProduct(k, m, ref temp); crossProduct(k, temp, ref kkm); //DebugMsg("kkm : ("+kkm.x+", "+kkm.y+", "+kkm.z+")"); // compute angles double CosAlpha = -1.0 * dotProduct(n, k); // n_hat and k_hat are almost anti-aligned double Cos2Alpha = 2.0 * CosAlpha * CosAlpha - 1.0; double CosAlphaStar = -1.0 * dotProduct(m, k); double Cos2AlphaStar = 2.0 * CosAlphaStar * CosAlphaStar - 1.0; //DebugMsg("Cos(alpha) = "+CosAlpha+", Cos(alphaStar) = "+cosAlphaStar); // compute some aux qtys // NOTE: we are using the formulas here with the app providing Luminosity (thru the solar flux value), // Mass, Cr, spacecraft mass, speed of light. Thus, the value for B_tilde_P_i and C_tilde // from the paper will be computed on the fly, rather than being assumed constant // // Also, there is a typo in formula (3.1) on page 5: in that formula, r // means magnitude(sun_to_Sat_vector) // NOTE: Cr is applied only to the k direction, not kkn nor kkm double C_Term = cr * illum * solarFlux * (m_BusTerm + 2 * m_SA_Term); double B_P_1_Term = illum * solarFlux * m_BP1Term; double B_P_2_Term = illum * solarFlux * m_BP2Term; double tempVal; // compute sailing srp contributions tempVal = B_P_1_Term * CosAlpha * (2.0 + m_SpecularReflectivity * (6.0 * CosAlpha - 2.0)); Tuple3 B_P_1_Term_Contrib_kkn = new Tuple3(kkn); B_P_1_Term_Contrib_kkn.scaleBy(tempVal); tempVal = B_P_2_Term * CosAlphaStar * (2.0 + m_SpecularReflectivity * (6.0 * CosAlphaStar - 2.0)); Tuple3 B_P_2_Term_Contrib_kkm = new Tuple3(kkm); B_P_2_Term_Contrib_kkm.scaleBy(tempVal); sailingSRP.scaleBy(0.0); sailingSRP.addTo(B_P_1_Term_Contrib_kkn); sailingSRP.addTo(B_P_2_Term_Contrib_kkm); DebugMsg("Sailing SRP = (" + sailingSRP.x + ", " + sailingSRP.y + ", " + sailingSRP.z + ")"); // compute sunlight srp contributions Tuple3 C_Term_Contrib = new Tuple3(k); C_Term_Contrib.scaleBy(C_Term); tempVal = cr * B_P_1_Term * CosAlpha * ((3.0 + 2.0 * CosAlpha) + m_SpecularReflectivity * (3.0 * Cos2Alpha - 2.0 * CosAlpha)); Tuple3 B_P_1_Term_Contrib_k = new Tuple3(k); B_P_1_Term_Contrib_k.scaleBy(tempVal); tempVal = cr * B_P_2_Term * CosAlphaStar * ((3.0 + 2.0 * CosAlphaStar) + m_SpecularReflectivity * (3.0 * Cos2AlphaStar - 2.0 * CosAlphaStar)); Tuple3 B_P_2_Term_Contrib_k = new Tuple3(k); B_P_2_Term_Contrib_k.scaleBy(tempVal); sunlightSRP.scaleBy(0.0); sunlightSRP.addTo(C_Term_Contrib); sunlightSRP.addTo(B_P_1_Term_Contrib_k); sunlightSRP.addTo(B_P_2_Term_Contrib_k); DebugMsg("Sunlight SRP = (" + sunlightSRP.x + ", " + sunlightSRP.y + ", " + sunlightSRP.z + ")"); }
public bool Evaluate(IAgAsHpopPluginResultEval ResultEval) { try { if (this.m_MsgCntr % this.m_MsgInterval == 0) { Debug.WriteLine("--> Entered", this.m_Name + ".Evaluate( " + this.m_MsgCntr + " )"); } if (m_Enabled) { // if illumination is zero, there isn't any contribution anyway, so do nothing // SRP must be on else this call throws an exception double illum = ResultEval.SolarIntensity; if (illum == 0.0) { return(m_Enabled); } double cr = ResultEval.Cr; // SRP must be on else this call throws an exception double solarFlux = ResultEval.SolarFlux; // L /(4 * pi * R_sun^2) Tuple3 r = new Tuple3(); Tuple3 v = new Tuple3(); Tuple3 sunPos = new Tuple3(); ResultEval.PosVel(AgEUtFrame.eUtFrameInertial, ref r.x, ref r.y, ref r.z, ref v.x, ref v.y, ref v.z); // SRP must be on else this call throws an exception because of AgEUtSunPosType.eUtSunPosTypeSRP ResultEval.SunPosition(AgEUtSunPosType.eUtSunPosTypeSRP, AgEUtFrame.eUtFrameInertial, ref sunPos.x, ref sunPos.y, ref sunPos.z); Tuple3 sailingSRP = new Tuple3(); computeSRP(illum, cr, solarFlux, r, v, sunPos, ref m_SunlightSRP, ref sailingSRP); // For OD to be able to estimate Cr, we need HPOP to compute SRP itself (i.e., the sunlight portion) // but of course we want HPOP to compute the value that we just computed // // THUS, for the sunlight portion, we'll modify the SRPArea to make this happen double magnitude = dotProduct(m_SunlightSRP, m_SunlightSRP); magnitude = Math.Sqrt(magnitude); ResultEval.SRPArea = magnitude / (cr * solarFlux * illum / (m_SpacecraftMass * m_SpeedOfLight)); // add sailing SRP contribution ResultEval.AddAcceleration(AgEUtFrame.eUtFrameInertial, sailingSRP.x, sailingSRP.y, sailingSRP.z); } } catch (Exception ex) { this.m_Enabled = false; Message(AgEUtLogMsgType.eUtLogMsgAlarm, this.m_Name + ".Evaluate(): Exception Message( " + ex.Message + " )"); Message(AgEUtLogMsgType.eUtLogMsgAlarm, this.m_Name + ".Evaluate(): Exception StackTr( " + ex.StackTrace + " )"); Debug.WriteLine("Exception Message( " + ex.Message + " )", this.m_Name + ".Evaluate()"); Debug.WriteLine("Exception StackTr( " + ex.StackTrace + " )", this.m_Name + ".Evaluate()"); } finally { if (this.m_MsgCntr % this.m_MsgInterval == 0) { Debug.WriteLine("<-- Exited", this.m_Name + ".Evaluate()"); } } return(this.m_Enabled); }
private Chunk ParseChunk(out bool success) { var reskey = new Tuple2<int, string>(position, "Chunk"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as Chunk; } int errorCount = Errors.Count; Chunk chunk = new Chunk(); int start_position = position; ParseSpOpt(out success); while (true) { while (true) { int seq_start_position1 = position; Statement statement = ParseStatement(out success); if (success) { chunk.Statements.Add(statement); } else { break; } while (true) { int seq_start_position2 = position; MatchTerminal(';', out success); if (!success) { break; } ParseSpOpt(out success); break; } success = true; break; } if (!success) { break; } } success = true; ParsingResults[reskey] = new Tuple3<object, bool, int>(chunk, success, position); return chunk; }
private DoStmt ParseDoStmt(out bool success) { var reskey = new Tuple2<int, string>(position, "DoStmt"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as DoStmt; } int errorCount = Errors.Count; DoStmt doStmt = new DoStmt(); int start_position = position; MatchTerminalString("do", out success); if (!success) { position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(doStmt, success, position);return doStmt; } ParseSpReq(out success); if (!success) { Error("Failed to parse SpReq of DoStmt."); position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(doStmt, success, position);return doStmt; } doStmt.Body = ParseChunk(out success); if (!success) { Error("Failed to parse Body of DoStmt."); position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(doStmt, success, position);return doStmt; } MatchTerminalString("end", out success); if (!success) { Error("Failed to parse 'end' of DoStmt."); position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(doStmt, success, position);return doStmt; } ParseSpReq(out success); if (!success) { Error("Failed to parse SpReq of DoStmt."); position = start_position; } if (success) { ClearError(errorCount); } ParsingResults[reskey] = new Tuple3<object, bool, int>(doStmt, success, position); return doStmt; }
void crossProduct(Tuple3 a, Tuple3 b, ref Tuple3 c) { c.x = a.y * b.z - a.z * b.y; c.y = a.z * b.x - a.x * b.z; c.z = a.x * b.y - a.y * b.x; }
private List<Expr> ParseExprList(out bool success) { var reskey = new Tuple2<int, string>(position, "ExprList"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as List<Expr>; } int errorCount = Errors.Count; List<Expr> list_Expr = new List<Expr>(); int start_position = position; Expr expr = ParseExpr(out success); if (success) { list_Expr.Add(expr); } else { position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(list_Expr, success, position);return list_Expr; } while (true) { while (true) { int seq_start_position1 = position; ParseSpOpt(out success); MatchTerminal(',', out success); if (!success) { Error("Failed to parse ',' of ExprList."); position = seq_start_position1; break; } ParseSpOpt(out success); expr = ParseExpr(out success); if (success) { list_Expr.Add(expr); } else { Error("Failed to parse Expr of ExprList."); position = seq_start_position1; } break; } if (!success) { break; } } success = true; ParsingResults[reskey] = new Tuple3<object, bool, int>(list_Expr, success, position); return list_Expr; }
private bool setSphericalReflectanceUsingFrame(AgAsLightReflectionResultEval ResultEval, double cr, AgEUtFrame frame) { double reflectanceMag; Tuple3 incidentVec = new Tuple3(); ResultEval.IncidentDirection((AgEUtFrame)frame, ref incidentVec.x, ref incidentVec.y, ref incidentVec.z); // reflectance is positive along the incident direction incidentVec.scaleBy(m_SRPArea); if (m_CrIndex > -1) { ResultEval.SetReflectanceParamPartials(m_CrIndex, frame, incidentVec.x, incidentVec.y, incidentVec.z); } incidentVec.scaleBy(cr); ResultEval.SetReflectance((AgEUtFrame)frame, incidentVec.x, incidentVec.y, incidentVec.z); double[,] incidentDirPosPartials, posPartials; incidentDirPosPartials = new double[3, 3]; posPartials = new double[3, 3]; ResultEval.IncidentDirectionCompPosPartials((AgEUtFrame)frame, ref incidentDirPosPartials[0, 0], ref incidentDirPosPartials[0, 1], ref incidentDirPosPartials[0, 2], ref incidentDirPosPartials[1, 0], ref incidentDirPosPartials[1, 1], ref incidentDirPosPartials[1, 2], ref incidentDirPosPartials[2, 0], ref incidentDirPosPartials[2, 1], ref incidentDirPosPartials[2, 2]); reflectanceMag = cr * m_SRPArea; posPartials[0, 0] = reflectanceMag * incidentDirPosPartials[0, 0]; posPartials[0, 1] = reflectanceMag * incidentDirPosPartials[0, 1]; posPartials[0, 2] = reflectanceMag * incidentDirPosPartials[0, 2]; posPartials[1, 0] = reflectanceMag * incidentDirPosPartials[1, 0]; posPartials[1, 1] = reflectanceMag * incidentDirPosPartials[1, 1]; posPartials[1, 2] = reflectanceMag * incidentDirPosPartials[1, 2]; posPartials[2, 0] = reflectanceMag * incidentDirPosPartials[2, 0]; posPartials[2, 1] = reflectanceMag * incidentDirPosPartials[2, 1]; posPartials[2, 2] = reflectanceMag * incidentDirPosPartials[2, 2]; ResultEval.SetReflectanceCompPosPartials((AgEUtFrame)frame, posPartials[0, 0], posPartials[0, 1], posPartials[0, 2], posPartials[1, 0], posPartials[1, 1], posPartials[1, 2], posPartials[2, 0], posPartials[2, 1], posPartials[2, 2]); // VelPartials are zero in inertial - we'll set this anyway to test it bool doVelPartials = true; if (doVelPartials) { double[,] incidentDirVelPartials, velPartials; incidentDirVelPartials = new double[3, 3]; velPartials = new double[3, 3];; ResultEval.IncidentDirectionCompVelPartials((AgEUtFrame)frame, ref incidentDirVelPartials[0, 0], ref incidentDirVelPartials[0, 1], ref incidentDirVelPartials[0, 2], ref incidentDirVelPartials[1, 0], ref incidentDirVelPartials[1, 1], ref incidentDirVelPartials[1, 2], ref incidentDirVelPartials[2, 0], ref incidentDirVelPartials[2, 1], ref incidentDirVelPartials[2, 2]); velPartials[0, 0] = reflectanceMag * incidentDirVelPartials[0, 0]; velPartials[0, 1] = reflectanceMag * incidentDirVelPartials[0, 1]; velPartials[0, 2] = reflectanceMag * incidentDirVelPartials[0, 2]; velPartials[1, 0] = reflectanceMag * incidentDirVelPartials[1, 0]; velPartials[1, 1] = reflectanceMag * incidentDirVelPartials[1, 1]; velPartials[1, 2] = reflectanceMag * incidentDirVelPartials[1, 2]; velPartials[2, 0] = reflectanceMag * incidentDirVelPartials[2, 0]; velPartials[2, 1] = reflectanceMag * incidentDirVelPartials[2, 1]; velPartials[2, 2] = reflectanceMag * incidentDirVelPartials[2, 2]; ResultEval.SetReflectanceCompVelPartials((AgEUtFrame)frame, velPartials[0, 0], velPartials[0, 1], velPartials[0, 2], velPartials[1, 0], velPartials[1, 1], velPartials[1, 2], velPartials[2, 0], velPartials[2, 1], velPartials[2, 2]); } Debug.WriteLine(m_MsgCntr + " " + cr + " : frame = Body : (" + incidentVec.x + "," + incidentVec.y + "," + incidentVec.z + ")"); return(true); }
private string ParseFoatNumber(out bool success) { var reskey = new Tuple2<int, string>(position, "FoatNumber"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as string; } int errorCount = Errors.Count; StringBuilder text = new StringBuilder(); int start_position = position; int counter = 0; while (true) { char ch = ParseDigit(out success); if (success) { text.Append(ch); } else { break; } counter++; } if (counter > 0) { success = true; } if (!success) { position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(text.ToString(), success, position);return text.ToString(); } while (true) { int seq_start_position1 = position; char ch = MatchTerminal('.', out success); if (success) { text.Append(ch); } else { break; } counter = 0; while (true) { ch = ParseDigit(out success); if (success) { text.Append(ch); } else { break; } counter++; } if (counter > 0) { success = true; } if (!success) { Error("Failed to parse (Digit)+ of FoatNumber."); position = seq_start_position1; } break; } success = true; while (true) { ErrorStatck.Push(errorCount); errorCount = Errors.Count; int seq_start_position2 = position; while (true) { char ch = MatchTerminal('e', out success); if (success) { ClearError(errorCount); text.Append(ch); break; } ch = MatchTerminal('E', out success); if (success) { ClearError(errorCount); text.Append(ch); break; } break; } errorCount = ErrorStatck.Pop(); if (!success) { break; } counter = 0; while (true) { char ch = ParseDigit(out success); if (success) { text.Append(ch); } else { break; } counter++; } if (counter > 0) { success = true; } if (!success) { Error("Failed to parse (Digit)+ of FoatNumber."); position = seq_start_position2; } break; } success = true; ParsingResults[reskey] = new Tuple3<object, bool, int>(text.ToString(), success, position); return text.ToString(); }
public Tuple3(Tuple3 a) { x = a.x; y = a.y; z = a.z; }
private StringLiteral ParseStringLiteral(out bool success) { var reskey = new Tuple2<int, string>(position, "StringLiteral"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as StringLiteral; } int errorCount = Errors.Count; StringLiteral stringLiteral = new StringLiteral(); while (true) { int seq_start_position1 = position; MatchTerminal('"', out success); if (!success) { break; } stringLiteral.Text = ParseDoubleQuotedText(out success); MatchTerminal('"', out success); if (!success) { Error("Failed to parse '\\\"' of StringLiteral."); position = seq_start_position1; } break; } if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(stringLiteral, success, position);return stringLiteral; } while (true) { int seq_start_position2 = position; MatchTerminal('\'', out success); if (!success) { break; } stringLiteral.Text = ParseSingleQuotedText(out success); MatchTerminal('\'', out success); if (!success) { Error("Failed to parse ''' of StringLiteral."); position = seq_start_position2; } break; } if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(stringLiteral, success, position);return stringLiteral; } stringLiteral.Text = ParseLongString(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(stringLiteral, success, position);return stringLiteral; } return stringLiteral; }
public void addTo(Tuple3 a) { x += a.x; y += a.y; z += a.z; }
private Term ParseTerm(out bool success) { var reskey = new Tuple2<int, string>(position, "Term"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as Term; } int errorCount = Errors.Count; Term term = null; term = ParseNilLiteral(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(term, success, position);return term; } term = ParseBoolLiteral(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(term, success, position);return term; } term = ParseNumberLiteral(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(term, success, position);return term; } term = ParseStringLiteral(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(term, success, position);return term; } term = ParseFunctionValue(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(term, success, position);return term; } term = ParseTableConstructor(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(term, success, position);return term; } term = ParseVariableArg(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(term, success, position);return term; } term = ParsePrimaryExpr(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(term, success, position);return term; } return term; }
public bool PlaceBlock(Block b, Tuple3 <int> location) { return(PlaceBlock(b, location.first, location.second, location.third)); }
private Var ParseVar(out bool success) { var reskey = new Tuple2<int, string>(position, "Var"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as Var; } int errorCount = Errors.Count; Var var = new Var(); int start_position = position; var.Base = ParseBaseExpr(out success); if (!success) { position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(var, success, position);return var; } while (true) { ErrorStatck.Push(errorCount); errorCount = Errors.Count; while (true) { while (true) { int seq_start_position1 = position; ParseSpOpt(out success); NameAccess nameAccess = ParseNameAccess(out success); if (success) { var.Accesses.Add(nameAccess); } else { Error("Failed to parse NameAccess of Var."); position = seq_start_position1; } break; } if (success) { ClearError(errorCount); break; } while (true) { int seq_start_position2 = position; ParseSpOpt(out success); KeyAccess keyAccess = ParseKeyAccess(out success); if (success) { var.Accesses.Add(keyAccess); } else { Error("Failed to parse KeyAccess of Var."); position = seq_start_position2; } break; } if (success) { ClearError(errorCount); break; } break; } errorCount = ErrorStatck.Pop(); if (!success) { break; } } success = true; ParsingResults[reskey] = new Tuple3<object, bool, int>(var, success, position); return var; }
private NilLiteral ParseNilLiteral(out bool success) { var reskey = new Tuple2<int, string>(position, "NilLiteral"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as NilLiteral; } int errorCount = Errors.Count; NilLiteral nilLiteral = new NilLiteral(); MatchTerminalString("nil", out success); if (success) { ClearError(errorCount); } else { Error("Failed to parse 'nil' of NilLiteral."); } ParsingResults[reskey] = new Tuple3<object, bool, int>(nilLiteral, success, position); return nilLiteral; }
private VarName ParseVarName(out bool success) { var reskey = new Tuple2<int, string>(position, "VarName"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as VarName; } int errorCount = Errors.Count; VarName varName = new VarName(); varName.Name = ParseName(out success); if (success) { ClearError(errorCount); } else { Error("Failed to parse Name of VarName."); } ParsingResults[reskey] = new Tuple3<object, bool, int>(varName, success, position); return varName; }
private NumberLiteral ParseNumberLiteral(out bool success) { var reskey = new Tuple2<int, string>(position, "NumberLiteral"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as NumberLiteral; } int errorCount = Errors.Count; NumberLiteral numberLiteral = new NumberLiteral(); numberLiteral.HexicalText = ParseHexicalNumber(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(numberLiteral, success, position);return numberLiteral; } numberLiteral.Text = ParseFoatNumber(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(numberLiteral, success, position);return numberLiteral; } return numberLiteral; }
private BreakStmt ParseBreakStmt(out bool success) { var reskey = new Tuple2<int, string>(position, "BreakStmt"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as BreakStmt; } int errorCount = Errors.Count; BreakStmt breakStmt = new BreakStmt(); int start_position = position; MatchTerminalString("break", out success); if (!success) { position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(breakStmt, success, position);return breakStmt; } ParseSpReq(out success); if (!success) { Error("Failed to parse SpReq of BreakStmt."); position = start_position; } if (success) { ClearError(errorCount); } ParsingResults[reskey] = new Tuple3<object, bool, int>(breakStmt, success, position); return breakStmt; }
private OperatorExpr ParseOperatorExpr(out bool success) { var reskey = new Tuple2<int, string>(position, "OperatorExpr"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as OperatorExpr; } int errorCount = Errors.Count; OperatorExpr operatorExpr = new OperatorExpr(); int start_position = position; while (true) { int seq_start_position1 = position; string unaryOper = ParseUnaryOperator(out success); if (success) { operatorExpr.Add(unaryOper); } else { break; } ParseSpOpt(out success); break; } success = true; Term firstTerm = ParseTerm(out success); if (success) { operatorExpr.Add(firstTerm); } else { Error("Failed to parse firstTerm of OperatorExpr."); position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(operatorExpr, success, position);return operatorExpr; } ParseSpOpt(out success); while (true) { while (true) { int seq_start_position2 = position; string binaryOper = ParseBinaryOperator(out success); if (success) { operatorExpr.Add(binaryOper); } else { break; } ParseSpOpt(out success); Term nextTerm = ParseTerm(out success); if (success) { operatorExpr.Add(nextTerm); } else { Error("Failed to parse nextTerm of OperatorExpr."); position = seq_start_position2; break; } ParseSpOpt(out success); break; } if (!success) { break; } } success = true; ParsingResults[reskey] = new Tuple3<object, bool, int>(operatorExpr, success, position); return operatorExpr; }
public bool CreateBlock(int blockType, Tuple3 <int> location) { return(CreateBlock(blockType, location.first, location.second, location.third)); }
private ParamList ParseParamList(out bool success) { var reskey = new Tuple2<int, string>(position, "ParamList"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as ParamList; } int errorCount = Errors.Count; ParamList paramList = new ParamList(); while (true) { int seq_start_position1 = position; paramList.NameList = ParseNameList(out success); if (!success) { break; } while (true) { int seq_start_position2 = position; MatchTerminal(',', out success); if (!success) { break; } ParseSpOpt(out success); MatchTerminalString("...", out success); if (!success) { Error("Failed to parse '...' of ParamList."); position = seq_start_position2; } break; } paramList.HasVarArg = success; success = true; break; } if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(paramList, success, position);return paramList; } paramList.IsVarArg = MatchTerminalString("...", out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(paramList, success, position);return paramList; } return paramList; }
private string ParseDoubleQuotedText(out bool success) { var reskey = new Tuple2<int, string>(position, "DoubleQuotedText"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as string; } int errorCount = Errors.Count; StringBuilder text = new StringBuilder(); while (true) { ErrorStatck.Push(errorCount); errorCount = Errors.Count; while (true) { char ch = MatchTerminalSet("\"\\", true, out success); if (success) { ClearError(errorCount); text.Append(ch); break; } ch = ParseEscapeChar(out success); if (success) { ClearError(errorCount); text.Append(ch); break; } break; } errorCount = ErrorStatck.Pop(); if (!success) { break; } } success = true; ParsingResults[reskey] = new Tuple3<object, bool, int>(text.ToString(), success, position); return text.ToString(); }
private PrimaryExpr ParsePrimaryExpr(out bool success) { var reskey = new Tuple2<int, string>(position, "PrimaryExpr"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as PrimaryExpr; } int errorCount = Errors.Count; PrimaryExpr primaryExpr = new PrimaryExpr(); int start_position = position; primaryExpr.Base = ParseBaseExpr(out success); if (!success) { position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(primaryExpr, success, position);return primaryExpr; } while (true) { while (true) { int seq_start_position1 = position; ParseSpOpt(out success); Access access = ParseAccess(out success); if (success) { primaryExpr.Accesses.Add(access); } else { Error("Failed to parse Access of PrimaryExpr."); position = seq_start_position1; } break; } if (!success) { break; } } success = true; ParsingResults[reskey] = new Tuple3<object, bool, int>(primaryExpr, success, position); return primaryExpr; }
private Expr ParseExpr(out bool success) { var reskey = new Tuple2<int, string>(position, "Expr"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as Expr; } int errorCount = Errors.Count; Expr expr = null; expr = ParseOperatorExpr(out success); if (success) { return expr.Simplify(); } expr = ParseTerm(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(expr, success, position);return expr; } return expr; }
private RepeatStmt ParseRepeatStmt(out bool success) { var reskey = new Tuple2<int, string>(position, "RepeatStmt"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as RepeatStmt; } int errorCount = Errors.Count; RepeatStmt repeatStmt = new RepeatStmt(); int start_position = position; MatchTerminalString("repeat", out success); if (!success) { position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(repeatStmt, success, position);return repeatStmt; } ParseSpReq(out success); if (!success) { Error("Failed to parse SpReq of RepeatStmt."); position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(repeatStmt, success, position);return repeatStmt; } repeatStmt.Body = ParseChunk(out success); if (!success) { Error("Failed to parse Body of RepeatStmt."); position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(repeatStmt, success, position);return repeatStmt; } MatchTerminalString("until", out success); if (!success) { Error("Failed to parse 'until' of RepeatStmt."); position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(repeatStmt, success, position);return repeatStmt; } ParseSpReq(out success); if (!success) { Error("Failed to parse SpReq of RepeatStmt."); position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(repeatStmt, success, position);return repeatStmt; } repeatStmt.Condition = ParseExpr(out success); if (!success) { Error("Failed to parse Condition of RepeatStmt."); position = start_position; } if (success) { ClearError(errorCount); } ParsingResults[reskey] = new Tuple3<object, bool, int>(repeatStmt, success, position); return repeatStmt; }
private ExprStmt ParseExprStmt(out bool success) { var reskey = new Tuple2<int, string>(position, "ExprStmt"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as ExprStmt; } int errorCount = Errors.Count; ExprStmt exprStmt = new ExprStmt(); exprStmt.Expr = ParseExpr(out success); if (success) { ClearError(errorCount); } else { Error("Failed to parse Expr of ExprStmt."); } ParsingResults[reskey] = new Tuple3<object, bool, int>(exprStmt, success, position); return exprStmt; }
private ReturnStmt ParseReturnStmt(out bool success) { var reskey = new Tuple2<int, string>(position, "ReturnStmt"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as ReturnStmt; } int errorCount = Errors.Count; ReturnStmt returnStmt = new ReturnStmt(); int start_position = position; MatchTerminalString("return", out success); if (!success) { position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(returnStmt, success, position);return returnStmt; } ParseSpReq(out success); if (!success) { Error("Failed to parse SpReq of ReturnStmt."); position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(returnStmt, success, position);return returnStmt; } returnStmt.ExprList = ParseExprList(out success); success = true; ParsingResults[reskey] = new Tuple3<object, bool, int>(returnStmt, success, position); return returnStmt; }
private List<Field> ParseFieldList(out bool success) { var reskey = new Tuple2<int, string>(position, "FieldList"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as List<Field>; } int errorCount = Errors.Count; List<Field> list_Field = new List<Field>(); int start_position = position; Field field = ParseField(out success); if (success) { list_Field.Add(field); } else { position = start_position; ParsingResults[reskey] = new Tuple3<object, bool, int>(list_Field, success, position);return list_Field; } while (true) { while (true) { int seq_start_position1 = position; ParseFieldSep(out success); if (!success) { break; } ParseSpOpt(out success); field = ParseField(out success); if (success) { list_Field.Add(field); } else { Error("Failed to parse Field of FieldList."); position = seq_start_position1; } break; } if (!success) { break; } } success = true; while (true) { int seq_start_position2 = position; ParseFieldSep(out success); if (!success) { break; } ParseSpOpt(out success); break; } success = true; ParsingResults[reskey] = new Tuple3<object, bool, int>(list_Field, success, position); return list_Field; }
private Statement ParseStatement(out bool success) { var reskey = new Tuple2<int, string>(position, "Statement"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as Statement; } int errorCount = Errors.Count; Statement statement = null; statement = ParseAssignment(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(statement, success, position);return statement; } statement = ParseFunction(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(statement, success, position);return statement; } statement = ParseLocalVar(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(statement, success, position);return statement; } statement = ParseLocalFunc(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(statement, success, position);return statement; } statement = ParseReturnStmt(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(statement, success, position);return statement; } statement = ParseBreakStmt(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(statement, success, position);return statement; } statement = ParseDoStmt(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(statement, success, position);return statement; } statement = ParseIfStmt(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(statement, success, position);return statement; } statement = ParseForStmt(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(statement, success, position);return statement; } statement = ParseForInStmt(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(statement, success, position);return statement; } statement = ParseWhileStmt(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(statement, success, position);return statement; } statement = ParseRepeatStmt(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(statement, success, position);return statement; } statement = ParseExprStmt(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(statement, success, position);return statement; } return statement; }
private Args ParseArgs(out bool success) { var reskey = new Tuple2<int, string>(position, "Args"); if (ParsingResults.ContainsKey(reskey)) { var parsingResult = ParsingResults[reskey]; success = parsingResult.Item2; position = parsingResult.Item3; return parsingResult.Item1 as Args; } int errorCount = Errors.Count; Args args = new Args(); args.ArgList = ParseArgList(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(args, success, position);return args; } args.String = ParseStringLiteral(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(args, success, position);return args; } args.Table = ParseTableConstructor(out success); if (success) { ClearError(errorCount); ParsingResults[reskey] = new Tuple3<object, bool, int>(args, success, position);return args; } return args; }
public bool PostEvaluate(IAgAsHpopPluginResultPostEval ResultEval) { try { if (this.m_MsgCntr % this.m_MsgInterval == 0) { Debug.WriteLine("--> Entered", this.m_Name + ".PostEvaluate( " + this.m_MsgCntr + " )"); } if (m_Enabled && m_DebugMode && ResultEval != null) { // get SRP acceleration from HPOP Tuple3 srpAccel = new Tuple3(0.0, 0.0, 0.0); ResultEval.GetAcceleration(AgEAccelType.eSRPAccel, AgEUtFrame.eUtFrameInertial, ref srpAccel.x, ref srpAccel.y, ref srpAccel.z); DebugMsg("HPOP computed Sunlight SRP = (" + srpAccel.x + ", " + srpAccel.y + ", " + srpAccel.z + ")"); srpAccel.scaleBy(-1.0); srpAccel.addTo(this.m_SunlightSRP); DebugMsg("Difference in Sunlight SRP = (" + srpAccel.x + ", " + srpAccel.y + ", " + srpAccel.z + ")"); double cr = ResultEval.Cr; double dragArea = ResultEval.DragArea; double solarFlux = ResultEval.SolarFlux; double illum = ResultEval.SolarIntensity; DebugMsg("Area = " + dragArea + ", Flux = " + solarFlux + ", Cr = " + cr + ", Mass = " + m_SpacecraftMass + ", Illum = " + illum); } else if (this.m_DebugMode) { this.m_UPS.Message(AgEUtLogMsgType.eUtLogMsgDebug, this.m_Name + ".PostEvaluate(): Disabled"); } } catch (Exception ex) { this.m_Enabled = false; Message(AgEUtLogMsgType.eUtLogMsgAlarm, this.m_Name + ".PostEvaluate(): Exception Message( " + ex.Message + " )"); Message(AgEUtLogMsgType.eUtLogMsgAlarm, this.m_Name + ".PostEvaluate(): Exception StackTr( " + ex.StackTrace + " )"); Debug.WriteLine("Exception Message( " + ex.Message + " )", this.m_Name + ".PostEvaluate()"); Debug.WriteLine("Exception StackTr( " + ex.StackTrace + " )", this.m_Name + ".PostEvaluate()"); } finally { if (this.m_MsgCntr % this.m_MsgInterval == 0) { Debug.WriteLine("<-- Exited", this.m_Name + ".PostEvaluate( " + this.m_MsgCntr + " )"); } } m_EvalMsgCount++; if (m_EvalMsgCount % m_EvalMsgMax == 0) { m_EvalMsgsOn = false; } return(this.m_Enabled); }