Solved

Java2D Area intersections.

Posted on 2004-04-17
4
466 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 250 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 250 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

856 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