static void Main() { LastType lt = new LastType(); SomeType st = new SomeType(); AnotherType atype = new AnotherType(); st.myInt = 7; atype.myString = "BOB"; atype.mySomeType = st; lt.mySomeType = st; lt.myAnotherType = atype; string xmlOutput = YourAwesomeFunction(lt); }
public bool TryAddD() { switch (_lastType) { case LastType.Number: if (_hasSpace || _hasLineBreak) { return(false); } _lastType = LastType.D; _hasSpace = false; _hasLineBreak = false; return(true); default: return(false); } }
public bool TryAddMinus() { switch (_lastType) { case LastType.None: _lastType = LastType.Minus; _hasSpace = false; _hasLineBreak = false; return(true); case LastType.Number: _tokens.Add(new Tokens.ConstantToken(_lastNumber)); _lastType = LastType.Minus; _hasSpace = false; _hasLineBreak = false; return(true); case LastType.Plus: _tokens.Add(new Tokens.PlusToken()); _hasSpace = false; _hasLineBreak = false; return(true); case LastType.Minus: _tokens.Add(new Tokens.MinusToken()); _lastType = LastType.Minus; _hasSpace = false; _hasLineBreak = false; return(true); case LastType.D: return(false); case LastType.DRightNumber: _tokens.Add(new Tokens.DieToken(_dCountNumber, _lastNumber)); _lastType = LastType.Minus; _hasSpace = false; _hasLineBreak = false; return(true); default: throw new Exception(); } }
public ExtTriangle(Vector3 a, Vector3 b, Vector3 c, bool _unidirectionnal, bool _inverseDirection, bool _noGravityBorders, bool _calculateAB, bool _calculateBC, bool _calculateCA, bool _calculateCorner) { A = a; B = b; C = c; AB = B - A; AC = C - A; unidirectionnal = _unidirectionnal; inverseDirection = _inverseDirection; noGravityBorders = _noGravityBorders; TriNorm = Vector3.Cross(a - b, a - c); TriNormNormalize = TriNorm.normalized; calculateAB = _calculateAB; calculateBC = _calculateBC; calculateCA = _calculateCA; calculateCorner = _calculateCorner; lastType = LastType.NONE; }
// 0 ≦ n ≦ 9 public bool TryAddNumber(int n) { switch (_lastType) { case LastType.None: _lastType = LastType.Number; _lastNumber = n; _hasSpace = false; _hasLineBreak = false; return(true); case LastType.Number: if (_hasSpace || _hasLineBreak) { return(false); } _lastNumber = (_lastNumber * 10) + n; _hasSpace = false; _hasLineBreak = false; return(true); case LastType.Plus: _tokens.Add(new Tokens.PlusToken()); _lastType = LastType.Number; _lastNumber = n; _hasSpace = false; _hasLineBreak = false; return(true); case LastType.Minus: _tokens.Add(new Tokens.MinusToken()); _lastType = LastType.Number; _lastNumber = n; _hasSpace = false; _hasLineBreak = false; return(true); case LastType.D: if (_hasSpace || _hasLineBreak) { return(false); } _dCountNumber = _lastNumber; _lastNumber = n; _lastType = LastType.DRightNumber; _hasSpace = false; _hasLineBreak = false; return(true); case LastType.DRightNumber: if (_hasSpace || _hasLineBreak) { return(false); } _lastNumber = (_lastNumber * 10) + n; _hasSpace = false; _hasLineBreak = false; return(true); default: throw new Exception(); } }
public Vector3 ClosestPointTo(Vector3 p) { // Check if P in vertex region outside A Vector3 ap = p - A; lastType = LastType.NONE; float d1 = Vector3.Dot(AB, ap); float d2 = Vector3.Dot(AC, ap); if (d1 <= 0.0f && d2 <= 0.0f) { lastType = LastType.A; if (noGravityBorders && (!calculateCorner || (calculateCorner && !calculateAB && !calculateCA))) { return(Vector3.zero); } if (unidirectionnal) { return(GetGoodPointUnidirectionnal(p, A)); } return(A); // barycentric coordinates (1,0,0) } // Check if P in vertex region outside B Vector3 bp = p - B; float d3 = Vector3.Dot(AB, bp); float d4 = Vector3.Dot(AC, bp); if (d3 >= 0.0f && d4 <= d3) { lastType = LastType.B; if (noGravityBorders && (!calculateCorner || (calculateCorner && !calculateAB && !calculateBC))) { return(Vector3.zero); } if (unidirectionnal) { return(GetGoodPointUnidirectionnal(p, B)); } return(B); // barycentric coordinates (0,1,0) } // Check if P in edge region of AB, if so return projection of P onto AB float vc = d1 * d4 - d3 * d2; if (vc <= 0.0f && d1 >= 0.0f && d3 <= 0.0f) { lastType = LastType.AB; if (noGravityBorders && !calculateAB) { return(Vector3.zero); } float v1 = d1 / (d1 - d3); if (unidirectionnal) { return(GetGoodPointUnidirectionnal(p, A + v1 * AB)); } return(A + v1 * AB); // barycentric coordinates (1-v,v,0) } // Check if P in vertex region outside C Vector3 cp = p - C; float d5 = Vector3.Dot(AB, cp); float d6 = Vector3.Dot(AC, cp); if (d6 >= 0.0f && d5 <= d6) { lastType = LastType.C; if (noGravityBorders && (!calculateCorner || (calculateCorner && !calculateBC && !calculateCA))) { return(Vector3.zero); } if (unidirectionnal) { return(GetGoodPointUnidirectionnal(p, C)); } return(C); // barycentric coordinates (0,0,1) } // Check if P in edge region of AC, if so return projection of P onto AC float vb = d5 * d2 - d1 * d6; if (vb <= 0.0f && d2 >= 0.0f && d6 <= 0.0f) { lastType = LastType.CA; if (noGravityBorders && !calculateCA) { return(Vector3.zero); } float w1 = d2 / (d2 - d6); if (unidirectionnal) { return(GetGoodPointUnidirectionnal(p, A + w1 * AC)); } return(A + w1 * AC); // barycentric coordinates (1-w,0,w) } // Check if P in edge region of BC, if so return projection of P onto BC float va = d3 * d6 - d5 * d4; if (va <= 0.0f && (d4 - d3) >= 0.0f && (d5 - d6) >= 0.0f) { lastType = LastType.BC; if (noGravityBorders && !calculateBC) { return(Vector3.zero); } float w2 = (d4 - d3) / ((d4 - d3) + (d5 - d6)); if (unidirectionnal) { return(GetGoodPointUnidirectionnal(p, B + w2 * (C - B))); } return(B + w2 * (C - B)); // barycentric coordinates (0,1-w,w) } // P inside face region. Compute Q through its barycentric coordinates (u,v,w) lastType = LastType.ABC; float denom = 1.0f / (va + vb + vc); float v = vb * denom; float w = vc * denom; if (unidirectionnal) { return(GetGoodPointUnidirectionnal(p, A + AB * v + AC * w)); } return(A + AB * v + AC * w); // = u*a + v*b + w*c, u = va * denom = 1.0f-v-w }
/// <summary> /// 读取定位块数据 /// </summary> /// <param name="sc">文本流</param> private void ReadLocation(StreamReader sc, object o, TextType t, LastType l = LastType.NA) { if (sc.EndOfStream) { return; } string data = sc.ReadLine();//读取#下一行,判断该值为那个类型 if (Const.LocationMap.IsMatch(data)) { //获取作为MAP的int数值 int num = int.Parse(Const.LocationMap.Match(data).Value); //将该map添加进字典 Dictionary <int, Dictionary <int, List <ViewData> > > temp; //从现有队列尝试获取已有值,如果没有建立新的 if (!this.structure.TryGetValue(num, out temp)) { temp = new Dictionary <int, Dictionary <int, List <ViewData> > >(); this.structure.Add(num, temp); } //根据规则 MAP下一级为Event //跳过下一个# sc.ReadLine(); //跳过两者间空格 sc.ReadLine(); //跳过EVENT的上方# sc.ReadLine(); this.nowMap = num; //递归读取 this.ReadLocation(sc, temp, t, LastType.Map); } if (Const.LocationEvent.IsMatch(data)) { if (o == null) { return; } //获取作为Event的int数值 int num = int.Parse(Const.LocationEvent.Match(data).Value); Dictionary <int, List <ViewData> > temp = null; //EVENT块属于三级数据关系中位,需要额外考虑 if (l == LastType.Map)//说明o来自于map传递值,此时只需要直接在其中添加新的Event项目 { if (!((o as Dictionary <int, Dictionary <int, List <ViewData> > >)).TryGetValue(num, out temp)) { temp = new Dictionary <int, List <ViewData> >(); (o as Dictionary <int, Dictionary <int, List <ViewData> > >).Add(num, temp); } } else if (l == LastType.Page)//说明o来自于page结束后的传值,需要对应的map下的event字典 { //获取当前map下的event字典 Dictionary <int, Dictionary <int, List <ViewData> > > _temp = this.structure[this.nowMap]; if (!(_temp.TryGetValue(num, out temp))) { temp = new Dictionary <int, List <ViewData> >(); _temp.Add(num, temp); } } //跳过下一个# sc.ReadLine(); //跳过两者间空格 sc.ReadLine(); //跳过PAGE的上方# sc.ReadLine(); this.ReadLocation(sc, temp, t, LastType.Event); } if (Const.LocationPage.IsMatch(data)) { if (o == null) { return; } //进入PAGE块,说明object已经传递了Page对应的索引 //获取作为Page的int数值 int num = int.Parse(Const.LocationPage.Match(data).Value); bool isHas = true; //特殊处理,准备进入Page内部的文本块递归 List <ViewData> temp; if (!(o as Dictionary <int, List <ViewData> >).TryGetValue(num, out temp)) { temp = new List <ViewData>(); (o as Dictionary <int, List <ViewData> >).Add(num, temp); isHas = false; } //temp用于存储文本块的链表 //跳过Page下面的# sc.ReadLine(); //如果该page存在 if (isHas) { //两者的文本块结构应该相同 IEnumerator <ViewData> next = temp.GetEnumerator(); next.MoveNext();//推进到第一个元素 SaveAs(t, next.Current, new string[1] { sc.ReadLine() }); //第一个元素应该为文本块开始的第一个虚线 next.MoveNext(); //推进到正式文本块 ReadNewBlock(sc, next, t); } else { //page不存在,直接压入数据 ViewData dt = new ViewData(); //读取PAGE下第一个----对应的参数并压入相应的List中 SaveAs(t, dt, new string[1] { sc.ReadLine() }); temp.Add(dt); ReadNewBlock(sc, temp, t); } if (sc.EndOfStream)//到达最后一个page { return; } sc.ReadLine();//根据规则,page块结束不是文档结束就是下一个EVENT/MAP/EVENT,跳过### ReadLocation(sc, o, t, LastType.Page); } //都没匹配到,说明该行非法【DM规则#与#之间应为map/event/page】 return; }