use gg.Str instead of gim.str

This commit is contained in:
Brian Picciano 2017-11-24 11:05:58 -07:00
parent 7c7502b42f
commit 286c2fbb35
4 changed files with 31 additions and 25 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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),
}

View File

@ -9,7 +9,7 @@ import (
type view struct {
g *gg.Graph
flowDir geo.XY
start str
start gg.Str
center geo.XY
}