modify drawing logic
[from now] Fri Dec  6 03:06:12 JST 2013

diff --git a/blf.gemspec b/blf.gemspec
index 6fd9164..909f098 100644
--- a/blf.gemspec
+++ b/blf.gemspec
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
   spec.require_paths = ["lib"]

   spec.add_runtime_dependency "rmagick", "~> 2.0"
+  spec.add_runtime_dependency "activesupport"

   spec.add_development_dependency "bundler", "~> 1.3"
   spec.add_development_dependency "rake"
diff --git a/example/example.rb b/example/example.rb
index 2d0a671..d4178f8 100644
--- a/example/example.rb
+++ b/example/example.rb
@@ -3,5 +3,6 @@ require "./lib/blf"

 world = World.new width: 500, height: 500
 world.add_block_with_location start_x: 0, start_y: 0, width: 50, height: 50
-# world.add_block width: 25, height: 50
+world.add_block width: 25, height: 50
+world.allocate
 world.draw
diff --git a/lib/blf/block.rb b/lib/blf/block.rb
index 3b5ab88..331a5a0 100644
--- a/lib/blf/block.rb
+++ b/lib/blf/block.rb
@@ -1,11 +1,13 @@
+require "active_support/all"
+
 class Block
   def initialize(args)
-    @start_x = args[:start_x]
-    @start_y = args[:start_y]
+    @start_x = args[:start_x].presence
+    @start_y = args[:start_y].presence
     @width = args[:width]
     @height = args[:height]
-    @end_x = @start_x + @width
-    @end_y = @start_y + @height
+    @end_x = @start_x + @width if @start_x
+    @end_y = @start_y + @height if @start_y
     @world = args[:world]
   end

diff --git a/lib/blf/world.rb b/lib/blf/world.rb
index 067595b..28dcba8 100644
--- a/lib/blf/world.rb
+++ b/lib/blf/world.rb
@@ -7,16 +7,17 @@ class World
   def initialize(args)
     @width = args[:width]
     @height = args[:height]
-    @blocks = []
+    @unplaced_blocks = []
+    @placed_blocks = []
     @bl_stable_point_list = []
   end

   def add_block(args)
-    @blocks << Block.new(width: args[:width], height: args[:height], world: self)
+    @unplaced_blocks << Block.new(width: args[:width], height: args[:height], world: self)
   end

   def add_block_with_location(args)
-    @blocks << Block.new(start_x: args[:start_x], start_y: args[:start_y],
+    @placed_blocks << Block.new(start_x: args[:start_x], start_y: args[:start_y],
                          width: args[:width], height: args[:height], world: self)
   end

@@ -25,28 +26,32 @@ class World
     @bl_stable_point_list << { x: 0, y: current_block.start_y }
     @bl_stable_point_list << { x: current_block.start_x, y: 0 }

-    @blocks.each do |existing_block|
+    @placed_blocks.each do |placed_block|
       @bl_stable_point_list << case
-      when (existing_block.end_x <= current_block.start_x) && (existing_block.end_y > current_block.end_y)
-        { x: existing_block.end_x, y: current_block.end_y }
-      when (existing_block.end_x >= current_block.start_x) && (existing_block.end_y < current_block.end_y)
-        { x: current_block.end_x, y: existing_block.end_y }
-      when (existing_block.end_x > current_block.end_x) && (existing_block.end_y <= current_block.start_y)
-        { x: current_block.end_x, y: existing_block.end_y }
-      when (existing_block.end_x < current_block.end_x) && (existing_block.start_y > current_block.end_y)
-        { x: existing_block.end_x, y: current_block.end_y }
+      when (placed_block.end_x <= current_block.start_x) && (placed_block.end_y > current_block.end_y)
+        { x: placed_block.end_x, y: current_block.end_y }
+      when (placed_block.end_x >= current_block.start_x) && (placed_block.end_y < current_block.end_y)
+        { x: current_block.end_x, y: placed_block.end_y }
+      when (placed_block.end_x > current_block.end_x) && (placed_block.end_y <= current_block.start_y)
+        { x: current_block.end_x, y: placed_block.end_y }
+      when (placed_block.end_x < current_block.end_x) && (placed_block.start_y > current_block.end_y)
+        { x: placed_block.end_x, y: current_block.end_y }
       end
     end

     @bl_stable_point_list.compact
   end

+  def allocate
+
+  end
+
   def draw
     @image = Image.new(@width, @height) do
      self.background_color = 'white'
     end

-    @blocks.each {|block| block.draw }
+    @placed_blocks.each {|block| block.draw }
     @image.write("example.jpg")
   end
 end
enable to calculate blf stable point candidates