isPointInRectangle static method
判断点是否在矩形内部
Implementation
static bool isPointInRectangle(double px, double py, Rect rect) {
double x1 = rect.left;
double y1 = rect.top;
double x2 = x1 + rect.width;
double y2 = y1 + rect.height;
// 先确保矩形的坐标是正确的,x1, y1 为左上角,x2, y2 为右下角
double minX = x1 < x2 ? x1 : x2;
double maxX = x1 > x2 ? x1 : x2;
double minY = y1 < y2 ? y1 : y2;
double maxY = y1 > y2 ? y1 : y2;
// 判断点是否在矩形内
return px >= minX && px <= maxX && py >= minY && py <= maxY;
}