Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java AWT Intersect Function regarding encapsulated shapes.

 
Chris Stabler
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2989
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Swing / AWT forum.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic