-
Notifications
You must be signed in to change notification settings - Fork 2
/
circle.go
68 lines (60 loc) · 1.53 KB
/
circle.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
package graphics
import (
"gioui.org/f32"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/unit"
"github.com/corywalker/expreduce/expreduce/atoms"
"github.com/wrnrlr/shape"
"image"
)
func toCircle(e *atoms.Expression) (*Circle, error) {
var err error
center := f32.Point{}
radius := float32(1)
length := e.Len()
if length == 1 {
center, err = toPoint(e.GetPart(1))
if err != nil {
return nil, err
}
} else if length == 2 {
center, err = toPoint(e.GetPart(1))
if err != nil {
return nil, err
}
radius, err = toFloat(e.GetPart(2))
if err != nil {
return nil, err
}
}
c := &Circle{center, radius}
return c, nil
}
type Circle struct {
center f32.Point
radius float32
}
func (c Circle) Draw(ctx *context, gtx *layout.Context) {
center := ctx.transformPoint(c.center)
radius := c.radius * float32(gtx.Px(unit.Sp(50)))
rgba := *ctx.style.StrokeColor
var stack op.StackOp
stack.Push(gtx.Ops)
r := shape.Circle{center, radius}.Stroke(rgba, ctx.style.Thickness, gtx)
stack.Pop()
p := image.Point{X: int(r.Max.X), Y: int(r.Max.Y)}
gtx.Dimensions = layout.Dimensions{Size: p, Baseline: int(r.Max.Y / 2)}
}
func (c Circle) BoundingBox() (bbox f32.Rectangle) {
min := f32.Point{X: c.center.X - c.radius, Y: c.center.Y - c.radius}
max := f32.Point{X: c.center.X + c.radius, Y: c.center.Y + c.radius}
return f32.Rectangle{Min: min, Max: max}
}
type Ellipse struct{}
type Arc struct{}
//func scaleRectangle(r f32.Rectangle) f32.Rectangle {
// min := r.Min.Mul(100)
// min := r.Min.Mul(100)
// rs := f32.Rectangle{}
//}