From 286c2fbb353bfa55684a79d88a8c704d5ae843f3 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Fri, 24 Nov 2017 11:05:58 -0700 Subject: [PATCH] use gg.Str instead of gim.str --- gg/gg.go | 12 ++++++++++++ gim/box.go | 2 +- gim/main.go | 40 +++++++++++++++++----------------------- gim/view.go | 2 +- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/gg/gg.go b/gg/gg.go index 64db16d..2ddd4ff 100644 --- a/gg/gg.go +++ b/gg/gg.go @@ -8,6 +8,8 @@ import ( "hash" ) +// TODO instead of Identifier being public, make it encoding.TextMarshaler + // Identifier is implemented by any value which can return a unique string for // itself via an Identify method type Identifier interface { @@ -20,6 +22,16 @@ func identify(i Identifier) string { return hex.EncodeToString(h.Sum(nil)) } +// Str is an Identifier identified by its string value +type Str string + +// Identify implements the Identifier interface +func (s Str) Identify(h hash.Hash) { + fmt.Fprintf(h, "%q", s) +} + +//////////////////////////////////////////////////////////////////////////////// + // VertexType enumerates the different possible vertex types type VertexType string diff --git a/gim/box.go b/gim/box.go index d536f4a..6593f1b 100644 --- a/gim/box.go +++ b/gim/box.go @@ -43,7 +43,7 @@ func boxFromVertex(v *gg.Vertex, flowDir geo.XY) box { numOut: len(v.Out), } if v.VertexType == gg.Value { - b.body = string(v.Value.(str)) + b.body = string(v.Value.(gg.Str)) } return b } diff --git a/gim/main.go b/gim/main.go index 527b5fe..59deaee 100644 --- a/gim/main.go +++ b/gim/main.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "hash" "math/rand" "os" "strings" @@ -19,7 +18,8 @@ import ( // TODO // - assign edges to "slots" on boxes -// - figure out how to keep boxes sorted on their levels (e.g. the "b" nodes) +// - finish initial implementation of constraint, use that to sort boxes by +// primary and secondary flowDir based on their edges // - be able to draw circular graphs const ( @@ -28,12 +28,6 @@ const ( rounder = geo.Ceil ) -type str string - -func (s str) Identify(h hash.Hash) { - fmt.Fprintln(h, s) -} - func debugf(str string, args ...interface{}) { if !strings.HasSuffix(str, "\n") { str += "\n" @@ -42,23 +36,23 @@ func debugf(str string, args ...interface{}) { } func mkGraph() *gg.Graph { - aE0 := gg.ValueOut(str("a"), str("aE0")) - aE1 := gg.ValueOut(str("a"), str("aE1")) - aE2 := gg.ValueOut(str("a"), str("aE2")) - aE3 := gg.ValueOut(str("a"), str("aE3")) + aE0 := gg.ValueOut(gg.Str("a"), gg.Str("aE0")) + aE1 := gg.ValueOut(gg.Str("a"), gg.Str("aE1")) + aE2 := gg.ValueOut(gg.Str("a"), gg.Str("aE2")) + aE3 := gg.ValueOut(gg.Str("a"), gg.Str("aE3")) g := gg.Null - g = g.AddValueIn(aE0, str("b0")) - g = g.AddValueIn(aE1, str("b1")) - g = g.AddValueIn(aE2, str("b2")) - g = g.AddValueIn(aE3, str("b3")) + g = g.AddValueIn(aE0, gg.Str("b0")) + g = g.AddValueIn(aE1, gg.Str("b1")) + g = g.AddValueIn(aE2, gg.Str("b2")) + g = g.AddValueIn(aE3, gg.Str("b3")) jE := gg.JunctionOut([]gg.OpenEdge{ - gg.ValueOut(str("b0"), str("")), - gg.ValueOut(str("b1"), str("")), - gg.ValueOut(str("b2"), str("")), - gg.ValueOut(str("b3"), str("")), - }, str("jE")) - g = g.AddValueIn(jE, str("c")) + gg.ValueOut(gg.Str("b0"), gg.Str("")), + gg.ValueOut(gg.Str("b1"), gg.Str("")), + gg.ValueOut(gg.Str("b2"), gg.Str("")), + gg.ValueOut(gg.Str("b3"), gg.Str("")), + }, gg.Str("jE")) + g = g.AddValueIn(jE, gg.Str("c")) return g } @@ -77,7 +71,7 @@ func main() { v := view{ g: mkGraph(), flowDir: geo.Down, - start: str("c"), + start: gg.Str("c"), center: geo.Zero.Midpoint(term.WindowSize(), rounder), } diff --git a/gim/view.go b/gim/view.go index 94cb53a..8479614 100644 --- a/gim/view.go +++ b/gim/view.go @@ -9,7 +9,7 @@ import ( type view struct { g *gg.Graph flowDir geo.XY - start str + start gg.Str center geo.XY }