-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw.go
77 lines (65 loc) · 2.38 KB
/
draw.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
package graphics2d
import (
"image/draw"
)
// Simple immediate drawing and filling functions with pens
// DrawPoint renders a point with the pen into the destination image.
func DrawPoint(dst draw.Image, at []float64, pen *Pen) {
DrawShape(dst, NewShape(Point(at)), pen)
}
// DrawLine renders a line with the pen into the destination image.
func DrawLine(dst draw.Image, start, end []float64, pen *Pen) {
DrawShape(dst, NewShape(Line(start, end)), pen)
}
// DrawArc renders an arc with the pen into the destination image.
// radians +ve CCW, -ve CW
func DrawArc(dst draw.Image, start, center []float64, radians float64, pen *Pen) {
DrawShape(dst, NewShape(ArcFromPoint(start, center, radians, ArcOpen)), pen)
}
// DrawPath renders a path with the pen into the destination image.
func DrawPath(dst draw.Image, path *Path, pen *Pen) {
DrawShape(dst, NewShape(path), pen)
}
// DrawShape renders a shape with the pen into the destination image.
func DrawShape(dst draw.Image, shape *Shape, pen *Pen) {
if pen.Stroke != nil {
shape = shape.ProcessPaths(pen.Stroke)
}
if pen.Xfm != nil {
shape = shape.Transform(pen.Xfm)
}
RenderShape(dst, shape, pen.Filler)
}
// DrawClippedShape renders a shape with the pen against a clip shape into the destination image.
func DrawClippedShape(dst draw.Image, shape, clip *Shape, pen *Pen) {
if pen.Stroke != nil {
shape = shape.ProcessPaths(pen.Stroke)
}
if pen.Xfm != nil {
shape = shape.Transform(pen.Xfm)
}
RenderClippedShape(dst, shape, clip, pen.Filler)
}
// Fill functions ignore the pen stroke and if any path isn't closed, it's forced so.
// FillPath renders a path with the pen filler image and transform into the destination image.
func FillPath(dst draw.Image, path *Path, pen *Pen) {
shape := NewShape(path)
if pen.Xfm != nil {
shape = shape.Transform(pen.Xfm)
}
RenderShape(dst, shape, pen.Filler)
}
// FillShape renders a shape with the pen filler and transform into the destination image.
func FillShape(dst draw.Image, shape *Shape, pen *Pen) {
if pen.Xfm != nil {
shape = shape.Transform(pen.Xfm)
}
RenderShape(dst, shape, pen.Filler)
}
// FillClippedShape renders a shape with the pen filler against a clipe shape and transform into the destination image.
func FillClippedShape(dst draw.Image, shape, clip *Shape, pen *Pen) {
if pen.Xfm != nil {
shape = shape.Transform(pen.Xfm)
}
RenderClippedShape(dst, shape, clip, pen.Filler)
}