Class: Lutaml::Xsd::Spa::Svg::Geometry::Box

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/xsd/spa/svg/geometry/box.rb

Overview

Immutable value object representing a rectangular box

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#heightObject (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

#widthObject (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

#xObject (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

#yObject (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_centerObject



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_leftObject



29
30
31
# File 'lib/lutaml/xsd/spa/svg/geometry/box.rb', line 29

def bottom_left
  Point.new(x, y + height)
end

#bottom_rightObject



33
34
35
# File 'lib/lutaml/xsd/spa/svg/geometry/box.rb', line 33

def bottom_right
  Point.new(x + width, y + height)
end

#centerObject



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

Returns:

  • (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_centerObject



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_centerObject



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_centerObject



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

#top_leftObject



21
22
23
# File 'lib/lutaml/xsd/spa/svg/geometry/box.rb', line 21

def top_left
  Point.new(x, y)
end

#top_rightObject



25
26
27
# File 'lib/lutaml/xsd/spa/svg/geometry/box.rb', line 25

def top_right
  Point.new(x + width, y)
end