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

Function RoundedRectangle

shapes.go:45–71  ·  view source on GitHub ↗

RoundedRectangle returns a rectangle of width w and height h with rounded corners of radius r. A negative radius will cast the corners inwards (i.e. concave).

(w, h, r float64)

Source from the content-addressed store, hash-verified

43
44// RoundedRectangle returns a rectangle of width w and height h with rounded corners of radius r. A negative radius will cast the corners inwards (i.e. concave).
45func RoundedRectangle(w, h, r float64) *Path {
46 if Equal(w, 0.0) || Equal(h, 0.0) {
47 return &Path{}
48 } else if Equal(r, 0.0) {
49 return Rectangle(w, h)
50 }
51
52 sweep := true
53 if r < 0.0 {
54 sweep = false
55 r = -r
56 }
57 r = math.Min(r, w/2.0)
58 r = math.Min(r, h/2.0)
59
60 p := &Path{}
61 p.MoveTo(0.0, r)
62 p.ArcTo(r, r, 0.0, false, sweep, r, 0.0)
63 p.LineTo(w-r, 0.0)
64 p.ArcTo(r, r, 0.0, false, sweep, w, r)
65 p.LineTo(w, h-r)
66 p.ArcTo(r, r, 0.0, false, sweep, w-r, h)
67 p.LineTo(r, h)
68 p.ArcTo(r, r, 0.0, false, sweep, 0.0, h-r)
69 p.Close()
70 return p
71}
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 {

Callers 4

mainFunction · 0.92
drawFunction · 0.92
TestShapesFunction · 0.85
drawShapeMethod · 0.85

Calls 6

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

Tested by 1

TestShapesFunction · 0.68