Solved

Java2D Area intersections.

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
network + 7 73
Spring Controller - inheritance in request parameter 3 38
word0 challenge 4 53
Java Timer (static) 9 16
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

760 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