draw2d/advanced_path.go

49 lines
1.2 KiB
Go
Raw Normal View History

2011-04-27 08:06:14 +00:00
// Copyright 2010 The draw2d Authors. All rights reserved.
// created: 13/12/2010 by Laurent Le Goff
2012-04-17 09:03:56 +00:00
2015-07-07 22:17:58 +00:00
//high level path creation
2011-04-27 08:06:14 +00:00
package draw2d
import (
"math"
)
2015-07-07 22:17:58 +00:00
// Rect draws a rectangle between (x1,y1) and (x2,y2)
2011-04-27 08:06:14 +00:00
func Rect(path Path, x1, y1, x2, y2 float64) {
path.MoveTo(x1, y1)
path.LineTo(x2, y1)
path.LineTo(x2, y2)
path.LineTo(x1, y2)
path.Close()
}
2015-07-07 22:17:58 +00:00
// RoundRect draws a rectangle between (x1,y1) and (x2,y2) with rounded corners
2011-04-27 08:06:14 +00:00
func RoundRect(path Path, x1, y1, x2, y2, arcWidth, arcHeight float64) {
arcWidth = arcWidth / 2
arcHeight = arcHeight / 2
path.MoveTo(x1, y1+arcHeight)
path.QuadCurveTo(x1, y1, x1+arcWidth, y1)
path.LineTo(x2-arcWidth, y1)
path.QuadCurveTo(x2, y1, x2, y1+arcHeight)
path.LineTo(x2, y2-arcHeight)
path.QuadCurveTo(x2, y2, x2-arcWidth, y2)
path.LineTo(x1+arcWidth, y2)
path.QuadCurveTo(x1, y2, x1, y2-arcHeight)
path.Close()
}
2015-07-07 22:17:58 +00:00
// Ellipse is drawn with center (cx,cy) and radius (rx,ry)
2011-04-27 08:06:14 +00:00
func Ellipse(path Path, cx, cy, rx, ry float64) {
path.MoveTo(cx-rx, cy)
2011-04-27 08:06:14 +00:00
path.ArcTo(cx, cy, rx, ry, 0, -math.Pi*2)
path.Close()
}
2015-07-07 22:17:58 +00:00
// Circle is drawn with center (cx,cy) and radius
2011-04-27 08:06:14 +00:00
func Circle(path Path, cx, cy, radius float64) {
path.MoveTo(cx-radius, cy)
2011-04-27 08:06:14 +00:00
path.ArcTo(cx, cy, radius, radius, 0, -math.Pi*2)
path.Close()
}