aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/llgcode/draw2d/draw2dkit
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/llgcode/draw2d/draw2dkit')
-rw-r--r--vendor/github.com/llgcode/draw2d/draw2dkit/README.md7
-rw-r--r--vendor/github.com/llgcode/draw2d/draw2dkit/draw2dkit.go47
-rw-r--r--vendor/github.com/llgcode/draw2d/draw2dkit/draw2dkit_test.go29
3 files changed, 83 insertions, 0 deletions
diff --git a/vendor/github.com/llgcode/draw2d/draw2dkit/README.md b/vendor/github.com/llgcode/draw2d/draw2dkit/README.md
new file mode 100644
index 0000000..deaf45f
--- /dev/null
+++ b/vendor/github.com/llgcode/draw2d/draw2dkit/README.md
@@ -0,0 +1,7 @@
+draw2d/draw2dkit
+=================
+
+[![Coverage](http://gocover.io/_badge/github.com/llgcode/draw2d/draw2dkit?0)](http://gocover.io/github.com/llgcode/draw2d/draw2dkit)
+[![GoDoc](https://godoc.org/github.com/llgcode/draw2d/draw2dkit?status.svg)](https://godoc.org/github.com/llgcode/draw2d/draw2dkit)
+
+Util package that help drawing common vectorial draw.
diff --git a/vendor/github.com/llgcode/draw2d/draw2dkit/draw2dkit.go b/vendor/github.com/llgcode/draw2d/draw2dkit/draw2dkit.go
new file mode 100644
index 0000000..eab81da
--- /dev/null
+++ b/vendor/github.com/llgcode/draw2d/draw2dkit/draw2dkit.go
@@ -0,0 +1,47 @@
+// Copyright 2010 The draw2d Authors. All rights reserved.
+// created: 13/12/2010 by Laurent Le Goff
+
+// Package draw2dkit provides helpers to draw common figures using a Path
+package draw2dkit
+
+import (
+ "math"
+
+ "github.com/llgcode/draw2d"
+)
+
+// Rectangle draws a rectangle using a path between (x1,y1) and (x2,y2)
+func Rectangle(path draw2d.PathBuilder, x1, y1, x2, y2 float64) {
+ path.MoveTo(x1, y1)
+ path.LineTo(x2, y1)
+ path.LineTo(x2, y2)
+ path.LineTo(x1, y2)
+ path.Close()
+}
+
+// RoundedRectangle draws a rectangle using a path between (x1,y1) and (x2,y2)
+func RoundedRectangle(path draw2d.PathBuilder, 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()
+}
+
+// Ellipse draws an ellipse using a path with center (cx,cy) and radius (rx,ry)
+func Ellipse(path draw2d.PathBuilder, cx, cy, rx, ry float64) {
+ path.ArcTo(cx, cy, rx, ry, 0, -math.Pi*2)
+ path.Close()
+}
+
+// Circle draws a circle using a path with center (cx,cy) and radius
+func Circle(path draw2d.PathBuilder, cx, cy, radius float64) {
+ path.ArcTo(cx, cy, radius, radius, 0, -math.Pi*2)
+ path.Close()
+}
diff --git a/vendor/github.com/llgcode/draw2d/draw2dkit/draw2dkit_test.go b/vendor/github.com/llgcode/draw2d/draw2dkit/draw2dkit_test.go
new file mode 100644
index 0000000..09eb0e4
--- /dev/null
+++ b/vendor/github.com/llgcode/draw2d/draw2dkit/draw2dkit_test.go
@@ -0,0 +1,29 @@
+package draw2dkit
+
+import (
+ "image"
+ "image/color"
+ "testing"
+
+ "github.com/llgcode/draw2d/draw2dimg"
+)
+
+func TestCircle(t *testing.T) {
+ width := 200
+ height := 200
+ img := image.NewRGBA(image.Rect(0, 0, width, height))
+ gc := draw2dimg.NewGraphicContext(img)
+
+ gc.SetStrokeColor(color.NRGBA{255, 255, 255, 255})
+ gc.SetFillColor(color.NRGBA{255, 255, 255, 255})
+ gc.Clear()
+
+ gc.SetStrokeColor(color.NRGBA{255, 0, 0, 255})
+ gc.SetLineWidth(1)
+
+ // Draw a circle
+ Circle(gc, 100, 100, 50)
+ gc.Stroke()
+
+ draw2dimg.SaveToPngFile("../output/draw2dkit/TestCircle.png", img)
+}