Class: BracketNotation::Geometry::Rect

Inherits:
Object
  • Object
show all
Defined in:
lib/bracket_notation/geometry/rect.rb

Overview

Rect represents a rectangle by means of origin and size fields.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(origin_or_x = Point.new, size_or_y = Size.new, width = 0, height = 0) ⇒ Rect

Initialize the new instance. If the first two parameters are a Point and a Size, they will be used as the origin and size of the node rect respectively. If not, it is assumed that they are numeric values corresponding to the new node’s origin coordinates, and they along with the optional last two parameters will be used to initialize new Point and Size objects to use for the rect.



41
42
43
44
45
46
47
48
49
# File 'lib/bracket_notation/geometry/rect.rb', line 41

def initialize(origin_or_x = Point.new, size_or_y = Size.new, width = 0, height = 0)
  if origin_or_x.kind_of? Point and size_or_y.kind_of? Size
    @origin = origin_or_x
    @size = size_or_y
  else
    @origin = Point.new(origin_or_x, size_or_y)
    @size = Size.new(width, height)
  end
end

Instance Attribute Details

#originObject (readonly)

Returns the value of attribute origin.



33
34
35
# File 'lib/bracket_notation/geometry/rect.rb', line 33

def origin
  @origin
end

#sizeObject (readonly)

Returns the value of attribute size.



33
34
35
# File 'lib/bracket_notation/geometry/rect.rb', line 33

def size
  @size
end

Instance Method Details

#==(rvalue) ⇒ Object

Test to see if two points are equal, where equality is defined as having identical origins and sizes



53
54
55
# File 'lib/bracket_notation/geometry/rect.rb', line 53

def ==(rvalue)
  @origin == rvalue.origin && @size == rvalue.size
end

#inspectObject Also known as: to_s



57
58
59
# File 'lib/bracket_notation/geometry/rect.rb', line 57

def inspect
  "{origin: #{@origin.inspect}, size: #{@size.inspect}}"
end