github.com/aarzilli/tools@v0.0.0-20151123112009-0d27094f75e0/transposablematrix/32-fusion-type-and-enums.go (about) 1 package transposablematrix 2 3 import "github.com/pbberlin/tools/util" 4 5 type CurveDesc int 6 7 const ( 8 cncave CurveDesc = iota 9 stairW // open towards west 10 stairE // open towards east 11 convex 12 ) 13 14 func (c CurveDesc) String() string { 15 switch c { 16 case cncave: 17 return "cncave" 18 case stairW: 19 return "stairW" 20 case stairE: 21 return "stairE" 22 case convex: 23 return "convex" 24 } 25 return "" 26 } 27 28 type Fusion struct { 29 idxL []int // indexes to the outline. Turned out unused, but kept. 30 base Point // point to the leftmost, lowest position of the fusion - for later stitching 31 32 // the lengths of the fusion edges, directions x-y-x 33 // x - western horizontal section, y - shared vertical, x - eastern horiz. sect 34 xyx []int 35 36 w, e []int // the lengths of the west/eastward continuations edges: directions y-x-y 37 pm []int // permissiveness westwards/eastwards/northwards 38 curveDesc CurveDesc // strongly concave, weakly concave or convex surroundings 39 } 40 41 func NewFusion() Fusion { 42 ret := Fusion{} 43 ret.idxL = make([]int, 0, 4) 44 ret.xyx = make([]int, 0, 3) 45 ret.w = make([]int, 0, 3) 46 ret.e = make([]int, 0, 3) 47 ret.pm = make([]int, 0, 3) 48 return ret 49 } 50 51 func (f Fusion) Print() { 52 53 if f.idxL == nil { 54 return 55 } 56 57 pf("fusn:%2v %2v %2v %2v | ", f.idxL[0], f.idxL[1], f.idxL[2], f.idxL[3]) 58 t1 := spf("%v;%v", f.base.x, f.base.y) 59 pf("baseP%6s | ", t1) 60 pf("xyx % 3v % 3v % 3v | ", f.xyx[0], f.xyx[1], f.xyx[2]) 61 pf("w % 2v % 2v % 2v | ", f.w[0], f.w[1], f.w[2]) 62 pf("e % 2v % 2v % 2v | ", f.e[0], f.e[1], f.e[2]) 63 64 pmd := make([]string, len(f.pm)) 65 for i := 0; i < len(f.pm); i++ { 66 if f.pm[i] < 0 { 67 pmd[i] = "bl" 68 } else { 69 pmd[i] = spf("%v", f.pm[i]) 70 } 71 } 72 73 pf("%s | overgr w%v e%v n%v | ", f.curveDesc, pmd[0], pmd[1], pmd[2]) 74 75 pf("\n") 76 77 } 78 79 // FillHeightFloor is the recommended minimal height 80 // of an amorph to fill in. 81 // 82 func (f Fusion) FillHeightFloor() int { 83 84 if f.xyx == nil || len(f.xyx) < 2 { 85 return cFusionHeightDefault 86 } 87 88 if f.xyx[1] > 0 { 89 // lower western flank => max of western or middle flank 90 if f.w == nil || len(f.w) < 1 { 91 return cFusionHeightDefault 92 } 93 return util.Max(f.xyx[1], f.w[0]) 94 } else { 95 // lower eastern flank => max of eastern or middle flank 96 if f.e == nil || len(f.e) < 1 { 97 return cFusionHeightDefault 98 } 99 return util.Max(-f.xyx[1], f.e[0]) 100 } 101 102 }