Esempio n. 1
0
func BenchmarkGeosPaulSmit(b *testing.B) {
	// Setup
	polygon, err := geos.NewPolygon([]geos.Coord{
		{0, 1, 0},
		{1, 2, 0},
		{2, 1, 0},
		{2, 0, 0},
		{1, -1, 0},
		{0, 0, 0},
		{0, 1, 0},
	})
	if err != nil {
		b.Fatal(err)
	}
	point, err := geos.NewPoint(geos.Coord{X: 1, Y: 0, Z: 0})
	if err != nil {
		b.Fatal(err)
	}

	b.ResetTimer()

	// Test
	for i := 0; i < b.N; i++ {
		contains, err := polygon.Contains(point)
		if err != nil {
			b.Fatal(err)
		}
		if !contains {
			b.Fatal("not contains")
		}
	}
}
Esempio n. 2
0
func getGeometry(ent *Entity) *geos.Geometry {
	var shell []geos.Coord
	for v, _ := range ent.Shape.Vectors {
		x, y := ent.Shape.Vectors[v].Rotate(ent.Angle)
		shell = append(shell, geos.Coord{x + ent.PosX, y + ent.PosY, 1})
	}
	x, y := ent.Shape.Vectors[0].Rotate(ent.Angle)
	shell = append(shell, geos.Coord{x + ent.PosX, y + ent.PosY, 1})
	geometry, err := geos.NewPolygon(shell)
	if err != nil {
		panic(err)
	}

	return geometry
}
Esempio n. 3
0
//newTilePolygon creates the geos polygon for a given tile.
func newTilePolygon(level, x, y int) (*geos.Geometry, error) {

	latDeg := raster.Y2Lat(level, y)
	lonDeg := raster.X2Lon(level, x)
	lat2Deg := raster.Y2Lat(level, y+1)
	lon2Deg := raster.X2Lon(level, x+1)

	return geos.NewPolygon(
		[]geos.Coord{
			geos.NewCoord(lonDeg, latDeg),
			geos.NewCoord(lon2Deg, latDeg),
			geos.NewCoord(lon2Deg, lat2Deg),
			geos.NewCoord(lonDeg, lat2Deg),
			geos.NewCoord(lonDeg, latDeg),
		})
}