i want my line 2d to stop being drawn when it hits the edge of the rectangle 2d (code below)

my declairations:

Point pointStart = new Point(posX, posY);
Point pointEnd = new...