This language bar is your friend. Select your favorite languages!
Select your favorite languages :
- Or search :
Idiom #178 Check if point is inside rectangle
Set boolean b to true if if the point with coordinates (x,y) is inside the rectangle with coordinates (x1,y1,x2,y2) , or to false otherwise.
Describe if the edges are considered to be inside the rectangle.
b = new Rect(new Point(x1, y1), new Point(x2, y2)).Contains(x, y);
There's an older System.Drawing.Rectangle class which has a similar API for this purpose if System.Windows is not available.
var r = Rectangle.fromPoints(Point(x1,y1),Point(x2,y2));
var b = r.containsPoint(Point(x,y));
Edges are considered to be inside the rectangle.
double w = x2 - x1, h = y2 - y1;
Rectangle2D r = new Rectangle2D.Double(x1, y1, w, h);
boolean b = r.contains(x, y);
int w = x2 - x1, h = y2 - y1;
Rectangle r = new Rectangle(x1, y1, w, h);
boolean b = r.contains(x, y);