Esempio n. 1
0
        /// <summary>
        /// Filters out only objects in a person's direction of a view
        /// </summary>
        private IEnumerable <string> FilterObjectsByPositionAndBearing(OsmObjectsOfImportance objects, GeoPoint position, double bearing)
        {
            Debug.Assert(objects != null, "objects == null");
            Debug.Assert(position != null, "position == null");

            var testingPoints = GetPointsAlongBearing(position, bearing);

            // filter objects
            var filterSingleNodesTask   = Task.Factory.StartNew(() => FilterSingleNodes(objects.SingleNodes, testingPoints));
            var filterBuildingsWaysTask = Task.Factory.StartNew(() =>
            {
                // filter buildings' ways by testing if some point along a person's direction of view is inside the way
                foreach (var point in testingPoints)
                {
                    foreach (var way in objects.BuildingsWays)
                    {
                        if (GeoCalc.IsPointInsidePolygon(point, way.Nodes))
                        {
                            return new { TestingPoint = point, Way = way }
                        }
                        ;
                    }
                }
                return(null);
            });

            Task.WaitAll(filterSingleNodesTask, filterBuildingsWaysTask);

            // print out objects' descriptions
            var building = filterBuildingsWaysTask.Result;

            if (building != null)
            {
                yield return(BuildingWayDescription(building.Way));
            }
            foreach (var node in filterSingleNodesTask.Result)
            {
                if (building == null ||
                    GeoCalc.GetDistance(node, building.TestingPoint) < Adjustment.MaxDeviationFromBearingBuildingIntersection)
                {
                    yield return(SingleNodeDescription(node));
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Filters single nodes by testing whether they are close to the points along a person's direction of view
        /// </summary>
        private ICollection <OsmNode> FilterSingleNodes(ICollection <OsmNode> singleNodes, IEnumerable <GeoPoint> testingPoints)
        {
            Debug.Assert(singleNodes != null, "singleNodes == null");
            Debug.Assert(testingPoints != null, "testingPoints == null");

            var result = new List <OsmNode>();

            foreach (var point in testingPoints)
            {
                foreach (var node in singleNodes)
                {
                    if (!result.Contains(node) && GeoCalc.GetDistance(point, node) < Adjustment.MaxDeviationFromBearing)
                    {
                        result.Add(node);
                    }
                }
            }
            return(result);
        }