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)
| 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). |
| 45 | func 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. |
| 74 | func BeveledRectangle(w, h, r float64) *Path { |