wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Java AWT Intersect Function regarding encapsulated shapes. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Java AWT Intersect Function regarding encapsulated shapes." Watch "Java AWT Intersect Function regarding encapsulated shapes." New topic
Author

Java AWT Intersect Function regarding encapsulated shapes.

Chris Stabler
Greenhorn

Joined: Oct 22, 2009
Posts: 13
I have been running some tests with the java.awt.geom API and i have a question about the Shape Class and i need to work with specifically the Area implementation.

I create 2 shapes, both Path2D types, then convert both to an Area. One shape in completely inside the other. When i do an intersect between the two i get some peculiar results.


If i say shape1.intersect(shape2), where shape2 is inside of shape1 completely, i get only the points for shape2. If i say shape2.intersect(shape1), then i get the original set of points for shape1...but regardless of which i do, the intersection test passes. I have read the API docs and i know that it says intersect checks for any polygon/rectangle that is inside of the area.

My issue is is that there is not a contains functions that works against areas..only against bounding boxes or 4 points. the getBounds2D() function talks of better precision but what if i had to check for contains with a triangle and one point of the triangle directly lies at the same x,y coordinate of the surrounding area? does the creation of the bounding box work with contains returning true?

thanks all for your help!
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2854
    
  11

Moving to Swing / AWT forum.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Java AWT Intersect Function regarding encapsulated shapes.