From c3819a378a180388e391231ac798c1dba59d7173 Mon Sep 17 00:00:00 2001 From: Sean Condon Date: Fri, 24 Apr 2020 15:13:52 +0100 Subject: [PATCH] Expose the "point" struct and the "orientation" --- go.mod | 3 +++ layout.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 go.mod diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..9900ac5 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/pmcxs/hexgrid + +go 1.14 diff --git a/layout.go b/layout.go index a7612ca..3669a2b 100644 --- a/layout.go +++ b/layout.go @@ -21,6 +21,40 @@ var orientationPointy orientation = orientation{math.Sqrt(3.), math.Sqrt(3.) / 2 var orientationFlat orientation = orientation{3. / 2., 0., math.Sqrt(3.) / 2., math.Sqrt(3.), 2. / 3., 0., -1. / 3., math.Sqrt(3.) / 3., 0.} +// LayoutFlat returns a layout with flat orientation +func LayoutFlat00(sizex float64, sizey float64) layout { + return layout{ + orientation: orientationFlat, + size: point{ + x: sizex, + y: sizey, + }, + origin: point{ + x: 0, + y: 0, + }, + } +} + +// LayoutPointY00 returns a layout with flat orientation +func LayoutPointY00(sizex float64, sizey float64) layout { + return layout{ + orientation: orientationPointy, + size: point{ + x: sizex, + y: sizey, + }, + origin: point{ + x: 0, + y: 0, + }, + } +} + +func Point(point point) (float64, float64) { + return point.x, point.y +} + // HexToPixel returns the center pixel for a given hexagon an a certain layout func HexToPixel(l layout, h hex) point {