-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbufferparams.go
87 lines (77 loc) · 2.22 KB
/
bufferparams.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
76
77
78
79
80
81
82
83
84
85
86
87
package geos
// #include "go-geos.h"
import "C"
// A BufferParams contains parameters for BufferWithParams.
type BufferParams struct {
context *Context
bufferParams *C.struct_GEOSBufParams_t
}
// Destroy destroys all resources associated with p.
func (p *BufferParams) Destroy() {
// Protect against Destroy being called more than once.
if p == nil || p.context == nil {
return
}
p.context.Lock()
defer p.context.Unlock()
C.GEOSBufferParams_destroy_r(p.context.handle, p.bufferParams)
*p = BufferParams{} // Clear all references.
}
// SetEndCapStyle sets p's end cap style.
func (p *BufferParams) SetEndCapStyle(style BufCapStyle) *BufferParams {
p.context.Lock()
defer p.context.Unlock()
if C.GEOSBufferParams_setEndCapStyle_r(p.context.handle, p.bufferParams, C.int(style)) != 1 {
panic(p.context.err)
}
return p
}
// SetJoinStyle sets p's join style.
func (p *BufferParams) SetJoinStyle(style BufJoinStyle) *BufferParams {
p.context.Lock()
defer p.context.Unlock()
if C.GEOSBufferParams_setJoinStyle_r(p.context.handle, p.bufferParams, C.int(style)) != 1 {
panic(p.context.err)
}
return p
}
// SetMitreLimit sets p's mitre limit.
func (p *BufferParams) SetMitreLimit(mitreLimit float64) *BufferParams {
p.context.Lock()
defer p.context.Unlock()
if C.GEOSBufferParams_setMitreLimit_r(p.context.handle, p.bufferParams, C.double(mitreLimit)) != 1 {
panic(p.context.err)
}
return p
}
// SetQuadrantSegments sets the number of segments to stroke each quadrant of
// circular arcs.
func (p *BufferParams) SetQuadrantSegments(quadSegs int) *BufferParams {
p.context.Lock()
defer p.context.Unlock()
if C.GEOSBufferParams_setQuadrantSegments_r(p.context.handle, p.bufferParams, C.int(quadSegs)) != 1 {
panic(p.context.err)
}
return p
}
// SetSingleSided sets whether the computed buffer should be single sided.
func (p *BufferParams) SetSingleSided(singleSided bool) *BufferParams {
p.context.Lock()
defer p.context.Unlock()
if C.GEOSBufferParams_setSingleSided_r(p.context.handle, p.bufferParams, C.int(intFromBool(singleSided))) != 1 {
panic(p.context.err)
}
return p
}
func (p *BufferParams) finalize() {
if p.context == nil {
return
}
p.Destroy()
}
func intFromBool(b bool) int {
if b {
return 1
}
return 0
}