lib/sqed/boundaries.rb in sqed-0.0.4 vs lib/sqed/boundaries.rb in sqed-0.1.0

- old
+ new

@@ -10,17 +10,19 @@ # In the pattern integer => [x1,y1, width, height] (ImageMagick convention rectangle descriptors) # e.g. # 0 => [10,10,40,40] attr_reader :coordinates - # An Sqed::Config::EXTRACTION_PATTERN layout + # A symbol from Sqed::Config::LAYOUTS.keys + # :right_t attr_accessor :layout - # Whether or not the last method to populate this object passed fully + # Boolean, whether or not the last method to populate this object passed fully attr_accessor :complete def initialize(layout = nil) + raise 'unrecognized layout' if layout && !SqedConfig::LAYOUTS.include?(layout) @complete = false @layout = layout @coordinates = {} initialize_coordinates if !@layout.nil? @@ -33,15 +35,16 @@ end def offset(boundary) b = Sqed::Boundaries.new() # the idea here is to create a deep copy of self, offsetting by boundary as we go (0..self.coordinates.length - 1).each do |i| - b.coordinates[i] = [] # create the instance of the i-th coordinate, then populate it - b.coordinates[i][0] = self.x_for(i) + boundary.x_for(0) - b.coordinates[i][1] = self.y_for(i) + boundary.y_for(0) - b.coordinates[i][2] = self.width_for(i) - b.coordinates[i][3] = self.height_for(i) + b.set(i, + [(self.x_for(i) + boundary.x_for(0)), + (self.y_for(i) + boundary.y_for(0)), + self.width_for(i), + self.height_for(i)] + ) end b.complete = self.complete b end @@ -73,7 +76,19 @@ end def height_for(index) @coordinates[index][3] end + + def set(index, coordinates) + @coordinates[index] = coordinates + end + + def populated? + @coordinates.each do |c| + return false if c[0].nil? + end + true + end + end