/** * Generate all the critical points based on the position of the viewpoint and end points * @param viewpoint the oject of the view point * @param endPoints the list of the end points that need to connected with the view point */ private void GenerateLinesCast(GameObject viewpoint, OBSTACLE.Obstacle endPoints) { for (int i = 0; i < endPoints.obstaclePoints.Length; i++) { Vector2 direction = endPoints.obstaclePoints[i] - viewpoint.transform.position; if (bPartiallyView) { if (HelpFunction.isInsideClockRangeOfTwoVector(startDirection, endDirection, direction)) { GenerateLineCast(viewpoint, endPoints, direction, i); } } else { GenerateLineCast(viewpoint, endPoints, direction, i); } } if (rangeEffect) { // compute the intersection point with the obstacle for (int i = 0; i < endPoints.obstaclePoints.Length; i++) { Vector2 intersection1; Vector2 intersection2; if (HelpFunction.FindLineCircleIntersections(viewpoint.transform.position, range, endPoints.obstaclePoints[i], endPoints.obstaclePoints[(i + 1) % endPoints.obstaclePoints.Length], out intersection1, out intersection2) != 0) { GenerateRangeIntersectionPoint(intersection1, endPoints.index); GenerateRangeIntersectionPoint(intersection2, endPoints.index); } } } }
/// <summary> /// compare two vector /// </summary> /// <param name="v1">vector1</param> /// <param name="v2">vector2</param> /// <returns>0 -> v1 == v2; -1 -> v1 < v2; 1 -> v1 > v2</returns> public static int compareByAngle(Vector2 v1, Vector2 v2) { v1 = new Vector2(v1.x, v1.y); v2 = new Vector2(v2.x, v2.y); float angle1 = Vector2.Angle(v1, new Vector2(1, 0)); float angle2 = Vector2.Angle(v2, new Vector2(1, 0)); if (v1.y > 0) { angle1 = 360 - angle1; } if (v2.y > 0) { angle2 = 360 - angle2; } if (HelpFunction.floatEqual(angle1, angle2)) { return(0); } else { return(angle1 > angle2 ? 1 : -1); } }
private void ButtonAdd_OnClick(object sender, RoutedEventArgs e) { if (!CheckInput()) { return; } android_update android = new android_update(); android.create_time = HelpFunction.ConvertToTimestamp(DateTime.Now); android.update_intro = this.TextIntro.HtmlContent; android.update_url = this.TextUrl.GetUrl(); android.version_no = this.TextBoxVersionNo.Text; android.version_id = this.TextBoxVersionId.Value ?? 0; bool bl = AndroidMgr.Instance.SaveAndroidApk(android); if (bl) { MessageBox.Show("保存成功"); this.DialogResult = true; } else { MessageBox.Show("保存失败"); this.DialogResult = false; } }
// this will throw exception if fail to convert public static byte[] GetBytesFromDecString(string decStr) { ArrayList list = new ArrayList(); string[] splitStr = HelpFunction.SplitString(decStr, new char[] { ' ', ',', '\r', '\n', '\t' }); for (int i = 0; i < splitStr.Length; i++) { int dec = 0; try { dec = Convert.ToInt32(splitStr[i]); } catch (Exception exception) { throw exception; break; } if (dec > 255) { break; } list.Add((byte)dec); } return((byte[])list.ToArray(typeof(byte))); }
private void GenerateLineCast(GameObject viewpoint, Vector2 direction) { HitPoint hitPoint = new HitPoint(); RaycastHit2D[] rayCastHits2D; rayCastHits2D = Physics2D.RaycastAll(viewpoint.transform.position, direction); if (rayCastHits2D.Length > 0) { if ((rayCastHits2D[0].point - new Vector2(viewpoint.transform.position.x, viewpoint.transform.position.y)).magnitude < range) { hitPoint.location = rayCastHits2D[0].point; // find the index of obstacle in the hit point foreach (OBSTACLE.Obstacle obstacle in ObstaclesLine) { if (HelpFunction.isInObstacle(hitPoint.location, obstacle.obstaclePoints)) { hitPoint.obstacleIndex = obstacle.index; break; } } addPointToCriticalList(hitPoint); } else { hitPoint.location = new Vector2(viewpoint.transform.position.x, viewpoint.transform.position.y) + direction.normalized * range; hitPoint.obstacleIndex = -1; addPointToCriticalList(hitPoint); } if (!bMesh) { GenerateVisibilityEffectWithLine(viewpoint, hitPoint.location); } } }
public void TestDateTimeTolong() { DateTime dateTime = new DateTime(2016, 4, 5, 12, 33, 42); var value = HelpFunction.ConvertToTimestamp(dateTime); var valued = HelpFunction.ConvertToDateTime(1463474565); Assert.AreEqual(valued, dateTime); }
public void TestVideoImg() { SearchModel model = new SearchModel(); ; model.Id = 12; var s = HelpFunction.JsonEncode(model); //string file = ""; //bool bl = ServerFileMgr.GetVideoThumbnailImg(FileTypeDirEnum.CrowdFundImgDir, "69937f4589276df4test.mp4", out file); //Assert.AreEqual(true, bl); }
private void GenerateCollider(Obstacle[] obstacles) { foreach (Obstacle obstacle in obstacles) { List <Obstacle> trianglizedObstacles = new List <Obstacle>(); trianglizedObstacles = HelpFunction.triangularization(obstacle); foreach (Obstacle trianglizedObstacle in trianglizedObstacles) { addCollider(trianglizedObstacle); } } }
private void GenerateObstacle(Obstacle obstacle) { // triangulation List <Obstacle> trianglizedObstacles = new List <Obstacle>(); trianglizedObstacles = HelpFunction.triangularization(obstacle); //List<Obstacle> tempObstacle = new List<Obstacle>(); //tempObstacle = obstacles.ToList(); //tempObstacle.Remove(obstacle); //tempObstacle.AddRange(trianglizedObstacles); //obstacles = tempObstacle.ToArray(); GenerateNewLine(obstacle.obstaclePoints); }
public void TestGenerateOrderId() { List <string> ls = new List <string>(); int count = 0; for (int i = 0; i < 1000; i++) { var id = HelpFunction.GenerateOrderNumber(); if (ls.Contains(id)) { count++; } ls.Add(id); } Assert.AreEqual(count, 0); }
private void ButtonQurey_OnClick(object sender, RoutedEventArgs e) { DataGrid.ItemsSource = null; if (ComboBoxFirst.GetCategory() == null) { return; } int num = -1; if (TextId.Text.Trim().Length > 0) { num = HelpFunction.ConvertToInt(TextId.Text.Trim()); } DataGrid.ItemsSource = CrowFoundMgr.Instance.QueryCrowDatas(num, TextActorName.Text.Trim(), this.ComboBoxFirst.GetCategory().fc_id); }
private void txtQuickSend_TextChanged(object sender, EventArgs e) { HelpFunction.ValidateResult result = HelpFunction.CheckInput(txtQuickSend.Text, mData.Format); if (result.IsValid) { lbInfo.IsShowText = false; lbInfo.Value = new int[] { GetInstanceData().Length }; lbInfo.ForeColor = Color.Black; UpdateBytesControlValue(); } else { lbInfo.IsShowText = true; lbInfo.Text = "Wrong Data"; lbInfo.ForeColor = Color.Red; } }
public async void GetAndroidUpdate() { WebUtils webUtils = new WebUtils(); Dictionary <string, string> dict = new Dictionary <string, string>(); dict.Add("sign", webUtils.GetSign("")); dict.Add("data", ""); dict.Add("source", "C31B32364CE19CA8FCD150A417ECCE58"); string json = await webUtils.DoPost("http://172.168.6.186:8088/comm/getandroidupdate", dict); var android = HelpFunction.ToObject <AndroidUpdate>(json); if (android != null) { } }
private void GenerateRangeIntersectionPoint(Vector2 intersection, int obstacleIndex) { if (Double.IsNaN(intersection.x) || Double.IsNaN(intersection.y)) { return; } Vector2 direction = intersection - (Vector2)viewpoint.transform.position; RaycastHit2D[] rayCastHits2D = Physics2D.RaycastAll(viewpoint.transform.position, direction, range); if (rayCastHits2D.Length == 0) { addPointToCriticalList(new HitPoint(intersection, obstacleIndex)); } if (rayCastHits2D.Length == 1 && HelpFunction.Vector2Equal(rayCastHits2D[0].point, intersection)) { addPointToCriticalList(new HitPoint(intersection, obstacleIndex)); } }
private bool isSameLine(Vector2 point1, Vector2 point2, Vector2 obstaclePoint1, Vector2 obstaclePoint2) { // move to the original Vector2 p1 = point1 - obstaclePoint1; Vector2 p2 = point2 - obstaclePoint1; Vector2 o1 = obstaclePoint1 - obstaclePoint1; Vector2 o2 = obstaclePoint2 - obstaclePoint1; // compute the direction Vector2 directionPoint = p2 - p1; Vector2 directionObstaclePoint = (o2 - o1).normalized; if (HelpFunction.Vector2Equal((p2 - p1).normalized, directionObstaclePoint) || HelpFunction.Vector2Equal((p1 - p2).normalized, directionObstaclePoint)) { // detect the range if (HelpFunction.Vector2Equal(o2 - p1, o2)) { // p1 = (0, 0) return(HelpFunction.floatGreat(o2.magnitude, (p2 - o2).magnitude) ? true : false); } else if (HelpFunction.Vector2Equal(o2 - p2, o2)) { // p2 = (0, 0) return(HelpFunction.floatGreat(o2.magnitude, (p1 - o2).magnitude) ? true : false); } else if (HelpFunction.Vector2Equal(p1.normalized, p2.normalized)) { // same line if (HelpFunction.floatGreat((o2 - p1).magnitude, o2.magnitude) || HelpFunction.floatGreat((o2 - p2).magnitude, o2.magnitude)) { return(false); } else { return((!HelpFunction.floatLess(o2.magnitude, p1.magnitude) && !HelpFunction.floatLess(o2.magnitude, p2.magnitude)) ? true : false); } } } return(false); }
public bool SaveTopData(Dictionary <int, TopDataModel> dict, DateTime dateTime) { using (userEntities userEntities = new userEntities()) { using (var tran = userEntities.Database.BeginTransaction()) { try { var dataList = userEntities.recommendation.Where(p => p.data_date == dateTime).ToList(); if (dataList.Count > 0) { userEntities.recommendation.RemoveRange(dataList); userEntities.SaveChanges(); } foreach (var item in dict) { recommendation data = new recommendation(); data.create_id = 1; data.create_name = "admin"; data.create_time = HelpFunction.ConvertToTimestamp(DateTime.Now); data.data_date = item.Value.Date; data.icon = item.Value.ImgaeUrl; data.order_index = item.Value.OrderIndex; data.source_id = item.Value.SourceId; data.source_type = item.Value.SourceTypeInt; data.source_title = item.Value.Title; userEntities.recommendation.Add(data); } userEntities.SaveChanges(); tran.Commit(); return(true); } catch (Exception ex) { tran.Rollback(); Trace.WriteLine(ex); } } } return(false); }
private void addPointToCriticalList(HitPoint point) { bool isContain = false; foreach (HitPoint v in criticalPoints) { if (HelpFunction.Vector2Equal(v.location, point.location)) { isContain = true; break; } } if (!isContain) { if (bPartiallyView && !HelpFunction.isInsideClockRangeOfTwoVector(startDirection, endDirection, point.location - (Vector2)viewpoint.transform.position)) { return; } criticalPoints.AddFirst(point); } }
// Update is called once per frame void Update() { if (!drawobstacle.bUserDefine) { if (moveable) { viewpoint = GameObject.FindGameObjectWithTag("ViewPoint"); if (viewpoint) { viewpoint.transform.position = new Vector2(GetMousePosition().x, GetMousePosition().y); if (HelpFunction.IsPointInsidePolygon(viewpoint.transform.position, BoundaryLine.ToList <Vector3>())) { GameObject viewpointPrefab = Instantiate(ViewPointPrefab, viewpoint.transform.position, Quaternion.identity); GenerateCriticalPoint(viewpoint); Destroy(viewpointPrefab, 0.02f); if (bMesh) { GenerateVisibilityEffectWithMesh(viewpoint, criticalPoints); if (rangeEffect) { GenerateRangeCircle(viewpoint, range); } } } else if (mesh) { mesh.Clear(); } position = viewpoint.transform.position; } } } else { // update the obstacles and boundry in advance BoundaryLine = drawboundary.GetBoundaryLine(); ObstaclesLine = drawobstacle.GetObstacles(); } }
public List <UserRequstModel> GetRequstModels() { List <UserRequstModel> list = new List <UserRequstModel>(); using (userEntities data = new userEntities()) { int index = 1; var res = from a in data.actor_requst join b in data.user_base on a.user_uid equals b.user_uid select new { a.career, a.experience, a.gender, a.org, a.requst_time, a.tel, a.user_uid, b.user_nick }; ; foreach (var item in res) { UserRequstModel model = new UserRequstModel(); model.Career = item.career; model.Experience = item.experience; model.Gender = item.gender; model.Org = item.org; model.Tel = item.tel; model.UserUid = item.user_uid; model.UserNick = item.user_nick; model.RequstTime = HelpFunction.GetDateTime(item.requst_time); model.Num = index; index++; list.Add(model); } } return(list); }
// compare two vector // 0 -> v1 == v2; -1 -> v1 < v2; 1 -> v1 > v2 private int compareByAngle(HitPoint h1, HitPoint h2) { Vector2 v1 = h1.location; Vector2 v2 = h2.location; v1 = new Vector2(v1.x - viewpoint.transform.position.x, v1.y - viewpoint.transform.position.y); v2 = new Vector2(v2.x - viewpoint.transform.position.x, v2.y - viewpoint.transform.position.y); float angle1; float angle2; if (!bPartiallyView) { angle1 = HelpFunction.clockwiseAngle(new Vector2(1, 0), v1); angle2 = HelpFunction.clockwiseAngle(new Vector2(1, 0), v2); } else { angle1 = HelpFunction.clockwiseAngle(startDirection, v1); angle2 = HelpFunction.clockwiseAngle(startDirection, v2); } if (HelpFunction.floatEqual(angle1, 0f)) { return(HelpFunction.floatEqual(angle2, 0f) ? 0 : -1); } if (HelpFunction.floatEqual(angle2, 0f)) { return(HelpFunction.floatEqual(angle1, 0f) ? 0 : 1); } if (HelpFunction.floatEqual(angle1, angle2)) { return(0); } else { return(angle1 > angle2 ? 1 : -1); } }
// Start is called before the first frame update void Start() { drawboundary = GameObject.Find("BoundaryManager").GetComponent <BOUNDARY>(); drawobstacle = GameObject.Find("ObstacleManager").GetComponent <OBSTACLE>(); // Generate the obstacles and boundry in advance BoundaryLine = drawboundary.GetBoundaryLine(); ObstaclesLine = drawobstacle.GetObstacles(); if (range <= 0) { rangeEffect = false; range = int.MaxValue; } if (!moveable) { viewpoint = GameObject.FindGameObjectWithTag("ViewPoint"); if (viewpoint) { viewpoint.transform.position = position; if (HelpFunction.IsPointInsidePolygon(viewpoint.transform.position, BoundaryLine.ToList <Vector3>())) { GameObject viewpointPrefab = Instantiate(ViewPointPrefab, viewpoint.transform.position, Quaternion.identity); GenerateCriticalPoint(viewpoint); } if (bMesh) { GenerateVisibilityEffectWithMesh(viewpoint, criticalPoints); if (rangeEffect) { GenerateRangeCircle(viewpoint, range); } } } } }
public bool SaveVideoInfo(video_info videoInfo, List <video_label> videoLabels) { using (userEntities user = new userEntities()) { using (var tran = user.Database.BeginTransaction()) { try { videoInfo.v_create_time = HelpFunction.ConvertToTimestamp(DateTime.Now); user.video_info.Add(videoInfo); int iRent = user.SaveChanges(); if (iRent > 0) { if (videoLabels.Count > 0) { foreach (var item in videoLabels) { item.v_id = videoInfo.id; } user.video_label.AddRange(videoLabels); user.SaveChanges(); } } tran.Commit(); return(true); } catch (Exception ex) { tran.Rollback(); Trace.WriteLine(ex); } } } return(false); }
public static void RegisterAll() { BreakExpression.Register(); ContinueExpression.Register(); ReturnFunctionExpression.Register(); AbsFunction.Register(); ExecuteFile.Register(); PowFunction.Register(); ProductFunction.Register(); HelpFunction.Register(); SqrtFunction.Register(); SumDeepFunction.Register(); SumFunction.Register(); LengthFunction.Register(); ConsoleObject.Register(); TrigonometryObject.Register(); ThisConstant.Register(); BooleanValue.Register(); ComplexValue.Register(); DecimalValue.Register(); NullValue.Register(); }
/// <summary> /// Executes a command based on the parameters passed in by the user /// </summary> /// <param name="args">String array that is passed in by the user from the command line (exactly the same as args[] passed into the Main function).</param> /// <returns>True if the command was executed successfully. Successful execution is defined in your command functions.</returns> public int ExecuteCommand(string[] args) { try { int CRESULT; if (args.Contains("-h") || args.Contains("-?")) { return(HelpFunction.Invoke()); } // check if there's a default command // and if there is, check if we use the default or another command // by checking if there is either: // A) There are no args, in which case the default is the only option. // B) There are args, but the first one is a switch if (hasDefaultCommand && UseDefaultCommand(args)) { CRESULT = DefaultCommand.ExecuteCommand(args); } else { if (args.Length == 0) { ConsoleLogger.PrintError("No command found."); return(HelpFunction.Invoke()); } string cmd = args[0].ToLower(); if (!_commands.ContainsKey(cmd)) { ConsoleLogger.PrintError("Unknown command \"" + cmd + "\"."); return(HelpFunction.Invoke()); } string[] switches = new string[args.Length - 1]; Array.Copy(args, 1, switches, 0, args.Length - 1); // Cmd is guaranteed to only contain 1 element at this point // Get the first element in cmd where the Command invocation string equals cmd, and execute that command, passing in switches. CRESULT = _commands[cmd].ExecuteCommand(switches); } if (CRESULT != 0) { if (ErrorCodes.ContainsKey(CRESULT)) { ConsoleLogger.PrintError(ErrorCodes[CRESULT]); } else { ConsoleLogger.PrintDebug("WARNING: Returning an error code not defined in CommandManager.ErrorCodes: " + CRESULT); } } return(CRESULT); } catch (Exception e) { ConsoleLogger.PrintDebug("FATAL ERROR: " + e.ToString()); ConsoleLogger.PrintDebug(e.StackTrace); return(1); } }
public List <CrowData> QueryCrowDatas(int id, string actorName, int category) { List <CrowData> listResult = new List <CrowData>(); using (userEntities userEntities = new userEntities()) { try { var res = from a in userEntities.crowd_funding join u in userEntities.user_base on a.cf_owner_id equals u.user_uid join t in userEntities.category on a.cf_category equals t.fc_id where a.cf_category == category select new { a.id, a.cf_category, t.fc_name, a.cf_name, u.user_nick, a.cf_begin_time, a.cf_end_time, a.cf_fund_end, a.cf_front_icon, a.cf_front_icon_type, a.cf_video_thumbnail, a.cf_created_time }; if (id != -1) { res = res.Where(p => p.id == id); } if (!string.IsNullOrEmpty(actorName)) { res = res.Where(p => p.user_nick.Contains(actorName)); } int index = 1; foreach (var item in res) { string img = item.cf_front_icon; if (item.cf_front_icon_type == 1) { img = item.cf_video_thumbnail; } listResult.Add(new CrowData() { Id = item.id, ActorName = item.user_nick, BeginTime = HelpFunction.GetDateTime(item.cf_begin_time), EndTime = HelpFunction.GetDateTime(item.cf_end_time), Category = item.fc_name, CreatTime = HelpFunction.GetDateTime(item.cf_created_time), FundEnd = item.cf_fund_end, Title = item.cf_name, FrontImg = img, Num = index }); index++; } } catch (Exception ex) { Trace.WriteLine(ex); } } return(listResult); }
/// <summary> /// 0 新建 1 待审核 2 审核通过 3 取消 4 作废 5 退款 6 完成 /// </summary> /// <param name="orderNo"></param> /// <param name="cfId"></param> /// <param name="status"></param> /// <returns></returns> public List <OrderModel> GetOrders(string orderNo, string cfId, int status) { List <OrderModel> list = new List <OrderModel>(); using (userEntities dataEntities = new userEntities()) { try { var cf = dataEntities.crowd_funding.SingleOrDefault(p => p.id.ToString() == cfId); var res = dataEntities.order.Where(p => p.id >= 0); if (!string.IsNullOrEmpty(cfId)) { res = res.Where(p => p.order_type_id.ToString() == cfId); } if (status >= 0) { res = res.Where(p => p.status == status); } if (!string.IsNullOrEmpty(orderNo)) { res = res.Where(p => p.order_code == orderNo); } int index = 1; var listOrder = res.ToList(); foreach (var item in listOrder) { OrderModel model = new OrderModel(); model.Buyer = item.buyer; if (item.create_time.HasValue) { model.CreateTime = HelpFunction.ConvertToDateTime(item.create_time.Value).ToString("yyyy-MM-dd HH:mm:ss"); } model.Num = index; model.OrderNo = item.order_code; model.Status = GeState(item.status); model.OrderType = item.order_type.ToString(); model.IsEnableCancelOrder = false; model.PayStatus = item.paystatus;//0 待支付 1已支付 2支付取消 3已退款 model.PayStatusText = GetPayState(item.paystatus); if (item.paystatus == 1) { if (item.order_type == 0) { if (cf != null) { DateTime?end = HelpFunction.GetDateTime(cf.cf_end_time); if (end.HasValue && end.Value < DateTime.Now) { model.IsEnableCancelOrder = true; } } } else { model.IsEnableCancelOrder = true; } } model.ProductName = item.product_name; model.Seller = item.seller; model.ServerAddress = item.service_location; model.Buyer = item.buyer; if (item.service_time.HasValue) { model.ServerTime = HelpFunction.ConvertToDateTime(item.service_time.Value).ToString("yyyy-MM-dd HH:mm:ss"); } list.Add(model); index++; } } catch (Exception ex) { Trace.WriteLine(ex); } } return(list); }
public static byte[] GetBytesFromTextString(string textStr, string cr) { return(HelpFunction.ConvertStringToBytes(textStr, cr)); }
public string GetTextString() { return(HelpFunction.ConvertBytesToString(Content)); }
private List <HitPoint> sortCriticalPointClockWise(List <HitPoint> list) { list.Sort(compareByAngle); criticalPointDebug = list.ToArray(); Debug.Log("Range" + range); int round = 1; bool flag = false; if (!rangeEffect) { Debug.Log("Rearrange the point order"); int cur = 0; // the index of previous node int pre = list.Count - 1; // the index of next node int next = 1; while (cur < list.Count + 1 && round < 3) { if (cur == list.Count) { cur = 0; round++; } int end = cur; while (end + 1 < list.Count && compareByAngle(list[end], list[end + 1]) == 0) { end++; next++; next %= list.Count; } // List with index from "cur" to "end" are all in the same line if (end > cur && flag) { Vector2 preNode = list[pre].location; Vector2 nextNode = list[next].location; bool test; if (cur == 0) { test = isInSameObstaclesLine(list[end].location, nextNode); } else { test = isInSameObstaclesLine(list[cur].location, preNode); } if (!test) { // swap the order swapOrder(list, cur, end); } } else { flag = true; } cur = end + 1; pre = end; next = cur + 1; if (next >= list.Count) { next -= list.Count; } } } else // with range effect { int cur = 0; // the index of previous node int pre = list.Count - 1; // the index of next node int next = 1; while (cur < list.Count + 1 && round < 3) { if (cur == list.Count) { cur = 0; round++; } int end = cur; while (end + 1 < list.Count && compareByAngle(list[end], list[end + 1]) == 0) { end++; next++; next %= list.Count; } // List with index from "cur" to "end" are all in the same line if (end > cur && flag) { HitPoint preNode = list[pre]; HitPoint nextNode = list[next]; HitPoint curNode = list[cur]; HitPoint endNode = list[end]; if (preNode.obstacleIndex != curNode.obstacleIndex) { if (endNode.obstacleIndex == preNode.obstacleIndex) { // swap the order swapOrder(list, cur, end); } else if (nextNode.obstacleIndex == curNode.obstacleIndex) { // swap the order swapOrder(list, cur, end); } } else if (HelpFunction.isConcave(list.ToArray()) != -1) { Debug.Log("Further swap"); if (!HelpFunction.isInRangeBound(preNode.location, viewpoint.transform.position, range) || !HelpFunction.isInRangeBound(curNode.location, viewpoint.transform.position, range)) { bool test1 = isInSameObstaclesLine(preNode.location, curNode.location); if (!isInSameObstaclesLine(preNode.location, curNode.location)) { // swap the order swapOrder(list, cur, end); } } else if (!HelpFunction.isInRangeBound(endNode.location, viewpoint.transform.position, range) || !HelpFunction.isInRangeBound(nextNode.location, viewpoint.transform.position, range)) { bool test2 = isInSameObstaclesLine(endNode.location, nextNode.location); if (!isInSameObstaclesLine(endNode.location, nextNode.location)) { // swap the order swapOrder(list, cur, end); } } } //if (cur == 0) //{ // test = list[end].obstacleIndex == nextNode.obstacleIndex; //} //else //{ // test = list[cur].obstacleIndex == preNode.obstacleIndex; //} //test = list[cur].obstacleIndex //if (!test) //{ // // swap the order // swapOrder(list, cur, end); //} } else { flag = true; } cur = end + 1; pre = end; next = cur + 1; if (next >= list.Count) { next -= list.Count; } } } return(list); }
private void GenerateLineCast(GameObject viewpoint, OBSTACLE.Obstacle endPoints, Vector2 direction, int endPointIndex) { HitPoint hitPoint = new HitPoint(); RaycastHit2D[] rayCastHits2D; rayCastHits2D = Physics2D.RaycastAll(viewpoint.transform.position, direction); if (rayCastHits2D.Length > 0) { if (!HelpFunction.Vector2Equal(endPoints.obstaclePoints[endPointIndex], rayCastHits2D[0].point)) { if ((rayCastHits2D[0].point - new Vector2(viewpoint.transform.position.x, viewpoint.transform.position.y)).magnitude > new Vector2(endPoints.obstaclePoints[endPointIndex].x - viewpoint.transform.position.x, endPoints.obstaclePoints[endPointIndex].y - viewpoint.transform.position.y).magnitude) { // force to add the critical point if ((endPoints.obstaclePoints[endPointIndex] - viewpoint.transform.position).magnitude < range) { addPointToCriticalList(new HitPoint(endPoints.obstaclePoints[endPointIndex], endPoints.index)); } } } foreach (RaycastHit2D rayCastHit2D in rayCastHits2D) { Vector2 temp = new Vector2(rayCastHit2D.point.x - viewpoint.transform.position.x , rayCastHit2D.point.y - viewpoint.transform.position.y); // if the hit result is the same position as obstacle position if (HelpFunction.Vector2Equal(rayCastHit2D.point, endPoints.obstaclePoints[endPointIndex])) { // If the hit point is out of the range if (temp.magnitude > range) { hitPoint.location = new Vector2(viewpoint.transform.position.x, viewpoint.transform.position.y) + direction.normalized * range; hitPoint.obstacleIndex = endPoints.index; addPointToCriticalList(hitPoint); } else { // If the neighbour endpoints of the hitting result are both in the one side, keep the hitting result Vector3 prev = endPoints.obstaclePoints[(endPointIndex + endPoints.obstaclePoints.Length - 1) % endPoints.obstaclePoints.Length]; Vector3 next = endPoints.obstaclePoints[(endPointIndex + 1) % endPoints.obstaclePoints.Length]; if (AreSameSide(new Vector2(rayCastHit2D.point.x - viewpoint.transform.position.x, rayCastHit2D.point.y - viewpoint.transform.position.y) , prev - viewpoint.transform.position, next - viewpoint.transform.position)) { addPointToCriticalList(new HitPoint(rayCastHit2D.point, endPoints.index)); if (!bMesh) { GenerateVisibilityEffectWithLine(viewpoint, rayCastHit2D.point); } continue; } else { hitPoint.location = rayCastHit2D.point; hitPoint.obstacleIndex = endPoints.index; addPointToCriticalList(hitPoint); break; } } } else { hitPoint.location = rayCastHit2D.point; // find the index of obstacle in the hit point foreach (OBSTACLE.Obstacle obstacle in ObstaclesLine) { if (HelpFunction.isInObstacle(hitPoint.location, obstacle.obstaclePoints)) { hitPoint.obstacleIndex = obstacle.index; break; } } if (temp.magnitude > range) { hitPoint.location = new Vector2(viewpoint.transform.position.x, viewpoint.transform.position.y) + direction.normalized * range; } addPointToCriticalList(hitPoint); break; } } if (!bMesh) { GenerateVisibilityEffectWithLine(viewpoint, hitPoint.location); } } }