The judgment point is in the rectangle !! (MFC)

Source: Internet
Author: User
/**//*
Crect: ptinrect

Determines whether the specified point lies within crect.
*/

Bool ptinrect (
Point point
) Const throw ();

/**//*
Parameters
Point
Contains a point structure or cpoint object.

Return Value

Nonzero if the point lies within crect; otherwise 0.

Remarks

A point is within crect if it lies on the left or top side or is within all four sides. A point on the right or bottom side is outside crect.

Note
The rectangle must be normalized or this function may fail. You can call normalizerect to normalize the rectangle before calling this function.
 

Example
*/

Crect rect (5, 5,100,100 );
Cpoint pt1 (35, 50 );
Cpoint pt2 (125,298 );

// This is true, because pt1 is inside the rectangle
Assert (rect. ptinrect (pt1 ));

// This is not true, because pt2 is outside the rectangle
Assert (! Rect. ptinrect (pt2 ));

// Note that the right and the bottom aren't inside
Assert (! Rect. ptinrect (cpoint (35,100 )));
Assert (! Rect. ptinrect (cpoint (100, 98 )));

// But the top and
Assert (rect. ptinrect (cpoint (5, 65 )));
Assert (rect. ptinrect (cpoint (88, 5 )));

// And that ptinrect () works against a point, too
Point pt;
PT. x = 35;
PT. Y = 50;
Assert (rect. ptinrect (PT ));
/*
See also

Reference
Crect class
Hierarchy chart
Crect: normalizerect
Ptinrect

Other resources
Crect members
*/

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.