コード例 #1
0
ファイル: Scatter.cs プロジェクト: Yinzhe-Qi/RPS
        /// <summary>
        /// 线段类的单元测试
        /// </summary>
        /// <param name="epsilon"></param>
        /// <returns></returns>
        public static string RunTest(double epsilon = 1e-3)
        {
            DateTime time = DateTime.Now;
            StringBuilder sb = new StringBuilder("Scatter Class Test Begin at " + time.ToString("yyyy-MM-dd HH:mm:ss") + "\n");
            test_log.Add(time, "");

            //test IsSegmentsLegal
            sb.AppendLine("----------------------------");
            sb.AppendLine("IsSegmentsLegal test 1");
            LineSegment[] segs = null;
            Debug.Assert(new Scatter().IsSegmentsLegal(segs) == false, "result should be false");
            sb.AppendLine("IsSegmentsLegal test 2");
            segs = new LineSegment[] { new LineSegment(new Point(0, 0), new Point(1, 1)) };
            Debug.Assert(new Scatter().IsSegmentsLegal(segs) == false, "result should be false");
            sb.AppendLine("IsSegmentsLegal test 3");
            segs = new LineSegment[] { new LineSegment(new Point(0, 0), new Point(1, 1)), 
                                       new LineSegment(new Point(1, 1), new Point(1, 0)), 
                                       new LineSegment(new Point(1, 0), new Point(0, 0)) };
            Debug.Assert(new Scatter().IsSegmentsLegal(segs) == true, "result should be true");
            sb.AppendLine("IsSegmentsLegal test 4");
            segs = new LineSegment[] { new LineSegment(new Point(0, 0), new Point(0, 1)),
                                       new LineSegment(new Point(0, 1), new Point(1, 1)),
                                       new LineSegment(new Point(1, 1), new Point(1, 0)), 
                                       new LineSegment(new Point(1, 0), new Point(0, 0)) };
            Debug.Assert(new Scatter().IsSegmentsLegal(segs) == true, "result should be true");
            sb.AppendLine("IsSegmentsLegal test 5");
            segs = new LineSegment[] { new LineSegment(new Point(0, 0), new Point(0, 1)),
                                       new LineSegment(new Point(1, 1), new Point(1, 0)), 
                                       new LineSegment(new Point(1, 0), new Point(0, 0)) };
            Debug.Assert(new Scatter().IsSegmentsLegal(segs) == false, "result should be false");
            sb.AppendLine("IsSegmentsLegal test 6");
            segs = new LineSegment[] { new LineSegment(new Point(0, 0), new Point(0, 1)),
                                       new LineSegment(new Point(0, 1), new Point(1, 1)),
                                       new LineSegment(new Point(1, 1), new Point(1, 0)), 
                                       new LineSegment(new Point(1, 0), new Point(0, 0)),
                                       new LineSegment(new Point(0, 0), new Point(0, 1)) };
            Debug.Assert(new Scatter().IsSegmentsLegal(segs) == false, "result should be false");
            sb.AppendLine("IsSegmentsLegal test 7");
            segs = new LineSegment[] { new LineSegment(new Point(0, 0), new Point(0, 1)),
                                       new LineSegment(new Point(0, 1), new Point(1, 1)),
                                       new LineSegment(new Point(1, 1), new Point(1, 0)), 
                                       new LineSegment(new Point(1, 0), new Point(0, 0)),
                                       new LineSegment(new Point(0, 0), new Point(2, 1)) };
            Debug.Assert(new Scatter().IsSegmentsLegal(segs) == false, "result should be false");
            sb.AppendLine("IsSegmentsLegal test 8");
            segs = new LineSegment[] { new LineSegment(new Point(0, 0), new Point(0, 2)),
                                       new LineSegment(new Point(0, 2), new Point(1, 2)),
                                       new LineSegment(new Point(1, 2), new Point(1, 4)), 
                                       new LineSegment(new Point(1, 4), new Point(0, 4)),
                                       new LineSegment(new Point(0, 4), new Point(0, 6)),
                                       new LineSegment(new Point(0, 6), new Point(2, 6)),
                                       new LineSegment(new Point(2, 6), new Point(2, 4)),
                                       new LineSegment(new Point(2, 4), new Point(4, 4)),
                                       new LineSegment(new Point(4, 4), new Point(4, 2)),
                                       new LineSegment(new Point(4, 2), new Point(2, 2)), 
                                       new LineSegment(new Point(2, 2), new Point(2, 0)), 
                                       new LineSegment(new Point(2, 0), new Point(0, 0))};
            Debug.Assert(new Scatter().IsSegmentsLegal(segs) == true, "result should be true");
            sb.AppendLine("IsSegmentsLegal test 9");
            Point[] pts = new Point[] { new Point(0, 0), new Point(0, 2),
                                        new Point(1, 2),
                                        new Point(1, 4), 
                                        new Point(0, 4),
                                        new Point(0, 6),
                                        new Point(2, 6),
                                        new Point(2, 4),
                                        new Point(4, 4),
                                        new Point(4, 2),
                                        new Point(2, 2), 
                                        new Point(2, 0) };
            Scatter s = new Scatter(pts);

            //test BorderRect
            sb.AppendLine("----------------------------");
            LineSegment[] sgs = new LineSegment[] { new LineSegment(new Point(0, 0), new Point(0, 2)),
                                                   new LineSegment(new Point(0, 2), new Point(1, 2)),
                                                   new LineSegment(new Point(1, 2), new Point(1, 4)), 
                                                   new LineSegment(new Point(1, 4), new Point(0, 4)),
                                                   new LineSegment(new Point(0, 4), new Point(0, 6)),
                                                   new LineSegment(new Point(0, 6), new Point(2, 6)),
                                                   new LineSegment(new Point(2, 6), new Point(2, 4)),
                                                   new LineSegment(new Point(2, 4), new Point(4, 4)),
                                                   new LineSegment(new Point(4, 4), new Point(4, 2)),
                                                   new LineSegment(new Point(4, 2), new Point(2, 2)), 
                                                   new LineSegment(new Point(2, 2), new Point(2, 0)), 
                                                   new LineSegment(new Point(2, 0), new Point(0, 0))};
            s = new Scatter(sgs, SCATTER_SEG_DIRECTION.ANTI_CLOCKWISE);
            sb.AppendLine("BorderRect test 1");
            Debug.Assert(s.BorderRect == new Rectangle(0, 0, 4, 6), "rect should be (0, 0, 4, 6)");
            sb.AppendLine("BorderRect test 2");
            sgs = new LineSegment[] { new LineSegment(new Point(2, 0), new Point(0, 2)),
                                    new LineSegment(new Point(0, 2), new Point(2, 4)),
                                    new LineSegment(new Point(2, 4), new Point(4, 2)), 
                                    new LineSegment(new Point(4, 2), new Point(2, 0)) };
            s = new Scatter(sgs, SCATTER_SEG_DIRECTION.ANTI_CLOCKWISE);
            Debug.Assert(s.BorderRect == new Rectangle(0, 0, 4, 4), "rect should be (0, 0, 4, 4)");

            //test GetClosestReflectionPoint
            sb.AppendLine("----------------------------");
            sgs = new LineSegment[] { new LineSegment(new Point(0, 0), new Point(0, 2)),
                                    new LineSegment(new Point(0, 2), new Point(1, 2)),
                                    new LineSegment(new Point(1, 2), new Point(1, 4)), 
                                    new LineSegment(new Point(1, 4), new Point(0, 4)),
                                    new LineSegment(new Point(0, 4), new Point(0, 6)),
                                    new LineSegment(new Point(0, 6), new Point(2, 6)),
                                    new LineSegment(new Point(2, 6), new Point(2, 4)),
                                    new LineSegment(new Point(2, 4), new Point(4, 4)),
                                    new LineSegment(new Point(4, 4), new Point(4, 2)),
                                    new LineSegment(new Point(4, 2), new Point(2, 2)), 
                                    new LineSegment(new Point(2, 2), new Point(2, 0)), 
                                    new LineSegment(new Point(2, 0), new Point(0, 0))};
            s = new Scatter(sgs, SCATTER_SEG_DIRECTION.ANTI_CLOCKWISE);
            LineSegment ss;
            sb.AppendLine("GetClosestReflectionPoint test 1");
            LineSegment seg = new LineSegment(new Point(0, 10), new Point(10, 10));
            Debug.Assert(s.GetClosestReflectionPoint(seg, out ss) == null && ss == null, "point should be null");
            sb.AppendLine("GetClosestReflectionPoint test 2");
            seg = new LineSegment(new Point(0, 2), new Point(8, 2));
            //Point? aaa = s.GetClosestReflectionPoint(seg, out ss);
            //Debug.Assert(aaa.Value == new Point(0, 2));
            Debug.Assert(s.GetClosestReflectionPoint(seg, out ss) == new Point(0, 2), "point should be (0, 2)");

            test_log[time] = sb.ToString();
            return test_log[time];
        }
コード例 #2
0
ファイル: FormMainWindow.cs プロジェクト: Yinzhe-Qi/RPS
 /// <summary>
 /// 添加散射体
 /// </summary>
 /// <param name="scatter"></param>
 public void AddScatter(Scatter scatter)
 {
     try
     {
         this.viz_rps.Map.AddScatter(scatter);
         ListViewItem lvi = new ListViewItem(scatter.Name);
         lvi.SubItems.Add(scatter.BorderRect.ToString());
         lvi.Name = scatter.Name;
         this.lvScatters.Items.Add(lvi);
         this.RePaint();
     }
     catch (Exception ex)
     {
         MessageBox.Show("添加散射体失败:\n" + ex.Message);
     }
 }
コード例 #3
0
ファイル: Scatter.cs プロジェクト: Yinzhe-Qi/RPS
 public ScatterEnumerator(Scatter[] scatter)
 {
     this.scatters = scatter.Clone() as Scatter[];
 }
コード例 #4
0
ファイル: Scatter.cs プロジェクト: Yinzhe-Qi/RPS
 public ScatterCollection(Scatter[] s)
 {
     this.scatters = s;
 }
コード例 #5
0
ファイル: Scatter.cs プロジェクト: Yinzhe-Qi/RPS
 /// <summary>
 /// 判断两个散射体是否有交集
 /// </summary>
 /// <param name="that"></param>
 /// <returns></returns>
 public bool JudgeIntersection(Scatter that)
 {
     if(this.BorderRect.IntersectsWith(that.BorderRect)) //先通过边界矩形快速判断
     {
         foreach (LineSegment l1 in this.BorderSegments)
             foreach (LineSegment l2 in that.BorderSegments)
                 if (l1.JudgeIntersection(l2))
                     return true;
     }
     return false;
 }
コード例 #6
0
ファイル: Map.cs プロジェクト: Yinzhe-Qi/RPS
 /// <summary>
 /// 添加散射体
 /// </summary>
 /// <param name="scatter"></param>
 public void AddScatter(Scatter scatter)
 {
     if (scatter.BorderRect.Top < 0 || scatter.BorderRect.Bottom > this.Size.Height - 1 || scatter.BorderRect.Left < 0 || scatter.BorderRect.Right > this.Size.Width - 1)
         throw new Exception("添加散射体失败:散射体的一部分在地图范围外!");
     foreach (Transmitter tr in this.transmitters.Values)
         if (scatter.IsPointInside(tr.Location))
             throw new Exception("添加散射体失败:现有发射机位于该散射体内部!");
     foreach (Receiver re in this.receivers.Values)
         if (scatter.IsPointInside(re.Location))
             throw new Exception("添加散射体失败:现有接收机位于该散射体内部!");
     foreach (Scatter s in this.scatters.Values)
     {
         if (s.JudgeIntersection(scatter))
             throw new Exception("添加散射体失败:与现有散射体重叠!");
         if (s.Name == scatter.Name)
             throw new Exception("添加散射体失败:名称与现有散射体相同!");
     }
     this.scatters[scatter.Name] = scatter;
 }
コード例 #7
0
ファイル: Map.cs プロジェクト: Yinzhe-Qi/RPS
 public Map(Image im, double meter_pxl_ratio, double power_th, int grid_width, Scatter[] scatters)
 {
     if (im == null)
         throw new Exception("地图图像不能为空!");
     if (meter_pxl_ratio <= 0)
         throw new Exception("比例尺应大于0!");
     if (power_th <= 0 || power_th >= 1)
         throw new Exception("功率阈值应在0到1之间!");
     this.image = im;
     this.MeterPixelRatio = meter_pxl_ratio;
     this.GridWidth = grid_width;
     foreach (Scatter s in scatters)
         this.AddScatter(s);
 }