Class: CTioga2::Graphics::Types::Point
- Inherits:
-
Object
- Object
- CTioga2::Graphics::Types::Point
- Defined in:
- lib/ctioga2/graphics/types/point.rb
Overview
Represents a given Point for Tioga. Its coordinates are BaseCoordinate objects.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#x ⇒ Object
The X coordinate, a BaseCoordinate object.
-
#y ⇒ Object
The Y coordinate, a BaseCoordinate object.
Class Method Summary collapse
-
.from_text(text, default = :figure) ⇒ Object
Creates a Point object from a text specification.
Instance Method Summary collapse
-
#initialize(x = nil, y = nil, type = :figure) ⇒ Point
constructor
Creates a Point with the given coordinates (of type type, see BaseCoordinate for more information).
-
#to_figure_xy(t) ⇒ Object
Converts the point to figure coordinates.
-
#to_frame_xy(t) ⇒ Object
Converts the points to frame coordinates.
Constructor Details
#initialize(x = nil, y = nil, type = :figure) ⇒ Point
Creates a Point with the given coordinates (of type type, see BaseCoordinate for more information).
87 88 89 90 91 92 |
# File 'lib/ctioga2/graphics/types/point.rb', line 87 def initialize(x = nil, y = nil, type = :figure) if x && y @x = BaseCoordinate.new(type, x, :x) @y = BaseCoordinate.new(type, y, :y) end end |
Instance Attribute Details
#x ⇒ Object
The X coordinate, a BaseCoordinate object
80 81 82 |
# File 'lib/ctioga2/graphics/types/point.rb', line 80 def x @x end |
#y ⇒ Object
The Y coordinate, a BaseCoordinate object
83 84 85 |
# File 'lib/ctioga2/graphics/types/point.rb', line 83 def y @y end |
Class Method Details
.from_text(text, default = :figure) ⇒ Object
Creates a Point object from a text specification. Splits up the text at a comma and
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/ctioga2/graphics/types/point.rb', line 106 def self.from_text(text, default = :figure) vals = text.split(/\s*,\s*/) if vals.size != 2 raise "Should really have two values: #{text}" end coord = Point.new coord.x = BaseCoordinate.from_text(vals[0], :x, default) coord.y = BaseCoordinate.from_text(vals[1], :y, default) return coord end |
Instance Method Details
#to_figure_xy(t) ⇒ Object
Converts the point to figure coordinates.
95 96 97 |
# File 'lib/ctioga2/graphics/types/point.rb', line 95 def to_figure_xy(t) return [@x.to_figure(t), @y.to_figure(t)] end |
#to_frame_xy(t) ⇒ Object
Converts the points to frame coordinates.
100 101 102 |
# File 'lib/ctioga2/graphics/types/point.rb', line 100 def to_frame_xy(t) return [@x.to_frame(t), @y.to_frame(t)] end |