class IiifGoogleCv::BoundingBox

Basic BoundingBox operations/parsing

Attributes

maxx[R]
maxy[R]
minx[R]
miny[R]
scale_factor[R]

Public Class Methods

from_gcv_a(bounds_array, scale_factor = 1.0) click to toggle source
# File lib/iiif_google_cv/bounding_box.rb, line 15
def self.from_gcv_a(bounds_array, scale_factor = 1.0)
  i = new(999_999_999, 999_999_999, -999_999_999, -999_999_999, scale_factor: scale_factor)
  bounds_array.each do |vertex|
    i.check_and_set_bounds(vertex)
  end
  i
end
new(minx, miny, maxx, maxy, scale_factor: 1.0) click to toggle source
# File lib/iiif_google_cv/bounding_box.rb, line 7
def initialize(minx, miny, maxx, maxy, scale_factor: 1.0)
  @minx = minx
  @miny = miny
  @maxx = maxx
  @maxy = maxy
  @scale_factor = scale_factor
end

Public Instance Methods

check_and_set_bounds(vertex) click to toggle source
# File lib/iiif_google_cv/bounding_box.rb, line 23
def check_and_set_bounds(vertex)
  @maxx = vertex.x / scale_factor if vertex.x / scale_factor > maxx
  @maxy = vertex.y / scale_factor if vertex.y / scale_factor > maxy
  @minx = vertex.x / scale_factor if vertex.x / scale_factor < minx
  @miny = vertex.y / scale_factor if vertex.y / scale_factor < miny
end
height() click to toggle source
# File lib/iiif_google_cv/bounding_box.rb, line 34
def height
  maxy - miny
end
to_xywh() click to toggle source
# File lib/iiif_google_cv/bounding_box.rb, line 38
def to_xywh
  "#{minx.to_i},#{miny.to_i},#{width.to_i},#{height.to_i}"
end
width() click to toggle source
# File lib/iiif_google_cv/bounding_box.rb, line 30
def width
  maxx - minx
end