Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

PATH2D.contain() not working?  RSS feed

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any reason why this "poly.contains(lat1, lon1)" is always returning false?
lat1,lon1 is definitely inside the polygon.
 
Greg Posey
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Console Output:

 
Marshal
Posts: 58419
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried displaying it on a panel? Please look what the closePath() method does. Also what the difference between lineTo() and moveTo() is. I think the point you are complaining about isn't actually inside the Path2D.
 
Sheriff
Posts: 23451
46
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:I think the point you are complaining about isn't actually inside the Path2D.



To me those four pairs of coordinates look like they form a rectangle, and the pair of coordinates being tested look like they're just about in the centre of that rectangle. So I'd agree with your comment about lineTo().
 
Campbell Ritchie
Marshal
Posts: 58419
178
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:. . . those four pairs of coordinates look like they form a rectangle . . .

They represent the corners of a rectangle, but the sides would have to be filled in too.
 
Rancher
Posts: 2458
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With 'path.moveTo(..)' you are not creating some boundary of a shape, that will make that some points are inside and some outside. You need some concrete lines or curves for that. For instance:
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!