From fb29d6a11c4622b83f4894ab1d6b4000eeffe62c Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Wed, 3 Jul 2019 17:19:25 -0700 Subject: [PATCH] Editor Mode: Line Tool and Rectangle Tool * Add support for the LineTool and RectTool while in the EditorMode to easily draw straight lines and rectangle outlines. * Key bindings were added to toggle tools in lieu of a proper UI to select the tool from a toolbar. * "F" for Pencil (Freehand) Tool (since "P" is for "Playtest") * "L" for Line Tool * "R" for Rectangle Tool --- interface.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/interface.go b/interface.go index 82d3966..3654a38 100644 --- a/interface.go +++ b/interface.go @@ -235,3 +235,44 @@ func IterLine(x1, y1, x2, y2 int32) chan Point { func IterLine2(p1 Point, p2 Point) chan Point { return IterLine(p1.X, p1.Y, p2.X, p2.Y) } + +// IterRect loops through all the points forming a rectangle between the +// top-left point and the bottom-right point. +func IterRect(p1, p2 Point) chan Point { + generator := make(chan Point) + + go func() { + var ( + TopLeft = p1 + BottomRight = p2 + TopRight = Point{ + X: BottomRight.X, + Y: TopLeft.Y, + } + BottomLeft = Point{ + X: TopLeft.X, + Y: BottomRight.Y, + } + ) + + // Trace all four edges and yield it. + var edges = []struct { + A Point + B Point + }{ + {TopLeft, TopRight}, + {TopLeft, BottomLeft}, + {BottomLeft, BottomRight}, + {TopRight, BottomRight}, + } + for _, edge := range edges { + for pt := range IterLine2(edge.A, edge.B) { + generator <- pt + } + } + + close(generator) + }() + + return generator +}