I'm writing a shape drawing function and want to check if the user clicks inside of a triangle shape like a hit test.
This is what I have so far:
public void draw(Graphics g)
{
int x[] = { (x1 + x2) / 2, x1, x2};
int y[] = { y1, y2, y2};
int numberOfPoints = 3;
g.setColor(color);
g.fillPolygon(x, y, numberOfPoints);
}
public boolean hitTest(int x, int y)
{
return x > ((x1 + x2) / 2) && x < x2 && y > y1 && y < y2;
}
This partially works for the triangle, but the right side of it still isn't hit-testing correctly. Any idea as to why this hitTest function wouldn't work?