diagonal layout now goes i nthe correct direction and refactored some internals

This commit is contained in:
Scott Davis 2011-09-03 15:56:57 -04:00
parent c7c007672f
commit 09dd9456e1
2 changed files with 5 additions and 5 deletions

View File

@ -57,8 +57,8 @@ module Compass
def calculate_diagonal_dimensions
@width = @images.map {|image| image.width}.inject(0) {|width, sum| sum + width}
@height = @images.map {|image| image.height}.inject(0) {|height, sum| sum + height}
@width = @images.inject(0) {|sum, img| sum + img.width}
@height = @images.inject(0) {|sum, img| sum + img.height}
end
def calculate_diagonal_positions
@ -66,11 +66,11 @@ module Compass
@images.each_with_index do |image, index|
if previous.nil?
previous = image
image.top = 0
image.top = @height - image.height
image.left = 0
next
end
image.top = previous.top + previous.height
image.top = previous.top - image.height
image.left = previous.left + previous.width
previous = image
end

View File

@ -126,7 +126,7 @@ class SpriteMapTest < Test::Unit::TestCase
base.generate
assert_equal 40, base.width
assert_equal 40, base.height
assert_equal [[0,0], [10,10], [20,20], [30,30]], base.images.map {|i| [i.top, i.left]}
assert_equal [[30, 0], [20, 10], [10, 20], [0, 30]], base.images.map {|i| [i.top, i.left]}
assert File.exists?(base.filename)
FileUtils.rm base.filename
end