Class: Emf::Model::Geometry::Rect
- Inherits:
-
Object
- Object
- Emf::Model::Geometry::Rect
- Defined in:
- lib/emf/model/geometry/rect.rb
Instance Attribute Summary collapse
-
#bottom ⇒ Object
readonly
Returns the value of attribute bottom.
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
-
#top ⇒ Object
readonly
Returns the value of attribute top.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #contains?(point) ⇒ Boolean
- #empty? ⇒ Boolean
- #hash ⇒ Object
- #height ⇒ Object
-
#initialize(left:, top:, right:, bottom:) ⇒ Rect
constructor
A new instance of Rect.
- #inspect ⇒ Object
- #to_wire ⇒ Object
- #width ⇒ Object
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
#bottom ⇒ Object (readonly)
Returns the value of attribute bottom.
14 15 16 |
# File 'lib/emf/model/geometry/rect.rb', line 14 def bottom @bottom end |
#left ⇒ Object (readonly)
Returns the value of attribute left.
14 15 16 |
# File 'lib/emf/model/geometry/rect.rb', line 14 def left @left end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
14 15 16 |
# File 'lib/emf/model/geometry/rect.rb', line 14 def right @right end |
#top ⇒ Object (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
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
32 33 34 |
# File 'lib/emf/model/geometry/rect.rb', line 32 def empty? width <= 0 || height <= 0 end |
#hash ⇒ Object
47 48 49 |
# File 'lib/emf/model/geometry/rect.rb', line 47 def hash [self.class, left, top, right, bottom].hash end |
#height ⇒ Object
28 29 30 |
# File 'lib/emf/model/geometry/rect.rb', line 28 def height bottom - top end |
#inspect ⇒ Object
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_wire ⇒ Object
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 |
#width ⇒ Object
24 25 26 |
# File 'lib/emf/model/geometry/rect.rb', line 24 def width right - left end |