MCPcopy
hub / github.com/tdewolff/canvas / BeveledRectangle

Function BeveledRectangle

shapes.go:74–96  ·  view source on GitHub ↗

BeveledRectangle returns a rectangle of width w and height h with beveled corners at distance r from the corner.

(w, h, r float64)

Source from the content-addressed store, hash-verified

72
73// BeveledRectangle returns a rectangle of width w and height h with beveled corners at distance r from the corner.
74func BeveledRectangle(w, h, r float64) *Path {
75 if Equal(w, 0.0) || Equal(h, 0.0) {
76 return &Path{}
77 } else if Equal(r, 0.0) {
78 return Rectangle(w, h)
79 }
80
81 r = math.Abs(r)
82 r = math.Min(r, w/2.0)
83 r = math.Min(r, h/2.0)
84
85 p := &Path{}
86 p.MoveTo(0.0, r)
87 p.LineTo(r, 0.0)
88 p.LineTo(w-r, 0.0)
89 p.LineTo(w, r)
90 p.LineTo(w, h-r)
91 p.LineTo(w-r, h)
92 p.LineTo(r, h)
93 p.LineTo(0.0, h-r)
94 p.Close()
95 return p
96}
97
98// Circle returns a circle of radius r.
99func Circle(r float64) *Path {

Callers 1

TestShapesFunction · 0.85

Calls 5

MoveToMethod · 0.95
LineToMethod · 0.95
CloseMethod · 0.95
EqualFunction · 0.85
RectangleFunction · 0.85

Tested by 1

TestShapesFunction · 0.68