graphcis: Refactoring

This commit is contained in:
Hajime Hoshi 2017-01-20 01:20:04 +09:00
parent 6e84919ed5
commit f8e589dd9c
2 changed files with 14 additions and 10 deletions

View File

@ -35,14 +35,16 @@ func vertices(parts ImageParts, width, height int, geo *affine.GeoM) []float32 {
g3 := g[4] g3 := g[4]
g4 := g[2] g4 := g[2]
g5 := g[5] g5 := g[5]
w := 1.0 w := 1
h := 1.0 h := 1
for w < float64(width) { for w < width {
w *= 2 w *= 2
} }
for h < float64(height) { for h < height {
h *= 2 h *= 2
} }
wf := float64(w)
hf := float64(h)
n := 0 n := 0
for i := 0; i < l; i++ { for i := 0; i < l; i++ {
dx0, dy0, dx1, dy1 := parts.Dst(i) dx0, dy0, dx1, dy1 := parts.Dst(i)
@ -53,7 +55,7 @@ func vertices(parts ImageParts, width, height int, geo *affine.GeoM) []float32 {
if sx0 == sx1 || sy0 == sy1 { if sx0 == sx1 || sy0 == sy1 {
continue continue
} }
u0, v0, u1, v1 := float64(sx0)/w, float64(sy0)/h, float64(sx1)/w, float64(sy1)/h u0, v0, u1, v1 := float64(sx0)/wf, float64(sy0)/hf, float64(sx1)/wf, float64(sy1)/hf
vs.SetIndex(n, dx0) vs.SetIndex(n, dx0)
vs.SetIndex(n+1, dy0) vs.SetIndex(n+1, dy0)
vs.SetIndex(n+2, u0) vs.SetIndex(n+2, u0)

View File

@ -33,14 +33,16 @@ func vertices(parts ImageParts, width, height int, geo *affine.GeoM) []float32 {
g3 := float32(g[4]) g3 := float32(g[4])
g4 := float32(g[2]) g4 := float32(g[2])
g5 := float32(g[5]) g5 := float32(g[5])
w := float32(1) w := 1
h := float32(1) h := 1
for w < float32(width) { for w < width {
w *= 2 w *= 2
} }
for h < float32(height) { for h < height {
h *= 2 h *= 2
} }
wf := float32(w)
hf := float32(h)
n := 0 n := 0
for i := 0; i < l; i++ { for i := 0; i < l; i++ {
dx0, dy0, dx1, dy1 := parts.Dst(i) dx0, dy0, dx1, dy1 := parts.Dst(i)
@ -52,7 +54,7 @@ func vertices(parts ImageParts, width, height int, geo *affine.GeoM) []float32 {
if sx0 == sx1 || sy0 == sy1 { if sx0 == sx1 || sy0 == sy1 {
continue continue
} }
u0, v0, u1, v1 := float32(sx0)/w, float32(sy0)/h, float32(sx1)/w, float32(sy1)/h u0, v0, u1, v1 := float32(sx0)/wf, float32(sy0)/hf, float32(sx1)/wf, float32(sy1)/hf
vs[n] = x0 vs[n] = x0
vs[n+1] = y0 vs[n+1] = y0
vs[n+2] = u0 vs[n+2] = u0