コード例 #1
0
ファイル: BBoxTest.cs プロジェクト: guifa/traveltimeanalysis
        public void BBoxCornersReturnsCorners()
        {
            BBox target = new BBox() { North = 10, South = 8, East = 9, West = 7 };

            PointGeo corner1 = new PointGeo(10, 9);
            PointGeo corner2 = new PointGeo(10, 7);
            PointGeo corner3 = new PointGeo(8, 9);
            PointGeo corner4 = new PointGeo(8, 7);

            Assert.Contains(corner1, target.Corners);
            Assert.Contains(corner2, target.Corners);
            Assert.Contains(corner3, target.Corners);
            Assert.Contains(corner4, target.Corners);
        }
コード例 #2
0
ファイル: BBoxTest.cs プロジェクト: guifa/traveltimeanalysis
        public void BBoxConstructorIEnumerableSetsBound()
        {
            PointGeo p1 = new PointGeo(15, 10, -100);
            PointGeo p2 = new PointGeo(-15, -10, 1000);

            BBox target = new BBox(new IPointGeo[] { p1, p2 });

            Assert.Equal(15, target.North);
            Assert.Equal(-15, target.South);
            Assert.Equal(10, target.East);
            Assert.Equal(-10, target.West);

            Assert.Equal(-100, target.MinElevation);
            Assert.Equal(1000, target.MaxElevation);
        }
コード例 #3
0
ファイル: BBoxTest.cs プロジェクト: guifa/traveltimeanalysis
        public void BBoxExtendToCoverInflatesBBox()
        {
            PointGeo p1 = new PointGeo(12.1, 18.3, 100);
            PointGeo p2 = new PointGeo(-12.9, -34.3, 500);

            BBox target = new BBox();
            target.ExtendToCover(p1);
            target.ExtendToCover(p2);

            Assert.Equal(12.1, target.North);
            Assert.Equal(-12.9, target.South);
            Assert.Equal(18.3, target.East);
            Assert.Equal(-34.3, target.West);

            Assert.Equal(100, target.MinElevation);
            Assert.Equal(500, target.MaxElevation);
        }
コード例 #4
0
        /// <summary>
        /// Finds all candidates points for given GPS track point
        /// </summary>
        /// <param name="gpxPt">GPS point</param>
        /// <returns>Collection of points candidate points on road segments</returns>
        public IEnumerable<CandidatePoint> FindCandidatePoints(GPXPoint gpxPt)
        {
            List<CandidatePoint> result = new List<CandidatePoint>();
            BBox gpxBbox = new BBox(new IPointGeo[] { gpxPt });
            gpxBbox.Inflate(0.0007, 0.0011);

            foreach (var road in _trackCutout) {
                if (Topology.Intersects(gpxBbox, road.BBox)) {
                    Segment<IPointGeo> roadSegment;
                    IPointGeo projectedPoint = Topology.ProjectPoint(gpxPt, road, out roadSegment);
                    result.Add(new CandidatePoint() { MapPoint = projectedPoint,
                                                        Road = road, RoadSegment = roadSegment,
                                                                                        ObservationProbability = CalculateObservationProbability(gpxPt, projectedPoint) });
                }
            }

            if (result.Count == 0) {
                throw new Exception(string.Format("Can not find any candidate point for {0}", gpxPt));
            }

            return result;
        }
コード例 #5
0
        void CreateTrackCutout(GPXTrackSegment track)
        {
            _trackCutout.Clear();

            BBox trackBBox = new BBox();
            foreach (var point in track.Nodes) {
                trackBBox.ExtendToCover(point);
            }
            trackBBox.Inflate(0.0015, 0.0015);

            foreach (var road in _graph.ConnectionGeometries) {
                if (Topology.Intersects(road.BBox, trackBBox)) {
                    _trackCutout.Add(road);
                }
            }
        }
コード例 #6
0
ファイル: Topology.cs プロジェクト: guifa/traveltimeanalysis
 /// <summary>
 /// Tests whether two BBoxes have non-empty intersection 
 /// </summary>
 /// <param name="bbox1">First BBox</param>
 /// <param name="bbox2">Second BBox</param>
 /// <returns>true if bbox have non-empty intersection, otherwise returns false</returns>
 public static bool Intersects(BBox bbox1, BBox bbox2)
 {
     return !(bbox2.West > bbox1.East || bbox2.East < bbox1.West || bbox2.South > bbox1.North || bbox2.North < bbox1.South);
 }
コード例 #7
0
ファイル: BBoxTest.cs プロジェクト: guifa/traveltimeanalysis
        public void BBoxInflateIncreasesBBoxSize()
        {
            PointGeo p1 = new PointGeo(1, 0);
            PointGeo p2 = new PointGeo(0, 1);

            BBox target = new BBox(new IPointGeo[] { p1, p2 });

            target.Inflate(0.1, 0.2);

            Assert.Equal(1.1, target.North);
            Assert.Equal(-0.1, target.South);
            Assert.Equal(1.2, target.East);
            Assert.Equal(-0.2, target.West);
        }
コード例 #8
0
ファイル: BBoxTest.cs プロジェクト: guifa/traveltimeanalysis
        public void BBoxIsInsideReturnsTrueForPointOnBoundary()
        {
            PointGeo p1 = new PointGeo(15, 10, -100);
            PointGeo p2 = new PointGeo(-15, -10, 1000);

            PointGeo pTestLat = new PointGeo(15, 0, 0);
            PointGeo pTestLat2 = new PointGeo(-15, 0, 0);
            PointGeo pTestLon = new PointGeo(0, 10, 0);
            PointGeo pTestLon2 = new PointGeo(0, -10, 0);
            PointGeo pTestEle = new PointGeo(0, 0, -100);
            PointGeo pTestEle2 = new PointGeo(0, 0, 1000);

            BBox target = new BBox(new IPointGeo[] { p1, p2 });

            Assert.True(target.IsInside(pTestLat), "Latitude");
            Assert.True(target.IsInside(pTestLon), "Longitude");
            Assert.True(target.IsInside(pTestEle), "Elevation");

            Assert.True(target.IsInside(pTestLat2), "Latitude");
            Assert.True(target.IsInside(pTestLon2), "Longitude");
            Assert.True(target.IsInside(pTestEle2), "Elevation");
        }
コード例 #9
0
ファイル: BBoxTest.cs プロジェクト: guifa/traveltimeanalysis
        public void BBoxIsInsideReturnsTrueIfPointIsInside()
        {
            PointGeo p1 = new PointGeo(15, 10, -100);
            PointGeo p2 = new PointGeo(-15, -10, 1000);
            PointGeo pTest = new PointGeo(0, 0, 0);

            BBox target = new BBox(new IPointGeo[] { p1, p2 });

            Assert.True(target.IsInside(pTest));
        }
コード例 #10
0
ファイル: BBoxTest.cs プロジェクト: guifa/traveltimeanalysis
        public void BBoxIsInsideReturnsFalseIfPointIsOutside()
        {
            PointGeo p1 = new PointGeo(15, 10, -100);
            PointGeo p2 = new PointGeo(-15, -10, 1000);

            PointGeo pTestLat = new PointGeo(30, 0, 0);
            PointGeo pTestLon = new PointGeo(0, 30, 0);
            PointGeo pTestEle = new PointGeo(30, 0, 5000);

            BBox target = new BBox(new IPointGeo[] { p1, p2 });

            Assert.False(target.IsInside(pTestLat), "Latitude");
            Assert.False(target.IsInside(pTestLon), "Longitude");
            Assert.False(target.IsInside(pTestEle), "Elevation");
        }
コード例 #11
0
        public void IntersectsReturnsTrueForIntersectingBBoxesCrossShape()
        {
            //    ___
            //   |   |
            //  _|___|__
            // |_|___|__|
            //   |___|

            BBox bbox1 = new BBox() { North = 4, South = 0, East = 3, West = 1};
            BBox bbox2 = new BBox() { North = 2, South = 1, East = 4, West = 0};

            Assert.True(Topology.Intersects(bbox1, bbox2));
            Assert.True(Topology.Intersects(bbox2, bbox1));
        }
コード例 #12
0
        public void IntersectsReturnsTrueForIntercestiongBBoxes()
        {
            BBox bbox1 = new BBox() { North = 1, South = -1, East = 1, West = -1 };
            BBox bbox2 = new BBox() { North = 1.5, South = 0.5, East = 1.5, West = 0.5 };

            Assert.True(Topology.Intersects(bbox1, bbox2));
            Assert.True(Topology.Intersects(bbox2, bbox1));
        }
コード例 #13
0
        public void IntersectsReturnsTrueForBBoxInsideLargerOne()
        {
            BBox large = new BBox() { North = 1, South = -1, East = 1, West = -1 };
            BBox small = new BBox() { North = 0.5, South = -0.5, East = 0.5, West = -0.5 };

            Assert.True(Topology.Intersects(large, small));
            Assert.True(Topology.Intersects(small, large));
        }
コード例 #14
0
        public void IntersectsReturnsFalseForNonIntercestiongBBoxes()
        {
            BBox bbox1 = new BBox() { North = 1, South = -1, East = 1, West = -1 };
            BBox bbox2 = new BBox() { North = 1.5, South = 1.1, East = 1.5, West = 1.1 };

            Assert.False(Topology.Intersects(bbox1, bbox2));
            Assert.False(Topology.Intersects(bbox2, bbox1));
        }