?
Solved

Java2D Area intersections.

Posted on 2004-04-17
4
Medium Priority
?
471 Views
Last Modified: 2008-01-16
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
0
Comment
Question by:ChrisEvans1234
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 750 total points
ID: 10849021
>>The only solution I've come up with so far is adding...

Sounds like quite a good one to me ;-)
0
 
LVL 1

Assisted Solution

by:RodionP
RodionP earned 750 total points
ID: 10849593
Well, you could try subtracting one from another and see if you have nothing, then areas don't intersect, but this is pretty much the same techniue as you used except using different functionality. I believe all the set operations provided by API are exactly for kind of problems that you have. Please elaborate the question, I might not understand you correctly.
0
 

Author Comment

by:ChrisEvans1234
ID: 10849745
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.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10849762
8-) You could be right -- the Area area is new to me ;-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month14 days, 23 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question