是否有可能在Point值中溢出?

时间:2015-08-10 04:44:51

标签: c# wpf

我正在尝试将多边形的点放在画布上。我使用两个嵌套的foreach循环来执行此操作。有一段时间,印刷的分数值似乎是正确的。然而,他们随机改变并开始打印非常庞大的数字。

我想知道是否可能存在点数溢出系统(如整数)?

输出:

看似正确的价值观:

(1st polygon) polygon with 3 points consists of: 456.052846081402,440.563719108395 , 288.468556739137,626.462219126099 , 123.170153242781,438.528230330192
(2nd polygon) polygon with 3 points consists of: 299.570190710352,822.113209251473 , 457.567502547491,630.483784090951 , 633.517910276476,805.773376352209

随机/不正确的值:

(1st polygon) polygon with 3 points consists of: 21789.3868304564,21788.5641463545 , 21621.8025411141,21974.4626463722 , 21456.5041376178,21786.5286575763
(2nd polygon) polygon with 3 points consists of: 21634.0541308582,22172.1999782293 , 21788.900457968,21978.0155243827 , 21967.6904229818,22150.4079126876

代码:

public void DefiningPolygonArea()
    {
        foreach (var polygon1 in this.PlayingCanvas.Children.OfType<Polygon>())
        {
            foreach (var polygon2 in this.PlayingCanvas.Children.OfType<Polygon>().Where(x => x != polygon1))
            {
                bool overlaps = HelperMethods.PointCollectionsOverlap_Fast(getPoints(polygon1), getPoints(polygon2));
            }
        }
    }
private List<Point> getPoints(Polygon poly)
    {
        if (poly.Points.Count == 4)
        {
            var transform = poly.TransformToVisual(this.PlayingCanvas);

            Point point1 = transform.Transform(poly.Points[0]);
            Point point2 = transform.Transform(poly.Points[1]);
            Point point3 = transform.Transform(poly.Points[2]);
            Point point4 = transform.Transform(poly.Points[3]);

            area1.Clear();
            area1.Add(point1);
            area1.Add(point2);
            area1.Add(point3);
            area1.Add(point4);
            //Console.WriteLine("polygon with 4 points consists of: " + point1 + " , " + point2 + " , " + point3 + " , " + point4);

        }
        else if (poly.Points.Count == 3)
        {
            var transform = poly.TransformToVisual(this.PlayingCanvas);

            Point point1 = transform.Transform(poly.Points[0]);
            Point point2 = transform.Transform(poly.Points[1]);
            Point point3 = transform.Transform(poly.Points[2]);

            area1.Clear();
            area1.Add(point1);
            area1.Add(point2);
            area1.Add(point3);

            //Console.WriteLine("polygon with 3 points consists of: " + point1 + " , " + point2 + " , " + point3);
        }
        return area1;
    }

0 个答案:

没有答案