Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Some boundary points return false] contains - Polygon #66

Open
hossainruetcse opened this issue Apr 30, 2019 · 3 comments
Open

[Some boundary points return false] contains - Polygon #66

hossainruetcse opened this issue Apr 30, 2019 · 3 comments

Comments

@hossainruetcse
Copy link

Some points on boundary line or on polygon vertices return false in contains- Polygon.
For example ,
polygon- (0,0), (5, 0), (5, 5 ) , (0, 5) returns false for point (0,0)

@Wulfheart
Copy link

Wulfheart commented Jul 11, 2019

I'm doubting this is repository is actively monitored by maintainers.

However the following code results in this output:

package main

import (
	"fmt"

	geo "github.com/kellydunn/golang-geo"
)

func main() {
	poly := []*geo.Point{
		geo.NewPoint(0, 0), geo.NewPoint(0, 1), geo.NewPoint(1, 1), geo.NewPoint(1, 0),
	}
	gon := geo.NewPolygon(poly)
	fmt.Println("x:0\ty:0\t", "Expecting: true\t", "Got:", gon.Contains(geo.NewPoint(0, 0)))
	fmt.Println("x:0.5\ty:0\t", "Expecting: true\t", "Got:", gon.Contains(geo.NewPoint(0.5, 0)))
	fmt.Println("x:0.5\ty:0.7\t", "Expecting: true\t", "Got:", gon.Contains(geo.NewPoint(0.5, 0.7)))
	fmt.Println("x:2\ty:8\t", "Expecting: false\t", "Got:", gon.Contains(geo.NewPoint(2, 8)))

}

Output:

x:0     y:0      Expecting: true         Got: false
x:0.5   y:0      Expecting: true         Got: true
x:0.5   y:0.7    Expecting: true         Got: true
x:2     y:8      Expecting: false        Got: false

Does anyone have an idea how this could be fixed? Which algorithm is used? Raycasting or Gauß-Jordan or ...?

I made little repo to just run and go.

@kellydunn
Copy link
Owner

👋 howdy!

I'm doubting this is repository is actively monitored by maintainers.

yes life keeps me busy and I haven't had time to maintain this as much as I would like, but! I welcome any PRs if you'd like to contribute upstream!

It's been a while since I've looked at the Polygon code, but I believe it's historically used Raycasting: https://github.com/kellydunn/golang-geo/blob/master/polygon.go#L65

@Wulfheart
Copy link

I didn't change anything on the raycasting algorithm but #71 should be a viable workaround.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants