Class: CTioga2::Graphics::Types::PointBasedBox
- Defined in:
- lib/ctioga2/graphics/types/boxes.rb
Overview
A box defined by an AlignedPoint and two dimensions
Constant Summary collapse
- PointBasedBoxRE =
A well formed point-based box must match the following regular expression.
/^\s*(.*):([^,]+)(?:,\s*(.*))?$/
Instance Attribute Summary collapse
-
#height ⇒ Object
The height.
-
#point ⇒ Object
The aligned point of the box:.
-
#width ⇒ Object
The width.
Class Method Summary collapse
-
.from_text(text, default = :frame) ⇒ Object
Returns a new PointBasedBox object based on the text specification, which reads:.
Instance Method Summary collapse
-
#initialize(point, width, height) ⇒ PointBasedBox
constructor
Creates a new PointBasedBox at the given point, with the given width and height.
-
#to_frame_coordinates(t) ⇒ Object
Returns the frame coordinates of the box.
Methods inherited from Box
Constructor Details
#initialize(point, width, height) ⇒ PointBasedBox
Creates a new PointBasedBox at the given point, with the given width and height.
112 113 114 115 116 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 112 def initialize(point, width, height) @point = point @width = width @height = height end |
Instance Attribute Details
#height ⇒ Object
The height
108 109 110 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 108 def height @height end |
#point ⇒ Object
The aligned point of the box:
102 103 104 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 102 def point @point end |
#width ⇒ Object
The width
105 106 107 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 105 def width @width end |
Class Method Details
.from_text(text, default = :frame) ⇒ Object
Returns a new PointBasedBox object based on the text specification, which reads:
aligned_point:w(,h)
The default holds for point and dimensions
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 128 def self.from_text(text, default = :frame) if text =~ PointBasedBoxRE po,w,h = $1,$2,$3 point = AlignedPoint.from_text(po, default) width = Dimension.from_text(w, :x, default) if h height = Dimension.from_text(h, :y, default) else height = width.dup end return PointBasedBox.new(point, width, height) else raise "#{text} is not a point-based box." end end |
Instance Method Details
#to_frame_coordinates(t) ⇒ Object
Returns the frame coordinates of the box.
145 146 147 148 149 150 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 145 def to_frame_coordinates(t) dx = @width.to_figure(t, :x) dy = @height.to_figure(t, :y) a = @point.to_frame_coordinates(t, dx, dy) return @point.to_frame_coordinates(t, dx, dy) end |