-
Notifications
You must be signed in to change notification settings - Fork 0
/
poly.go
75 lines (62 loc) · 1.54 KB
/
poly.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package tgo
/*
#cgo LDFLAGS: -lm
#include "tg.h"
#include <stdlib.h>
*/
import "C"
import "unsafe"
type Poly struct {
cp *C.struct_tg_poly
}
type MultiPoly struct {
cg *C.struct_tg_geom
}
// AsGeom returns a Geom of the polygon without cloning.
func (p *Poly) AsGeom() *Geom {
cg := (*C.struct_tg_geom)(unsafe.Pointer(p.cp))
return &Geom{
cg: cg,
}
}
// IsClockWise returns true if the polygon is clock wise.
func (p *Poly) IsClockWise() bool {
return bool(C.tg_poly_clockwise(p.cp))
}
// AsText returns the representation of the poly as WKT.
func (p *Poly) AsText() string {
return p.AsGeom().AsText()
}
// HolesCount returns the holes count.
func (p *Poly) HolesCount() int {
return int(C.tg_poly_num_holes(p.cp))
}
// Exterior returns the exterior Ring of the poly.
func (p *Poly) Exterior() *Ring {
cr := C.tg_poly_exterior(p.cp)
return &Ring{
cr: cr,
}
}
// AsGeom returns a Geom of the multipolygon without cloning.
func (mp *MultiPoly) AsGeom() *Geom {
return &Geom{
cg: mp.cg,
}
}
// AsText returns the representation of the multipoly as WKT.
func (mp *MultiPoly) AsText() string {
return mp.AsGeom().AsText()
}
// PolygonsCount returns the count of polygons in the multipoly.
func (mp *MultiPoly) PolygonsCount() int {
return int(C.tg_geom_num_polys(mp.cg))
}
// PolygonAt returns the Poly at index, true if it's applicable.
func (mp *MultiPoly) PolygonAt(index int) (*Poly, bool) {
if index < 0 || index+1 > mp.PolygonsCount() {
return nil, false
}
cp := C.tg_geom_poly_at(mp.cg, C.int(index))
return &Poly{cp: cp}, true
}