示例#1
0
        private void calculateRatio()
        {
            minPoint = new Point()
            {
                X = 0, Y = 0
            };
            maxPoint = new Point()
            {
                X = ip.CaptureWidth, Y = ip.CaptureHeight
            };
            System.Drawing.Point[] minPoints = new System.Drawing.Point[] { new System.Drawing.Point(), new System.Drawing.Point(), new System.Drawing.Point(), };
            System.Drawing.Point[] maxPoints = new System.Drawing.Point[] { new System.Drawing.Point(), new System.Drawing.Point(), new System.Drawing.Point(), };
            if (currentGems.Count() != 0)
            {
                minPoints[0].X = currentGems.Min(g => g.Position.X);
                minPoints[0].Y = currentGems.Min(g => g.Position.Y);

                maxPoints[0].X = currentGems.Max(g => g.Position.X);
                maxPoints[0].Y = currentGems.Max(g => g.Position.Y);
            }

            if (currentWalls.Count() != 0)
            {
                minPoints[1].X = currentWalls.Min(g => g.StartPosition.X);
                minPoints[1].Y = currentWalls.Min(g => g.StartPosition.Y);
                minPoints[2].X = currentWalls.Min(g => g.EndPosition.X);
                minPoints[2].Y = currentWalls.Min(g => g.EndPosition.Y);

                maxPoints[1].X = currentWalls.Max(g => g.StartPosition.X);
                maxPoints[1].Y = currentWalls.Max(g => g.StartPosition.Y);
                maxPoints[2].X = currentWalls.Max(g => g.EndPosition.X);
                maxPoints[2].Y = currentWalls.Max(g => g.EndPosition.Y);
            }
            minPoint.X = minPoints.Min(p => p.X);
            minPoint.Y = minPoints.Min(p => p.Y);
            maxPoint.X = maxPoints.Max(p => p.X);
            maxPoint.Y = maxPoints.Max(p => p.Y);
            width      = maxPoint.X - minPoint.X;
            height     = maxPoint.Y - minPoint.Y;

            float horizontalRatio = width / 14.4f;
            float verticalRatio   = height / 10.0f;

            ratio = horizontalRatio > verticalRatio ? horizontalRatio : verticalRatio;
        }