-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathshapeRectangle.go
More file actions
74 lines (59 loc) · 1.6 KB
/
shapeRectangle.go
File metadata and controls
74 lines (59 loc) · 1.6 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
package gorough
import (
"github.com/NovikovRoman/gorough/data_parser"
)
type rectangle struct {
options *RectangleOptions
operations []operation
}
func (r rectangle) Name() string {
return shapeRectangle
}
func (r rectangle) Operations() []operation {
return r.operations
}
func (r rectangle) Attributes() Attributes {
return map[string]string{
"stroke": r.options.Styles.Stroke,
"stroke-width": data_parser.FloatToString(r.options.Styles.StrokeWidth),
"fill": r.options.Styles.Fill,
"fill-weight": data_parser.FloatToString(r.options.Styles.FillWeight),
}
}
func (r rectangle) Styles() *Styles {
return r.options.Styles
}
func NewRectangle(p Point, width, height float64, opt *RectangleOptions) *rectangle {
if opt == nil {
opt = &RectangleOptions{}
}
if opt.PenOptions == nil {
opt.PenOptions = PenOptionsDefault()
}
if opt.Styles == nil {
opt.Styles = StylesDefault()
}
opt.Styles.canonicalValues()
var operations []operation
operations = []operation{}
outline := rectangleOperation(p, width, height, opt)
if opt.Styles.Fill != "" {
points := []Point{p, {X: p.X + width, Y: p.Y}, {X: p.X + width, Y: p.Y + height}, {X: p.X, Y: p.Y + height}}
if opt.Styles.Filler == nil {
operations = append(operations, solidFillPolygon(points, opt.PenOptions))
} else {
operations = append(operations, patternFillPolygon(points, &LineOptions{
PenOptions: opt.PenOptions,
Styles: opt.Styles,
}))
}
}
if opt.Styles.Stroke != None {
operations = append(operations, outline)
}
r := &rectangle{
options: opt,
operations: operations,
}
return r
}