Solved

Java2D Area intersections.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
unix in java example 9 52
rhino JavaScript import, load 25 66
netstat -ano | find "8000" and taskkill /f /pid 2984 3 30
diffSum example 4 21
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

914 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now