Class: CTioga2::Graphics::Types::PointBasedBox

Inherits:
Box
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Box

#classes, #to_frame_margins, #within_frames

Constructor Details

#initialize(point, width, height) ⇒ PointBasedBox

Creates a new PointBasedBox at the given point, with the given width and height.



154
155
156
157
158
# File 'lib/ctioga2/graphics/types/boxes.rb', line 154

def initialize(point, width, height)
  @point = point
  @width = width
  @height = height
end

Instance Attribute Details

#heightObject

The height



150
151
152
# File 'lib/ctioga2/graphics/types/boxes.rb', line 150

def height
  @height
end

#pointObject

The aligned point of the box:



144
145
146
# File 'lib/ctioga2/graphics/types/boxes.rb', line 144

def point
  @point
end

#widthObject

The width



147
148
149
# File 'lib/ctioga2/graphics/types/boxes.rb', line 147

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



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/ctioga2/graphics/types/boxes.rb', line 170

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.



187
188
189
190
191
192
# File 'lib/ctioga2/graphics/types/boxes.rb', line 187

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