Class: Lutaml::Xsd::Spa::Svg::Geometry::Box
- Inherits:
-
Object
- Object
- Lutaml::Xsd::Spa::Svg::Geometry::Box
- Defined in:
- lib/lutaml/xsd/spa/svg/geometry/box.rb
Overview
Immutable value object representing a rectangular box
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #bottom_center ⇒ Object
- #bottom_left ⇒ Object
- #bottom_right ⇒ Object
- #center ⇒ Object
- #contains?(point) ⇒ Boolean
-
#initialize(x, y, width, height) ⇒ Box
constructor
A new instance of Box.
- #left_center ⇒ Object
- #right_center ⇒ Object
- #top_center ⇒ Object
- #top_left ⇒ Object
- #top_right ⇒ Object
Constructor Details
#initialize(x, y, width, height) ⇒ Box
Returns a new instance of Box.
14 15 16 17 18 19 |
# File 'lib/lutaml/xsd/spa/svg/geometry/box.rb', line 14 def initialize(x, y, width, height) @x = x.to_f @y = y.to_f @width = width.to_f @height = height.to_f end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
12 13 14 |
# File 'lib/lutaml/xsd/spa/svg/geometry/box.rb', line 12 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
12 13 14 |
# File 'lib/lutaml/xsd/spa/svg/geometry/box.rb', line 12 def width @width end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
12 13 14 |
# File 'lib/lutaml/xsd/spa/svg/geometry/box.rb', line 12 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
12 13 14 |
# File 'lib/lutaml/xsd/spa/svg/geometry/box.rb', line 12 def y @y end |
Instance Method Details
#bottom_center ⇒ Object
45 46 47 |
# File 'lib/lutaml/xsd/spa/svg/geometry/box.rb', line 45 def bottom_center Point.new(x + (width / 2.0), y + height) end |
#bottom_left ⇒ Object
29 30 31 |
# File 'lib/lutaml/xsd/spa/svg/geometry/box.rb', line 29 def bottom_left Point.new(x, y + height) end |
#bottom_right ⇒ Object
33 34 35 |
# File 'lib/lutaml/xsd/spa/svg/geometry/box.rb', line 33 def bottom_right Point.new(x + width, y + height) end |
#center ⇒ Object
37 38 39 |
# File 'lib/lutaml/xsd/spa/svg/geometry/box.rb', line 37 def center Point.new(x + (width / 2.0), y + (height / 2.0)) end |
#contains?(point) ⇒ Boolean
57 58 59 60 |
# File 'lib/lutaml/xsd/spa/svg/geometry/box.rb', line 57 def contains?(point) point.x.between?(x, x + width) && point.y >= y && point.y <= (y + height) end |
#left_center ⇒ Object
49 50 51 |
# File 'lib/lutaml/xsd/spa/svg/geometry/box.rb', line 49 def left_center Point.new(x, y + (height / 2.0)) end |
#right_center ⇒ Object
53 54 55 |
# File 'lib/lutaml/xsd/spa/svg/geometry/box.rb', line 53 def right_center Point.new(x + width, y + (height / 2.0)) end |
#top_center ⇒ Object
41 42 43 |
# File 'lib/lutaml/xsd/spa/svg/geometry/box.rb', line 41 def top_center Point.new(x + (width / 2.0), y) end |