-
Notifications
You must be signed in to change notification settings - Fork 1
/
potracelib.go
113 lines (106 loc) · 2.17 KB
/
potracelib.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Code generated by cxgo. DO NOT EDIT.
package gotrace
import (
"unsafe"
)
const TurnBlack = 0
const TurnWhite = 1
const TurnLeft = 2
const TurnRight = 3
const TurnMinority = 4
const TurnMajority = 5
const TurnRandom = 6
const POTRACE_CURVETO = 1
const POTRACE_CORNER = 2
const statusOK = 0
const statusIncomplete = 1
type Progress struct {
Callback func(progress float64, privdata unsafe.Pointer)
Data unsafe.Pointer
Min float64
Max float64
Epsilon float64
}
type Config struct {
TurdSize int
TurnPolicy int
AlphaMax float64
OptiCurve bool
OptTolerance float64
Progress Progress
}
type Word uint
type Bitmap struct {
W int
H int
Dy int
Map []Word
}
type DPoint struct {
X float64
Y float64
}
type Curve struct {
N int
Tag []int
C [][3]DPoint
}
type Path struct {
Area int
Sign int
Curve Curve
Next *Path
Childlist *Path
Sibling *Path
Priv *potrace_privpath_s
}
type traceState struct {
Status int
Plist *Path
Priv *potrace_privstate_s
}
var param_default Config = Config{TurdSize: 2, TurnPolicy: TurnMinority, AlphaMax: 1.0, OptiCurve: true, OptTolerance: 0.2, Progress: Progress{Callback: nil, Data: nil, Min: 0.0, Max: 1.0, Epsilon: 0.0}}
func DefaultConfig() *Config {
var p *Config
p = new(Config)
if p == nil {
return nil
}
*p = param_default
return p
}
func traceBitmap(param *Config, bm *Bitmap) *traceState {
var (
r int
plist *Path = nil
st *traceState
prog progress
subprog progress
)
prog.Callback = param.Progress.Callback
prog.Data = param.Progress.Data
prog.Min = param.Progress.Min
prog.Max = param.Progress.Max
prog.Epsilon = param.Progress.Epsilon
prog.D_prev = param.Progress.Min
st = new(traceState)
if st == nil {
return nil
}
progress_subrange_start(0.0, 0.1, &prog, &subprog)
r = bm_to_pathlist(bm, &plist, param, &subprog)
if r != 0 {
return nil
}
st.Status = statusOK
st.Plist = plist
st.Priv = nil
progress_subrange_end(&prog, &subprog)
progress_subrange_start(0.1, 1.0, &prog, &subprog)
r = process_path(plist, param, &subprog)
if r != 0 {
st.Status = statusIncomplete
}
progress_subrange_end(&prog, &subprog)
return st
}