?
Solved

Java2D Area intersections.

Posted on 2004-04-17
4
Medium Priority
?
470 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

649 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