Class: CTioga2::Graphics::Types::BaseCoordinate
- Defined in:
- lib/ctioga2/graphics/types/point.rb
Overview
This class performs the same function as Dimension, except that it represents a coordinate. As such, its #value only makes sense as a page, frame or figure coordinate
Constant Summary
Constants inherited from Dimension
Dimension::DimensionConversion, Dimension::DimensionRegexp
Instance Attribute Summary
Attributes inherited from Dimension
Class Method Summary collapse
-
.from_text(text, orientation, default = :figure) ⇒ Object
Creates a BaseCoordinate object from a text specification.
Instance Method Summary collapse
-
#initialize(type, value, orientation) ⇒ BaseCoordinate
constructor
Creates a BaseCoordinate object of the given type, the given value and oriented along the given orientation.
-
#to_figure(t, orientation = nil) ⇒ Object
Converts the Dimension to the figure coordinates of the current figure in t.
-
#to_frame(t, orientation = nil) ⇒ Object
Converts the Dimension to the frame coordinates of the current frame in t.
Methods inherited from Dimension
#replace_if_bigger, #to_text_height
Constructor Details
#initialize(type, value, orientation) ⇒ BaseCoordinate
Creates a BaseCoordinate object of the given type, the given value and oriented along the given orientation
32 33 34 |
# File 'lib/ctioga2/graphics/types/point.rb', line 32 def initialize(type, value, orientation) super end |
Class Method Details
.from_text(text, orientation, default = :figure) ⇒ Object
Creates a BaseCoordinate object from a text specification. Takes the same argument as Dimension.from_text, except that purely dimension #type won’t be accepted.
64 65 66 67 68 69 70 |
# File 'lib/ctioga2/graphics/types/point.rb', line 64 def self.from_text(text, orientation, default = :figure) dim = Dimension.from_text(text, orientation, default) if dim.type == :bp or dim.type == :dy raise "Does not accept dimensions only for coordinates" end return BaseCoordinate.new(dim.type, dim.value, dim.orientation) end |
Instance Method Details
#to_figure(t, orientation = nil) ⇒ Object
Converts the Dimension to the figure coordinates of the current figure in t.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ctioga2/graphics/types/point.rb', line 38 def to_figure(t, orientation = nil) orientation ||= @orientation case @type when :frame return t.send("convert_frame_to_figure_#{orientation}", @value) when :page return t.send("convert_page_to_figure_#{orientation}", @value) when :figure return @value else raise "Invalid type for BaseCoordinate: #{@type}" end end |
#to_frame(t, orientation = nil) ⇒ Object
Converts the Dimension to the frame coordinates of the current frame in t.
54 55 56 57 58 |
# File 'lib/ctioga2/graphics/types/point.rb', line 54 def to_frame(t, orientation = nil) orientation ||= @orientation return t.send("convert_figure_to_frame_#{orientation}", to_figure(t, orientation)) end |