Class: Archimate::DataModel::Bounds

Inherits:
Object
  • Object
show all
Includes:
Comparison
Defined in:
lib/archimate/data_model/bounds.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Comparison

#==, #[], #dig, #each, #hash, included, #pretty_print, #to_h

Constructor Details

#initialize(x: nil, y: nil, width:, height:) ⇒ Bounds

Returns a new instance of Bounds.



25
26
27
28
29
30
31
32
# File 'lib/archimate/data_model/bounds.rb', line 25

def initialize(x: nil, y: nil, width:, height:)
  raise "Width expected" unless width
  raise "Height expected" unless height
  @x = x.nil? ? nil : x.to_f
  @y = y.nil? ? nil : y.to_f
  @width = width.to_f
  @height = height.to_f
end

Instance Attribute Details

#heightFloat (readonly)

Returns:

  • (Float)


19
# File 'lib/archimate/data_model/bounds.rb', line 19

model_attr :height

#widthFloat (readonly)

Returns:

  • (Float)


16
# File 'lib/archimate/data_model/bounds.rb', line 16

model_attr :width

#xFloat, NilClass (readonly)

Returns:

  • (Float, NilClass)


10
# File 'lib/archimate/data_model/bounds.rb', line 10

model_attr :x

#yFloat, NilClass (readonly)

Returns:

  • (Float, NilClass)


13
# File 'lib/archimate/data_model/bounds.rb', line 13

model_attr :y

Class Method Details

.zeroObject



21
22
23
# File 'lib/archimate/data_model/bounds.rb', line 21

def self.zero
  Archimate::DataModel::Bounds.new(x: 0, y: 0, width: 0, height: 0)
end

Instance Method Details

#bottomObject



50
51
52
# File 'lib/archimate/data_model/bounds.rb', line 50

def bottom
  top + height
end

#centerObject



62
63
64
65
66
67
68
69
# File 'lib/archimate/data_model/bounds.rb', line 62

def center
  DataModel::Bounds.new(
    x: left + width / 2.0,
    y: top + height / 2.0,
    width: 0,
    height: 0
  )
end

#inside?(other) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
94
95
96
# File 'lib/archimate/data_model/bounds.rb', line 91

def inside?(other)
  left > other.left &&
    right < other.right &&
    top > other.top &&
    bottom < other.bottom
end

#is_above?(other) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/archimate/data_model/bounds.rb', line 71

def is_above?(other)
  bottom < other.top
end

#is_below?(other) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/archimate/data_model/bounds.rb', line 75

def is_below?(other)
  top > other.bottom
end

#is_left_of?(other) ⇒ Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/archimate/data_model/bounds.rb', line 83

def is_left_of?(other)
  right < other.left
end

#is_right_of?(other) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/archimate/data_model/bounds.rb', line 79

def is_right_of?(other)
  left > other.right
end

#leftObject



58
59
60
# File 'lib/archimate/data_model/bounds.rb', line 58

def left
  x || 0
end

#reduced_by(val) ⇒ Object



87
88
89
# File 'lib/archimate/data_model/bounds.rb', line 87

def reduced_by(val)
  Bounds.new(x: left + val, y: top + val, width: width - val * 2, height: height - val * 2)
end

#rightObject



54
55
56
# File 'lib/archimate/data_model/bounds.rb', line 54

def right
  left + width
end

#to_sObject



34
35
36
# File 'lib/archimate/data_model/bounds.rb', line 34

def to_s
  "Bounds(x: #{x}, y: #{y}, width: #{width}, height: #{height})"
end

#topObject



46
47
48
# File 'lib/archimate/data_model/bounds.rb', line 46

def top
  y || 0
end

#x_rangeObject



38
39
40
# File 'lib/archimate/data_model/bounds.rb', line 38

def x_range
  Range.new(left, right)
end

#y_rangeObject



42
43
44
# File 'lib/archimate/data_model/bounds.rb', line 42

def y_range
  Range.new(top, bottom)
end