-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathshapeCurve.go
More file actions
81 lines (64 loc) · 1.75 KB
/
shapeCurve.go
File metadata and controls
81 lines (64 loc) · 1.75 KB
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
package gorough
import (
"github.com/NovikovRoman/gorough/data_parser"
)
type curve struct {
options *EllipseOptions
operations []operation
}
func (c curve) Name() string {
return shapeCurve
}
func (c curve) Operations() []operation {
return c.operations
}
func (c curve) Attributes() Attributes {
return map[string]string{
"stroke": c.options.Styles.Stroke,
"stroke-width": data_parser.FloatToString(c.options.Styles.StrokeWidth),
"fill": c.options.Styles.Fill,
"fill-weight": data_parser.FloatToString(c.options.Styles.FillWeight),
}
}
func (c curve) Styles() *Styles {
return c.options.Styles
}
func NewCurve(points []Point, opt *EllipseOptions) *curve {
if opt == nil {
opt = &EllipseOptions{}
}
if opt.PenOptions == nil {
opt.PenOptions = PenOptionsDefault()
}
if opt.CurveOptions == nil {
opt.CurveOptions = CurveOptionsDefault()
}
if opt.Styles == nil {
opt.Styles = StylesDefault()
}
opt.Styles.canonicalValues()
var operations []operation
operations = []operation{}
outline := curveOperation(points, opt)
if opt.Styles.Fill != None && len(points) >= 3 {
// Ошибку не проверяем, тк уже проверили количество точек
bcurve, _ := CurveToBezier(points, 0)
polyPoints := PointsOnBezierCurves(bcurve, 10, (1+opt.PenOptions.Roughness)/2)
if opt.Styles.Filler == nil {
operations = append(operations, solidFillPolygon(polyPoints, opt.PenOptions))
} else {
operations = append(operations, patternFillPolygon(polyPoints, &LineOptions{
PenOptions: opt.PenOptions,
Styles: opt.Styles,
}))
}
}
if opt.Styles.Stroke != None {
operations = append(operations, outline)
}
c := &curve{
options: opt,
operations: operations,
}
return c
}