pip

package module
Version: v0.0.0-...-99c4cbb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2018 License: MIT Imports: 2 Imported by: 4

README

🎯 Point in Polygon - Go

Detect if a point (X, Y) is within a given polygon (Set of X, Ys) .

Usage

import pip

// Polygons are self closing (i.e. you don't need to add first point at end)
rectangle := pip.Polygon{
  Points : []pip.Point {
    pip.Point{X : 1.0, Y : 1.0},
    pip.Point{X : 1.0, Y : 2.0},
    pip.Point{X : 2.0, Y : 2.0},
    pip.Point{X : 2.0, Y : 1.0},
  },
}

pt1 := pip.Point{X : 1.1,  Y : 1.1}

pip.PointInPolygon(pt1, rectangle) // Test - Should return true

Caveats

  • Currently no support for holes although this should be easy to account for if the hole is tested as a separate polygon.
  • Currently no support for points that reside on edges (returns outside, i.e. false).
  • Beware of roundoff errors
  • The direction that you list the vertices (clockwise or counterclockwise) does not matter.

Credit

Based on the example code given in this article by W. Randolph Franklin. The method is named PNPOLY.

License

MIT License Original C code : Copyright (c) 1970-2003, Wm. Randolph Franklin Modified Go code: Copyright 2016 James Milner

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBoundingBoxFromGeoJson

func GetBoundingBoxFromGeoJson(poly [][]float64) []float64

func MaxParallelism

func MaxParallelism() int

func PointInBoundingBox

func PointInBoundingBox(pt Point, bb BoundingBox) bool

func PointInGeoJsonBoundingBox

func PointInGeoJsonBoundingBox(x float64, y float64, bb []float64) bool

func PointInGeoJsonPolygon

func PointInGeoJsonPolygon(pt []float64, poly [][][]float64) bool

func PointInPolygon

func PointInPolygon(pt Point, poly Polygon) bool

func PointInSlice

func PointInSlice(x float64, y float64, poly [][]float64) bool

Types

type BoundingBox

type BoundingBox struct {
	BottomLeft Point
	TopRight   Point
}

func GetBoundingBox

func GetBoundingBox(poly Polygon) BoundingBox

type Point

type Point struct {
	// A point
	X float64
	Y float64
}

func PointInPolygonParallel

func PointInPolygonParallel(pts []Point, poly Polygon, numcores int) []Point

type Polygon

type Polygon struct {
	// A polygon
	Points []Point
}

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL