Skip to content

Commit

Permalink
moving to handling full float64 for resizing computation, fixing #5. …
Browse files Browse the repository at this point in the history
…Also, the new integration test run twice each, so that the issue mentioned will be auto-tested on integration level. Thanks @RebelDesigner for the amazing troubleshooting spirit! 👍
  • Loading branch information
jondot committed Oct 8, 2015
1 parent bde4fb9 commit f3ad72d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 21 deletions.
10 changes: 5 additions & 5 deletions dimensions.go
Expand Up @@ -8,8 +8,8 @@ type Dimensions struct {
}

type Rect struct {
Width uint
Height uint
Width float64
Height float64
}

func NewDimensions() *Dimensions {
Expand Down Expand Up @@ -45,8 +45,8 @@ func (d *Dimensions) Compute(contents *Contents, meta *ContentsImage, sourceRect
scaleDownFactor := float64(meta.GetScale()) / highestFactor
//log.Printf("%v scale factor: %1.2f computed from %d and highest %2.0f", meta, scaleDownFactor, meta.GetScale(), highestFactor)
return Rect{
uint(float64(sourceRect.Width) * scaleDownFactor),
uint(float64(sourceRect.Height) * scaleDownFactor),
float64(sourceRect.Width) * scaleDownFactor,
float64(sourceRect.Height) * scaleDownFactor,
}

}
Expand All @@ -55,5 +55,5 @@ func dimensionFromSize(c *ContentsImage) Rect {
w, h := c.GetSize()
factor := float64(c.GetScale())

return Rect{Width: uint(factor * w), Height: uint(factor * h)}
return Rect{Width: factor * w, Height: factor * h}
}
Expand Up @@ -4,19 +4,19 @@
"filename": "source-universal-333@1x.png",
"idiom": "universal",
"scale": "1x",
"size": "333x333"
"size": "333.3333333333333x333.3333333333333"
},
{
"filename": "source-universal-333@2x.png",
"idiom": "universal",
"scale": "2x",
"size": "666x666"
"size": "333.3333333333333x333.3333333333333"
},
{
"filename": "source-universal-333@3x.png",
"idiom": "universal",
"scale": "3x",
"size": "1000x1000"
"size": "333.3333333333333x333.3333333333333"
}
],
"info": {
Expand Down
Expand Up @@ -4,37 +4,37 @@
"filename": "source-universal-333@1x.png",
"idiom": "universal",
"scale": "1x",
"size": "333x333"
"size": "333.3333333333333x333.3333333333333"
},
{
"filename": "source-universal-333@2x.png",
"idiom": "universal",
"scale": "2x",
"size": "666x666"
"size": "333.3333333333333x333.3333333333333"
},
{
"filename": "source-universal-333@3x.png",
"idiom": "universal",
"scale": "3x",
"size": "1000x1000"
"size": "333.3333333333333x333.3333333333333"
},
{
"filename": "source-watch-500@2x.png",
"idiom": "watch",
"scale": "2x",
"size": "1000x1000"
"size": "500x500"
},
{
"filename": "source-watch-500@2x.png",
"idiom": "watch",
"scale": "2x",
"size": "1000x1000"
"size": "500x500"
},
{
"filename": "source-watch-500@2x.png",
"idiom": "watch",
"scale": "2x",
"size": "1000x1000"
"size": "500x500"
}
],
"info": {
Expand Down
10 changes: 7 additions & 3 deletions integration.rb
Expand Up @@ -17,9 +17,13 @@ def error_if(condition, msg)
cd test_dir
rm_rf "after"
cp_r "before", "after"
blade_out = `#{blade}`
error_if(!blade_out.empty?, blade_out)
exit(1) unless blade_out.empty?

2.times do
blade_out = `#{blade}`
error_if(!blade_out.empty?, blade_out)
exit(1) unless blade_out.empty?
end

diff_out = `git diff #{test_dir}`
error_if(!diff_out.empty?, diff_out)
putc "."
Expand Down
6 changes: 3 additions & 3 deletions resize_converter.go
Expand Up @@ -38,8 +38,8 @@ func (r *ResizeConverter) Size(inFile string) (Rect, error) {
}

return Rect{
uint(source.Bounds().Dx()),
uint(source.Bounds().Dy()),
float64(source.Bounds().Dx()),
float64(source.Bounds().Dy()),
}, nil
}

Expand All @@ -66,7 +66,7 @@ func (r *ResizeConverter) Convert(inFile string, outFile string, rect Rect) erro
interp = interpolations["l3"]
}

resized := resize.Resize(rect.Width, rect.Height, source, interp)
resized := resize.Resize(uint(rect.Width), uint(rect.Height), source, interp)
png.Encode(out, resized)
return nil
}
2 changes: 1 addition & 1 deletion runner.go
Expand Up @@ -35,7 +35,7 @@ func (f *Runner) run() {

// sync meta structure with the new data we've generated
if meta.Size == "" {
meta.Size = fmt.Sprintf("%dx%d", rect.Width, rect.Height)
meta.Size = fmt.Sprintf("%vx%v", float64(rect.Width)/float64(meta.GetScale()), float64(rect.Height)/float64(meta.GetScale()))
}
if meta.Filename == "" {
baseName := strings.TrimSuffix(path.Base(f.SourceFile), path.Ext(f.SourceFile))
Expand Down

0 comments on commit f3ad72d

Please sign in to comment.