-
Notifications
You must be signed in to change notification settings - Fork 156
/
prepared.go
48 lines (42 loc) · 978 Bytes
/
prepared.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package geos
/*
#cgo LDFLAGS: -lgeos_c
#include "geos_c.h"
#include <stdlib.h>
*/
import "C"
import "github.com/omniscale/imposm3/log"
type PreparedGeom struct {
v *C.GEOSPreparedGeometry
}
func (g *Geos) Prepare(geom *Geom) *PreparedGeom {
prep := C.GEOSPrepare_r(g.v, geom.v)
if prep == nil {
return nil
}
return &PreparedGeom{prep}
}
func (g *Geos) PreparedContains(a *PreparedGeom, b *Geom) bool {
result := C.GEOSPreparedContains_r(g.v, a.v, b.v)
if result == 1 {
return true
}
// result == 2 -> exception (already logged to console)
return false
}
func (g *Geos) PreparedIntersects(a *PreparedGeom, b *Geom) bool {
result := C.GEOSPreparedIntersects_r(g.v, a.v, b.v)
if result == 1 {
return true
}
// result == 2 -> exception (already logged to console)
return false
}
func (g *Geos) PreparedDestroy(geom *PreparedGeom) {
if geom.v != nil {
C.GEOSPreparedGeom_destroy_r(g.v, geom.v)
geom.v = nil
} else {
log.Printf("double free?")
}
}