ChrisEvans1234
asked on
Java2D Area intersections.
Hi Guys,
I was wondering if any of you could help. I need to test whether two Area objects actually overlap as in their path's - not the bounding boxes. The only solution I've come up with so far is adding the area's then testing if the resulting pathiterator is different to the first. This seems a little "around the houses" though. I've given this question 500 points as I require a quick response.
Regards,
Chris
I was wondering if any of you could help. I need to test whether two Area objects actually overlap as in their path's - not the bounding boxes. The only solution I've come up with so far is adding the area's then testing if the resulting pathiterator is different to the first. This seems a little "around the houses" though. I've given this question 500 points as I require a quick response.
Regards,
Chris
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
8-) You could be right -- the Area area is new to me ;-)
ASKER
public boolean doesAreaIntersect(Area lhs, Area rhs) {
lhs.intersect(rhs);
PathIterator pi = lhs.getPathIterator(null);
if (pi == null) {
return false;
} else {
int count =0;
while (!pi.isDone()) {
count++;
pi.next();
}
if (count < 1) {
return false;
} else {
return true;
}
}
}
As far as I can see, this is the quickest and most in-expensive way to do this.