private void InitOrderdPoints(Figure figure) { //Initialize all possible segments from the picked points foreach (var item in figure.Path.PathPoints) { pID++; PointF p = new PointF(item.X, item.Y); SuperPoint sp = new SuperPoint(p, pID); pointsList.Add(sp); } for (int i = 0; i < pointsList.Count; i++) { for (int j = 0; j < pointsList.Count; j++) { if (i != j) { Segment op = new Segment(); PointF p1 = pointsList[i].P; PointF p2 = pointsList[j].P; op.p = p1; op.q = p2; Segments.Add(op); } } } }
public static float calDistance(SuperPoint a, SuperPoint b)//计算两个触控点距离的方法 { float result = 0; result = (float)Mathf.Sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); return(result); }
public bool contains(SuperPoint point) { if (p.Equals(point.P) || q.Equals(point.P)) { return(true); } return(false); }
private void frmConvexHull_MouseDown(object sender, MouseEventArgs e) { render(); pID++; graphics = this.CreateGraphics(); renderPoint(e.X, e.Y, Color.Lime); PointF p = new PointF(e.X, e.Y); SuperPoint sp = new SuperPoint(p, pID); pointsList.Add(sp); }
public static uint CMPOverrideObject() { SuperPoint point = new SuperPoint(100, 200); if (point.GetSum() == 600) { return(1); } return(0); }
public Memento(MyMap Map, SuperPoint TheSuperPoint, Point ThePoint) { MMap = new MyMap(); MMap = Map; MTheSuperPoint = new SuperPoint(); MTheSuperPoint = TheSuperPoint; MThePoint = new Point(); MThePoint = ThePoint; }
public void InheritanceTests() { var superPoint = new SuperPoint() { X = 10, Y = 10, Z = 10, W = 42 }; var str = Operations.Serialize(superPoint); var sstr = Operations.Deserialize(str); Assert.AreEqual(superPoint.speckle_type, sstr.speckle_type); }
void OnPress(bool pressed) { if (pressed)//按下 { //要排除是双指或双指以上的模式 if (!(UICamera.touchCount >= 2)) { GameCamera.Inst.jiaodian = UICamera.lastWorldPosition;//试试这个新学到的 //SuperGameManager.Instance.core = UICamera.lastWorldPosition; } //------------------------------------------- SuperGameManager.Instance.buttonPressed = true; SuperGameManager.Instance.validClickRequest = true; int id = UICamera.currentTouchID; SuperPoint sp = new SuperPoint(); sp.Init(UICamera.GetTouch(id).pos.x, UICamera.GetTouch(id).pos.y); //加入直接先判断是否存在 if (GameCamera.Inst.pd.ContainsKey(id)) { GameCamera.Inst.pd.Remove(id); } //无论是主点还是辅点按下皆向map中放入一个新点 GameCamera.Inst.pd.Add(id, sp); if (UICamera.touchCount == 2) { if (GameCamera.Inst.pd.Count == 2)//如果已经有两个触控点按下 { //SuperPoint sp1 = GameCamera.Inst.pd[0];//从map中取出第一个点 //SuperPoint sp2 = GameCamera.Inst.pd[1];//从map中取出第二个点 //GameCamera.Inst.distance = SuperPoint.calDistance(sp1, sp2);//计算两个触控点之间的距离 //Debug.Log("这两个触控点的初始距离是" + GameCamera.Inst.distance); } } } else//抬起 { SuperGameManager.Instance.validClickRequest = true; //----------------------------------------------------------------------- SuperGameManager.Instance.buttonPressed = false; SuperGameManager.Instance.time = 0f; if (UICamera.currentTouchID == 0)//如果是主点抬起 { GameCamera.Inst.pd.Clear(); SuperGameManager.Instance.touchMode = SuperGameManager.TouchMode.None; } else if (UICamera.currentTouchID == 1)//如果是辅点抬起 { GameCamera.Inst.pd.Remove(1); SuperGameManager.Instance.validClickRequest = false; } } }
public static uint CMPMethodNullReference() { SuperPoint point = null; try { point.GetSum(); return(3); } catch (System.NullReferenceException) { return(1); } catch { return(2); } }
public SuperPoint[][] MakeSuperPoints(bool[,] map, Point end) { SuperPoint[][] spoint = new SuperPoint[map.GetLength(0)][]; // Make measurements from each point to the end. // This is a simple type of heuristic calculation. for (int y = 0; y < map.GetLength(0); y++) { spoint[y] = new SuperPoint[map.GetLength(1)]; for (int x = 0; x < map.GetLength(1); x++) { var coords = new Point(x, y); spoint[y][x] = new SuperPoint { Coords = coords, Heuristic = Vector2.Distance(coords.ToVector2(), end.ToVector2()), IsPassable = map[y, x] }; } } return(spoint); }
public List <Point> CreatePath(bool[,] map, Point start, Point end) { SuperPoint[][] spoint = MakeSuperPoints(map, end); // Check open list for lowest F (if the same -> take the one added to open list later) // Add it to closed list (remove from open list) // Add all non-blocked neighbours (not open/closed) to the open list (parent is the one closed). // Calculate the "heuristic" for all item in the open list. // Calculate G-score for all in the open list: is 1 + G score of parent (G+H = F) // Check adjacent tiles on open list, is it better to go through currently closed // - to check it just take the G score of current, add the cost of going to the one being checked and see if it's lower than what is already in the one being checked // - if it's lower recalculate F for the one being checked, based on the new G score // - and change the parent var closed = new List <SuperPoint>(); var open = new List <SuperPoint> { spoint[start.Y][start.X] }; while (open.Count > 0) { // Get the one with lowest F. SuperPoint current = open.OrderBy(e => e.FScore).First(); // Add it to closed, remove from open. open.Remove(current); closed.Add(current); if (current == spoint[end.Y][end.X]) { break; } // Find all non-blocked neighbours (not in open nor closed) List <SuperPoint> neighbours = GetNeighbours(current.Coords, spoint) .Where(e => e.IsPassable && !open.Contains(e) && !closed.Contains(e)) .ToList(); open.AddRange(neighbours); // Calculate the G score for all neighbours. Parent + path from parent to them. neighbours.ForEach(n => n.Gscore = current.Gscore + 1); neighbours.ForEach(n => n.Parent = current); // Find the neighbours which are still open. List <SuperPoint> neighboursInOpen = GetNeighbours(current.Coords, spoint) .Where(e => e.IsPassable && open.Contains(e)) .ToList(); foreach (SuperPoint neighbourOpen in neighboursInOpen) { // Calculate the potential new cost. float potentialG = current.Gscore + 1; if (potentialG < neighbourOpen.Gscore) { neighbourOpen.Gscore = potentialG; neighbourOpen.Parent = current; } } } var superResult = new List <SuperPoint> { spoint[end.Y][end.X] }; while (true) { SuperPoint current = superResult[superResult.Count - 1]; if (current.Parent == null) { break; } superResult.Add(current.Parent); if (superResult.Count > map.GetLength(0) * map.GetLength(1)) { throw new Exception("Invalid path. Circles or something."); } } var result = superResult.Select(sp => sp.Coords).ToList(); result.Reverse(); return(result); }