AForge.Math.Geometry.PointsCloud.GetBoundingRectangle C# (CSharp) Method

GetBoundingRectangle() public static method

Get bounding rectangle of the specified list of points.
public static GetBoundingRectangle ( IEnumerable cloud, IntPoint &minXY, IntPoint &maxXY ) : void
cloud IEnumerable Collection of points to get bounding rectangle for.
minXY IntPoint Point comprised of smallest X and Y coordinates.
maxXY IntPoint Point comprised of biggest X and Y coordinates.
return void
        public static void GetBoundingRectangle( IEnumerable<IntPoint> cloud, out IntPoint minXY, out IntPoint maxXY )
        {
            int minX = int.MaxValue;
            int maxX = int.MinValue;
            int minY = int.MaxValue;
            int maxY = int.MinValue;

            foreach ( IntPoint pt in cloud )
            {
                int x = pt.X;
                int y = pt.Y;

                // check X coordinate
                if ( x < minX )
                    minX = x;
                if ( x > maxX )
                    maxX = x;

                // check Y coordinate
                if ( y < minY )
                    minY = y;
                if ( y > maxY )
                    maxY = y;
            }

            if ( minX > maxX ) // if no point appeared to set either minX or maxX
                throw new ArgumentException( "List of points can not be empty." );

            minXY = new IntPoint( minX, minY );
            maxXY = new IntPoint( maxX, maxY );
        }

Usage Example

Example #1
0
        public bool IsCircle(List <IntPoint> edgePoints, out Point center, out float radius)
        {
            if (edgePoints.Count < 8)
            {
                center = new Point(0f, 0f);
                radius = 0f;
                return(false);
            }
            PointsCloud.GetBoundingRectangle(edgePoints, out IntPoint minXY, out IntPoint maxXY);
            IntPoint point = maxXY - minXY;

            center = minXY + (Point)point / 2f;
            radius = ((float)point.X + (float)point.Y) / 4f;
            float num = 0f;
            int   i   = 0;

            for (int count = edgePoints.Count; i < count; i++)
            {
                num += System.Math.Abs(center.DistanceTo(edgePoints[i]) - radius);
            }
            num /= (float)edgePoints.Count;
            float num2 = System.Math.Max(minAcceptableDistortion, ((float)point.X + (float)point.Y) / 2f * relativeDistortionLimit);

            return(num <= num2);
        }
All Usage Examples Of AForge.Math.Geometry.PointsCloud::GetBoundingRectangle