Link to home
Start Free TrialLog in
Avatar of ChrisEvans1234
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
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ChrisEvans1234
ChrisEvans1234

ASKER

I don't think using the subtraction operation would have saved time - instead I used the Intersection routine then count the number of edges in the resulting pathiterator:

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.
8-) You could be right -- the Area area is new to me ;-)