コード例 #1
0
ファイル: LineSearchGridTest.cs プロジェクト: abordt/Viking
        public void LineSearchGridTestMethod()
        {
            LineSearchGrid<string> LineSearch = new LineSearchGrid<string>(new GridRectangle(-10, 10, -10, 10), 500);

            GridLineSegment lineA = new GridLineSegment(new GridVector2(-5, 3),
                                                        new GridVector2(5, 3));
            GridLineSegment lineB = new GridLineSegment(new GridVector2(3, -5),
                                                        new GridVector2(3, 5));
            GridLineSegment lineC = new GridLineSegment(new GridVector2(-6, -5),
                                                        new GridVector2(-6, 5));
            GridLineSegment lineD = new GridLineSegment(new GridVector2(-9, 8),
                                                        new GridVector2(1, -8)); //Should be in seven grid cells
            GridLineSegment lineE = new GridLineSegment(new GridVector2(-9, 8),
                                                        new GridVector2(1, -2));

            LineSearch.Add(lineA, "A");
            LineSearch.Add(lineB, "B");
            LineSearch.Add(lineC, "C");
            LineSearch.Add(lineD, "D");
            LineSearch.Add(lineE, "E");

            GridVector2 intersection;
            double distance;
            string value = LineSearch.GetNearest(new GridVector2(-5, 3), out intersection, out distance);
            Debug.Assert(value == "A");

            value = LineSearch.GetNearest(new GridVector2(-10, -10), out intersection, out distance);
            Debug.Assert(value == "C");

            value = LineSearch.GetNearest(new GridVector2(7, 4), out intersection, out distance);
            Debug.Assert(value == "A");

            value = LineSearch.GetNearest(new GridVector2(3.5, 6), out intersection, out distance);
            Debug.Assert(value == "B");
        }
コード例 #2
0
ファイル: LineSearchGridTest.cs プロジェクト: abordt/Viking
        public void LineSearchGridTestMethod()
        {
            LineSearchGrid<GridVector2> LineSearch = new LineSearchGrid<GridVector2>(new GridRectangle(-10, 10, -10, 10), 500);

            GridLineSegment lineA = new GridLineSegment(new GridVector2(-5, 3),
                                                        new GridVector2(5, 3));
            GridLineSegment lineB = new GridLineSegment(new GridVector2(3, -5),
                                                        new GridVector2(3, 5));
            GridLineSegment lineC = new GridLineSegment(new GridVector2(-6, -5),
                                                        new GridVector2(-6, 5));
            GridLineSegment lineD = new GridLineSegment(new GridVector2(-9, 8),
                                                        new GridVector2(1, -8));
            GridLineSegment lineE = new GridLineSegment(new GridVector2(-9, 8),
                                                        new GridVector2(1, -2));

            LineSearch.Add(lineA, lineA.A);
            LineSearch.Add(lineB, lineB.A);
            LineSearch.Add(lineC, lineC.A);
            LineSearch.Add(lineD, lineD.A);
            LineSearch.Add(lineE, lineE.B);

            GridVector2 intersection;
            double distance;
            GridVector2 value = LineSearch.GetNearest(new GridVector2(-5, 3), out intersection, out distance);
            Debug.Assert(value == lineA.A);

            value = LineSearch.GetNearest(new GridVector2(-10, -10), out intersection, out distance);
            Debug.Assert(value == lineC.A);
        }