Class: Emf::Model::Geometry::Rect

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left:, top:, right:, bottom:) ⇒ Rect

Returns a new instance of Rect.



7
8
9
10
11
12
# File 'lib/emf/model/geometry/rect.rb', line 7

def initialize(left:, top:, right:, bottom:)
  @left = left
  @top = top
  @right = right
  @bottom = bottom
end

Instance Attribute Details

#bottomObject (readonly)

Returns the value of attribute bottom.



14
15
16
# File 'lib/emf/model/geometry/rect.rb', line 14

def bottom
  @bottom
end

#leftObject (readonly)

Returns the value of attribute left.



14
15
16
# File 'lib/emf/model/geometry/rect.rb', line 14

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right.



14
15
16
# File 'lib/emf/model/geometry/rect.rb', line 14

def right
  @right
end

#topObject (readonly)

Returns the value of attribute top.



14
15
16
# File 'lib/emf/model/geometry/rect.rb', line 14

def top
  @top
end

Class Method Details

.from_wire(wire) ⇒ Object



16
17
18
# File 'lib/emf/model/geometry/rect.rb', line 16

def self.from_wire(wire)
  new(left: wire.left, top: wire.top, right: wire.right, bottom: wire.bottom)
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



40
41
42
43
44
# File 'lib/emf/model/geometry/rect.rb', line 40

def ==(other)
  other.is_a?(self.class) &&
    left == other.left && top == other.top &&
    right == other.right && bottom == other.bottom
end

#contains?(point) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/emf/model/geometry/rect.rb', line 36

def contains?(point)
  point.x.between?(left, right) && point.y.between?(top, bottom)
end

#empty?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/emf/model/geometry/rect.rb', line 32

def empty?
  width <= 0 || height <= 0
end

#hashObject



47
48
49
# File 'lib/emf/model/geometry/rect.rb', line 47

def hash
  [self.class, left, top, right, bottom].hash
end

#heightObject



28
29
30
# File 'lib/emf/model/geometry/rect.rb', line 28

def height
  bottom - top
end

#inspectObject



51
52
53
# File 'lib/emf/model/geometry/rect.rb', line 51

def inspect
  "#<#{self.class.name} left=#{left} top=#{top} right=#{right} bottom=#{bottom}>"
end

#to_wireObject



20
21
22
# File 'lib/emf/model/geometry/rect.rb', line 20

def to_wire
  Binary::Types::RectL.new(left: left, top: top, right: right, bottom: bottom)
end

#widthObject



24
25
26
# File 'lib/emf/model/geometry/rect.rb', line 24

def width
  right - left
end