From f8e589dd9cf0d0003d064e2d477162c8da7c7e7f Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 20 Jan 2017 01:20:04 +0900 Subject: [PATCH] graphcis: Refactoring --- vertices_js.go | 12 +++++++----- vertices_notjs.go | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/vertices_js.go b/vertices_js.go index d7b9ce78a..759033a23 100644 --- a/vertices_js.go +++ b/vertices_js.go @@ -35,14 +35,16 @@ func vertices(parts ImageParts, width, height int, geo *affine.GeoM) []float32 { g3 := g[4] g4 := g[2] g5 := g[5] - w := 1.0 - h := 1.0 - for w < float64(width) { + w := 1 + h := 1 + for w < width { w *= 2 } - for h < float64(height) { + for h < height { h *= 2 } + wf := float64(w) + hf := float64(h) n := 0 for i := 0; i < l; 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 { 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+1, dy0) vs.SetIndex(n+2, u0) diff --git a/vertices_notjs.go b/vertices_notjs.go index 44fbc10a9..febc9bfbe 100644 --- a/vertices_notjs.go +++ b/vertices_notjs.go @@ -33,14 +33,16 @@ func vertices(parts ImageParts, width, height int, geo *affine.GeoM) []float32 { g3 := float32(g[4]) g4 := float32(g[2]) g5 := float32(g[5]) - w := float32(1) - h := float32(1) - for w < float32(width) { + w := 1 + h := 1 + for w < width { w *= 2 } - for h < float32(height) { + for h < height { h *= 2 } + wf := float32(w) + hf := float32(h) n := 0 for i := 0; i < l; 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 { 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+1] = y0 vs[n+2] = u0