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
#*, #-@, adjust_line, #copy_from, get_angle, get_distance, make_dimension, #replace_if_bigger, #set_from_text, #to_bp, #to_dy, #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
30 31 32 |
# File 'lib/ctioga2/graphics/types/point.rb', line 30 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.
63 64 65 66 67 68 69 |
# File 'lib/ctioga2/graphics/types/point.rb', line 63 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.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ctioga2/graphics/types/point.rb', line 36 def to_figure(t, orientation = nil) orientation ||= @orientation case @type when :frame return t.send("convert_frame_to_figure_#{orientation}", @value) when :page int = t.send("convert_page_to_frame_#{orientation}", @value) return t.send("convert_frame_to_figure_#{orientation}", int) 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.
53 54 55 56 57 |
# File 'lib/ctioga2/graphics/types/point.rb', line 53 def to_frame(t, orientation = nil) orientation ||= @orientation return t.send("convert_figure_to_frame_#{orientation}", to_figure(t, orientation)) end |