コード例 #1
0
        /// <summary>
        /// 큰 diagridUnit에 pixel이 들어갈 수록 높은 점수를 받는다.
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="intension"></param>
        public double EstimateInclusionScore(RectangleFrameDiagrid grid, IntensionLayer intension, GeometryParser parser)
        {
            var handler = new GeoHandler();
            List <List <(int, int)> > all = parser.ToPolygonPointList(grid);
            double       width            = all.SelectMany(n => n).Max(n => n.Item1);
            double       height           = all.SelectMany(n => n).Max(n => n.Item2);
            List <Pixel> pixels           = intension.GetPixels(width, height);

            var diagridUnits = grid.DiagridUnits;

            var inspections = diagridUnits
                              .Select(n => new { pointList = parser.ToPolygonPointList(n), mag = n.Magnification })
                              .Select(n => new { pts = n.pointList.Select(k => new Point(k.Item1, k.Item2)), mag = n.mag })
                              .Select(n => new { polygon = new Polygon(n.pts), mag = n.mag })
                              .ToList();


            double total = 0;

            foreach (var inspect in inspections)
            {
                var inclusions = pixels
                                 .Where(n => handler.PointInPolygon(new Point(n.PixelCenterX, n.PixelCenterY), inspect.polygon) == PointPositionWithPolygon.Inside)
                                 .ToList();

                double score = inclusions
                               .Select(n => (int)n.Val)
                               .Sum();

                double weightedScore = score * inspect.mag;
                total += weightedScore;
            }

            return(total);
        }
コード例 #2
0
        public void LineBasedPointPosition_Test2()
        {
            var handler = new GeoHandler();
            var ln      = new Line(0, 0, 10, 0);
            var pt1     = new Point(5, 5);
            var pt2     = new Point(20, 0);

            Assert.IsTrue(handler.LineBasedPointPosition(pt1, ln) == PointPositionWithLine.OutOfBoundary);
            Assert.IsTrue(handler.LineBasedPointPosition(pt2, ln) == PointPositionWithLine.OnTheLineOrHorizonal);
        }
コード例 #3
0
        public void IsPointOnLine_Test2()
        {
            var handler = new GeoHandler();
            var ln      = new Line(0, 0, 2, 1);
            var pt1     = new Point(1, 0.5);
            var pt2     = new Point(1, 0.5 + 0.000000000001);

            Assert.IsTrue(handler.IsPointOnLine(pt1, ln));
            Assert.IsTrue(handler.IsPointOnLine(pt2, ln));
        }
コード例 #4
0
        public void LineBasedPointPosition_Test1()
        {
            var handler = new GeoHandler();
            var ln      = new Line(0, 0, 10, 10);
            var pt1     = new Point(10, 10);
            var pt2     = new Point(0, 0);
            var pt3     = new Point(20, 20);
            var pt4     = new Point(100, 5);
            var pt5     = new Point(-20, 5);

            Assert.IsTrue(handler.LineBasedPointPosition(pt1, ln) == PointPositionWithLine.OnTheLineOrHorizonal);
            Assert.IsTrue(handler.LineBasedPointPosition(pt2, ln) == PointPositionWithLine.OnTheLineOrHorizonal);
            Assert.IsTrue(handler.LineBasedPointPosition(pt3, ln) == PointPositionWithLine.OutOfBoundary);
            Assert.IsTrue(handler.LineBasedPointPosition(pt4, ln) == PointPositionWithLine.Right);
            Assert.IsTrue(handler.LineBasedPointPosition(pt5, ln) == PointPositionWithLine.Left);
        }
コード例 #5
0
        public void IsPointOnLine_Test1()
        {
            var handler = new GeoHandler();
            var ln      = new Line(0, 0, 10, 0);
            var pt1     = new Point(-10, 0);
            var pt2     = new Point(0, 0);
            var pt3     = new Point(5, 0);
            var pt4     = new Point(10, 0);
            var pt5     = new Point(15, 0);

            Assert.IsFalse(handler.IsPointOnLine(pt1, ln));
            Assert.IsTrue(handler.IsPointOnLine(pt2, ln));
            Assert.IsTrue(handler.IsPointOnLine(pt3, ln));
            Assert.IsTrue(handler.IsPointOnLine(pt4, ln));
            Assert.IsFalse(handler.IsPointOnLine(pt5, ln));
        }
コード例 #6
0
        public void PointInPolygon_Test1()
        {
            var handler = new GeoHandler();

            var pts = new List <Point>()
            {
                new Point(0, 0),
                new Point(2, 3),
                new Point(-2, 7),
            };
            var poly = new Polygon(pts);
            var pt1  = new Point(1, 1);
            var pt2  = new Point(0, 1);
            var pt3  = new Point(1.50921, 2.2638);

            Assert.IsTrue(handler.PointInPolygon(pt1, poly) == PointPositionWithPolygon.Outside);
            Assert.IsTrue(handler.PointInPolygon(pt2, poly) == PointPositionWithPolygon.Inside);
            Assert.IsTrue(handler.PointInPolygon(pt3, poly) == PointPositionWithPolygon.OnBoundary);
        }