Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/polygon intersection #200

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

pietervdvn
Copy link
Contributor

Calculate a polygon intersection with a.IntersectionsWith(b).

Unions and differences are available under a.UnionWith(b) and a.DifferencesWith(b).

The surface area of a polygon can be found with a.SurfaceArea()

@juliusfriedman
Copy link

juliusfriedman commented May 24, 2020

Overall LGTM 👍

@pietervdvn, @xivk

I think in TestExtensions

        /// <summary>
        /// Loads a test network from geojson.
        /// </summary>
        private static IEnumerable<Itinero.LocalGeo.Coordinate> LoadTestPoints(string geoJson)
        {
            var geoJsonReader = new NetTopologySuite.IO.GeoJsonReader();
            var features = geoJsonReader.Read<FeatureCollection>(geoJson);

            foreach (var feature in features)
            {
                if(feature.Geometry is Point point)
                {
                    yield return new Itinero.LocalGeo.Coordinate((float)point.Coordinate.Y, (float)point.Coordinate.X);
                }
                else if(feature.Geometry is NetTopologySuite.Geometries.Polygon polygon)
                {
                    foreach(NetTopologySuite.Geometries.Coordinate coordinate in polygon.Coordinates)
                    {
                        yield return new Itinero.LocalGeo.Coordinate((float)coordinate.Y, (float)coordinate.X);
                    }
                }
            }
        }

Is needed for your LoadTestPolygon to get a polygon with more than 0 points.

I also don't think I see any validation for Polygon like Coordiate has but I assume that because it's made from Coordiates which must be valid?

Perhaps in Polygon

        /// <summary>
        /// Determines if the instance is valid
        /// </summary>
        /// <returns></returns>
        public bool IsValid()
        {
            //Hopefully no repeated points. (Perhaps a Distinct().Count()) would be able to be used instead
            //CheckTooFewPoints
            return ExteriorRing.Count + InteriorRings.Count >= 4;

            //CheckConsistentArea
            //IsSelfTouchingRingFormingHoleValid -> CheckNoSelfIntersectingRings
            //CheckHolesInShell
            //CheckHolesNotNested
            //CheckConnectedInteriors
        }

Also wanted to note that with the changes in Line that RouterTests.TestBicycleWithCyclenetwork then fails at Assert.IsNotNull(route.Value.From.From.From);

Also PolygonIntersection.FollowAlong

if (i == 0 && j == 1)
            {
                i = i;
            }

this code says when i is 0 and j is 1 set i to i which is already equal to 0....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants