示例#1
0
        public void TestOneEdgeExcluded()
        {
            var routerDb = new RouterDb();
            var network  = routerDb.Network;

            network.AddVertex(0, 51.154800936865406f, 4.2070770263671875f);
            network.AddVertex(1, 51.159968767920475f, 4.2235565185546875f);
            var edgeId = network.AddEdge(0, 1, new Itinero.Data.Network.Edges.EdgeData()
            {
                Distance = 57.69f,
                Profile  = 1,
                MetaId   = 10
            });

            var area = new PolygonArea(new Polygon()
            {
                ExteriorRing = new List <Coordinate>(new Coordinate[]
                {
                    new Coordinate(51.27391736369659f, 4.799566268920898f),
                    new Coordinate(51.258531028690626f, 4.78879451751709f),
                    new Coordinate(51.2665873439388f, 4.817891120910644f),
                    new Coordinate(51.27391736369659f, 4.799566268920898f)
                })
            });

            var handler = new AreaMetaDataHandler(routerDb, area);

            handler.NewVertex  += id => { Assert.Fail("This should not be called!"); };
            handler.NewEdge    += (oldEdgeId, newEdgeId) => { Assert.Fail("This should not be called!"); };
            handler.EdgeInside += id => { Assert.Fail("This should not be called!"); };

            handler.Run();
            Assert.IsTrue(handler.HasSucceeded);
        }
示例#2
0
    public static Vector3 RandomPoint(this PolygonArea area)
    {
        switch (area.Vertexes.Count)
        {
        case 0: return(Vector3.zero);

        case 1: return(area.Vertexes[0]);

        case 2: return(RandomPoint(area.Vertexes[0], area.Vertexes[1]));

        case 3: return(area.Triangles[0].RandomTrianglePoint());
        }

        float n = Random.Range(0, area.Area);
        float c = 0;

        for (int i = 0; i < area.TriangleAreas.Count; ++i)
        {
            var triArea = area.TriangleAreas[i];
            c += triArea;
            if (c >= n)
            {
                return(area.Triangles[i].RandomTrianglePoint());
            }
        }
        return(area.Triangles[area.Triangles.Count - 1].RandomTrianglePoint());
    }
示例#3
0
        public void TestOneEdgeIncluded()
        {
            var routerDb = new RouterDb();
            var network  = routerDb.Network;

            network.AddVertex(0, 51.268305f, 4.8014116287231445f);
            network.AddVertex(1, 51.2643048646482f, 4.797978401184082f);
            var edgeId = network.AddEdge(0, 1, new Itinero.Data.Network.Edges.EdgeData()
            {
                Distance = 57.69f,
                Profile  = 1,
                MetaId   = 10
            });

            var area = new PolygonArea(new Polygon()
            {
                ExteriorRing = new List <Coordinate>(new Coordinate[]
                {
                    new Coordinate(51.27391736369659f, 4.799566268920898f),
                    new Coordinate(51.258531028690626f, 4.78879451751709f),
                    new Coordinate(51.2665873439388f, 4.817891120910644f),
                    new Coordinate(51.27391736369659f, 4.799566268920898f)
                })
            });

            var handler = new AreaMetaDataHandler(routerDb, area);

            handler.NewVertex  += id => { Assert.Fail("This should not be called!"); };
            handler.NewEdge    += (oldEdgeId, newEdgeId) => { Assert.Fail("This should not be called!"); };
            handler.EdgeInside += id => { Assert.AreEqual(edgeId, id); };

            handler.Run();
            Assert.IsTrue(handler.HasSucceeded);
        }
示例#4
0
 public PolyPanel()
 {
     InitializeComponent();
     m_poly = new PolygonArea(false);
     m_majorRadiusTextBox.Text = m_poly.MajorRadius.ToString();
     m_flatteningTextBox.Text = m_poly.Flattening.ToString();
     m_lengthTextBox.Text = m_areaTextBox.Text = m_numPointsTextBox.Text = "0";
     m_currLatTextBox.Text = m_currLonTextBox.Text = "";
 }
示例#5
0
 public PolyPanel()
 {
     InitializeComponent();
     m_poly = new PolygonArea(false);
     m_majorRadiusTextBox.Text = m_poly.MajorRadius.ToString();
     m_flatteningTextBox.Text  = m_poly.Flattening.ToString();
     m_lengthTextBox.Text      = m_areaTextBox.Text = m_numPointsTextBox.Text = "0";
     m_currLatTextBox.Text     = m_currLonTextBox.Text = "";
 }
        public ApplicationState()
        {
            this.CurrentArea     = Utilities.Area.Circle;
            this.mCircleArea     = new CircleArea(new Point(-100, -100), 100);
            this.mPolygonArea    = new PolygonArea(new Point(-100, -100));
            this.mWholeImageArea = new WholeImageArea();

            Filter = Filter.Negative;
        }
示例#7
0
        private static void CalcuateLenghtIncrements(List <Coordinate> points)
        {
            // setting the polyline to true allows us
            // to calculate length of a polyline
            var calc = new PolygonArea(Geodesic.WGS84, true);

            foreach (var point in points)
            {
                calc.AddPoint(point.X, point.Y);
                var length = calc.Compute().Perimeter;
                Console.WriteLine("Adding Point({0},{1}) : Curent Length : {2}", point.X, point.Y, length);
            }
        }
示例#8
0
        public void TestOneEdgeSplitInTwo()
        {
            var routerDb = new RouterDb();
            var network  = routerDb.Network;

            network.AddVertex(0, 51.26830584177533f, 4.8014116287231445f);
            network.AddVertex(1, 51.27440062061442f, 4.810037612915039f);
            var edgeId = network.AddEdge(0, 1, new Itinero.Data.Network.Edges.EdgeData()
            {
                Distance = 906.00f,
                Profile  = 1,
                MetaId   = 10
            });
            var futureNewVertexId = network.VertexCount;

            var area = new PolygonArea(new Polygon()
            {
                ExteriorRing = new List <Coordinate>(new Coordinate[]
                {
                    new Coordinate(51.27391736369659f, 4.799566268920898f),
                    new Coordinate(51.258531028690626f, 4.78879451751709f),
                    new Coordinate(51.2665873439388f, 4.817891120910644f),
                    new Coordinate(51.27391736369659f, 4.799566268920898f)
                })
            });

            var handler       = new AreaMetaDataHandler(routerDb, area);
            var newEdgeCalled = 0;
            var newEdges      = new HashSet <uint>();

            handler.NewVertex += id => { Assert.AreEqual(futureNewVertexId, id); };
            handler.NewEdge   += (oldEdgeId, newEdgeId) =>
            { // this should be called twice.
                newEdgeCalled++;
                Assert.AreEqual(edgeId, oldEdgeId);
                newEdges.Add(newEdgeId);
            };
            var edgeInsideCalled = 0;

            handler.EdgeInside += id =>
            { // this should be called only once.
                Assert.AreNotEqual(edgeId, id);
                Assert.IsTrue(newEdges.Contains(id));
                edgeInsideCalled++;
                Assert.AreEqual(1, edgeInsideCalled);
            };

            handler.Run();
            Assert.IsTrue(handler.HasSucceeded);
            Assert.AreEqual(2, newEdgeCalled);
        }
示例#9
0
        private static void CalculateLength(List <Coordinate> points)
        {
            // setting the polyline to true allows us
            // to calculate length of a polyline
            var calc = new PolygonArea(Geodesic.WGS84, true);

            foreach (var point in points)
            {
                calc.AddPoint(point.X, point.Y);
            }
            var length = calc.Compute().Perimeter;

            Console.WriteLine("Length Is : {0}", length);
        }
示例#10
0
        private static void CalculateArea(List <Coordinate> points)
        {
            // setting the polyline to false allows us
            // to calculate length of a polyline
            var calc = new PolygonArea(Geodesic.WGS84, false);

            foreach (var point in points)
            {
                calc.AddPoint(point.X, point.Y);
            }
            var area = calc.Compute();

            Console.WriteLine("Area Is      : {0}", area.Area);
            Console.WriteLine("Perimeter Is : {0}", area.Perimeter);
        }
示例#11
0
    private static void GetValue(PolygonAreaConfig scr, out PolygonArea area, out Vector3 origin, out Vector3 dir,
                                 out Color color, out float vOffset, out float dirLineLength, out float dirLineWidth)
    {
        var type = scr.GetType();

        area          = (PolygonArea)type.GetFieldAll("m_Area").GetValue(scr);
        color         = (Color)type.GetFieldAll("m_AreaColor").GetValue(scr);
        vOffset       = (float)type.GetFieldAll("m_AreaVertialOffsetBase").GetValue(scr);
        dirLineLength = (float)type.GetFieldAll("m_DirLineLength").GetValue(scr);
        dirLineWidth  = (float)type.GetFieldAll("m_DirLineWidth").GetValue(scr);

        var polygonType = area.GetType();

        origin = (Vector3)polygonType.GetFieldAll("m_Origin").GetValue(area);
        dir    = (Vector3)polygonType.GetFieldAll("m_Direction").GetValue(area);
    }
示例#12
0
 private void OnSet(object sender, EventArgs e)
 {
     try
     {
         double a = Double.Parse(m_majorRadiusTextBox.Text);
         double f = Double.Parse(m_flatteningTextBox.Text);
         m_poly = new PolygonArea(new Geodesic(a, f), m_polylineCheckBox.Checked);
         m_lengthTextBox.Text  = m_areaTextBox.Text = m_numPointsTextBox.Text = "0";
         m_currLatTextBox.Text = m_currLonTextBox.Text = "";
         m_edgeButton.Enabled  = false;
     }
     catch (Exception xcpt)
     {
         MessageBox.Show(xcpt.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
示例#13
0
 static void Main(string[] args)
 {
     try {
         Geodesic geod = new Geodesic();  // WGS84
         PolygonArea poly = new PolygonArea(geod, true);
         poly.AddPoint( 52,  0);     // London
         poly.AddPoint( 41,-74);     // New York
         poly.AddPoint(-23,-43);     // Rio de Janeiro
         poly.AddPoint(-26, 28);     // Johannesburg
         double perimeter, area;
         uint n = poly.Compute(false, true, out perimeter, out area);
         Console.WriteLine(String.Format("{0} {1} {2}", n, perimeter, area));
     }
     catch (GeographicErr e) {
         Console.WriteLine(String.Format("Caught exception: {0}", e.Message));
     }
 }
示例#14
0
 static void Main(string[] args)
 {
     try {
         Geodesic    geod = new Geodesic(); // WGS84
         PolygonArea poly = new PolygonArea(geod, true);
         poly.AddPoint(52, 0);              // London
         poly.AddPoint(41, -74);            // New York
         poly.AddPoint(-23, -43);           // Rio de Janeiro
         poly.AddPoint(-26, 28);            // Johannesburg
         double perimeter, area;
         uint   n = poly.Compute(false, true, out perimeter, out area);
         Console.WriteLine(String.Format("{0} {1} {2}", n, perimeter, area));
     }
     catch (GeographicErr e) {
         Console.WriteLine(String.Format("Caught exception: {0}", e.Message));
     }
 }
示例#15
0
 public bool ValidateRestrictedArea(Observation observation)
 {
     if (this.Mission.RestrictedArea != null)
     {
         if (this.Mission.RestrictedArea.GetType() == typeof(CircleArea))
         {
             CircleArea cirleArea = (CircleArea)this.Mission.RestrictedArea;
             double     distance  = GeoHelper.CalculateDistance(new Position(cirleArea.Center.Coordinates.Latitude, cirleArea.Center.Coordinates.Longitude), new Position(observation.Coordinates.Coordinates.Latitude, observation.Coordinates.Coordinates.Longitude));
             return(distance < cirleArea.Radius);
         }
         else
         {
             PolygonArea polygonArea = (PolygonArea)this.Mission.RestrictedArea;
             return(GeoHelper.IsPointInPolygon(polygonArea.Polygon.Coordinates.Exterior.Positions.Select(x => new Position(x.Latitude, x.Longitude)).ToArray(), new Position(observation.Coordinates.Coordinates.Latitude, observation.Coordinates.Coordinates.Longitude)));
         }
     }
     return(true);
 }
示例#16
0
    public static bool IsContainsPoint(this PolygonArea area, Vector3 point)
    {
        if (area.Vertexes.Count <= 0)
        {
            return(false);
        }
        Plane plane = new Plane(-PolygonArea.Normal, area.Vertexes[0]);

        point = plane.GetPointOnPlane(point);
        foreach (var tri in area.Triangles)
        {
            if (tri.IsContainsPoint(point))
            {
                return(true);
            }
        }
        return(false);
    }
示例#17
0
        public static void main(string[] args)
        {
            PolygonArea p = new PolygonArea(Geodesic.WGS84, false);

            try
            {
                var inp = (from arg in args select double.Parse(arg)).GetEnumerator();
                while (inp.MoveNext())
                {
                    double lat = inp.Current;
                    inp.MoveNext();
                    double lon = inp.Current;
                    p.AddPoint(lat, lon);
                }
            }
            catch (Exception e) { }
            PolygonResult r = p.Compute();

            Console.WriteLine(r.Num + " " + r.Perimeter + " " + r.Area);
        }
示例#18
0
 private void OnValidate(object sender, EventArgs e)
 {
     try
     {
         double      lat, lon, perim, area;
         PolygonArea pa = new PolygonArea(new Geodesic(50000.0, 0.001), true);
         pa = new PolygonArea(false);
         pa.AddPoint(32.0, -86.0);
         pa.AddEdge(20.0, 10000.0);
         pa.AddEdge(-45.0, 10000.0);
         pa.CurrentPoint(out lat, out lon);
         pa.Compute(false, false, out perim, out area);
         pa.TestEdge(-70.0, 5000.0, false, false, out perim, out area);
         pa.TestPoint(31.0, -86.5, false, false, out perim, out area);
         MessageBox.Show("No errors detected", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (Exception xcpt)
     {
         MessageBox.Show(xcpt.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
示例#19
0
 public PolygonAreaTests(ITestOutputHelper output)
 {
     _area   = new PolygonArea(_nw, _ne, _se, _sw);
     _output = output;
 }
 public PolygonArea CreateParallelogramTopCornerBaseline()
 {
     return(PolygonArea.Parallelogram(Origin, Size, Size, true, LineAlgorithm));
 }
 public PolygonArea CreateRectangleBaseline()
 {
     return(PolygonArea.Rectangle(new Rectangle(Origin.X, Origin.Y, Size, Size), LineAlgorithm));
 }
 public PolygonArea CreateParallelogramBottomCornerBaseline()
 {
     return(PolygonArea.Parallelogram(Origin, Size, Size, false, LineAlgorithm));
 }
示例#23
0
 public static Vector3 GetCentroid(this PolygonArea polygon)
 {
     return(GetCentroid(polygon.Vertexes));
 }
示例#24
0
        public RegionTests()
        {
            var polygon = new PolygonArea(_nw, _ne, _se, _sw);

            _area = new Region(polygon);
        }
 public PolygonArea CreateRegularPolygonBaseline()
 {
     return(PolygonArea.RegularPolygon(Center, NumberOfSidesOrCorners, ParameterizedRadius, LineAlgorithm));
 }
 public PolygonArea CreateRegularStarInnerOneHalfBaseline()
 {
     return(PolygonArea.RegularStar(Center, NumberOfSidesOrCorners,
                                    ParameterizedRadius, (int)(ParameterizedRadius / 2.0), LineAlgorithm));
 }
 public PolygonArea CreateRegularStarInnerThreeFourthsBaseline()
 {
     return(PolygonArea.RegularStar(Center, NumberOfSidesOrCorners,
                                    ParameterizedRadius, (int)(ParameterizedRadius * 0.75), LineAlgorithm));
 }
示例#28
0
 private void OnSet(object sender, EventArgs e)
 {
     try
     {
         double a = Double.Parse(m_majorRadiusTextBox.Text);
         double f = Double.Parse(m_flatteningTextBox.Text);
         m_poly = new PolygonArea(new Geodesic(a, f), m_polylineCheckBox.Checked);
         m_lengthTextBox.Text = m_areaTextBox.Text = m_numPointsTextBox.Text = "0";
         m_currLatTextBox.Text = m_currLonTextBox.Text = "";
         m_edgeButton.Enabled = false;
     }
     catch (Exception xcpt)
     {
         MessageBox.Show(xcpt.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
示例#29
0
 private void OnValidate(object sender, EventArgs e)
 {
     try
     {
         double lat, lon, perim, area;
         PolygonArea pa = new PolygonArea(new Geodesic(50000.0, 0.001), true);
         pa = new PolygonArea(false);
         pa.AddPoint(32.0, -86.0);
         pa.AddEdge(20.0, 10000.0);
         pa.AddEdge(-45.0, 10000.0);
         pa.CurrentPoint(out lat, out lon);
         pa.Compute(false, false, out perim, out area);
         pa.TestEdge(-70.0, 5000.0, false, false, out perim, out area);
         pa.TestPoint(31.0, -86.5, false, false, out perim, out area);
         MessageBox.Show("No errors detected", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (Exception xcpt)
     {
         MessageBox.Show(xcpt.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
示例#30
0
    private void DrawRandomTest(SerializedProperty vertexesProp, SerializedProperty trianglesProp,
                                SerializedProperty triangleAreasProp, SerializedProperty areaProp, SerializedProperty pointSizeProp)
    {
        if (areaProp.floatValue <= 0 || Mathf.Approximately(areaProp.floatValue, 0))
        {
            return;
        }

        EditorGUILayout.BeginHorizontal();

        bool isTest  = GUILayout.Button("测试");
        bool isClear = GUILayout.Button("清除");


        GUILayout.FlexibleSpace();
        GUILayout.Label("随机点大小");

        pointSizeProp.floatValue = EditorGUILayout.FloatField(pointSizeProp.floatValue, GUILayout.Width(100));
        pointSizeProp.floatValue = Mathf.Clamp(pointSizeProp.floatValue, 0.01f, 1.0f);

        bool isRefresh = GUILayout.Button("刷新");

        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();


        if (isTest)
        {
            if (vertexesProp.arraySize > 3)
            {
                PolygonArea area = new PolygonArea()
                {
                    Vertexes      = new List <Vector3>(),
                    Triangles     = new List <ThreeVector3>(),
                    TriangleAreas = new List <float>(),
                    Area          = areaProp.floatValue,
                };
                for (int i = 0; i < vertexesProp.arraySize; ++i)
                {
                    area.Vertexes.Add(vertexesProp.GetArrayElementAtIndex(i).vector3Value);
                }

                for (int i = 0; i < trianglesProp.arraySize; ++i)
                {
                    var triProp = trianglesProp.GetArrayElementAtIndex(i);
                    var x       = triProp.FindPropertyRelative("x").vector3Value;
                    var y       = triProp.FindPropertyRelative("y").vector3Value;
                    var z       = triProp.FindPropertyRelative("z").vector3Value;
                    area.Triangles.Add(new ThreeVector3(x, y, z));

                    area.TriangleAreas.Add(triangleAreasProp.GetArrayElementAtIndex(i).floatValue);
                }

                testPoints.Clear();
                for (int i = 0; i < TestPointCount; ++i)
                {
                    Vector3 p = area.RandomPoint();
                    testPoints.Add(p);
                }
                testPointsSize = pointSizeProp.floatValue;
                SceneView.RepaintAll();
            }
        }

        if (isClear)
        {
            testPoints.Clear();
            SceneView.RepaintAll();
        }


        if (isRefresh)
        {
            testPointsSize = pointSizeProp.floatValue;
            SceneView.RepaintAll();
        }
    }