Class: CTioga2::Graphics::Types::Point

Inherits:
Object
  • Object
show all
Defined in:
lib/ctioga2/graphics/types/point.rb

Overview

Represents a given Point for Tioga. Its coordinates are BaseCoordinate objects.

Direct Known Subclasses

AlignedPoint

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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).



86
87
88
89
90
91
# File 'lib/ctioga2/graphics/types/point.rb', line 86

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

#xObject

The X coordinate, a BaseCoordinate object



79
80
81
# File 'lib/ctioga2/graphics/types/point.rb', line 79

def x
  @x
end

#yObject

The Y coordinate, a BaseCoordinate object



82
83
84
# File 'lib/ctioga2/graphics/types/point.rb', line 82

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



105
106
107
108
109
110
111
112
113
114
# File 'lib/ctioga2/graphics/types/point.rb', line 105

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.



94
95
96
# File 'lib/ctioga2/graphics/types/point.rb', line 94

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.



99
100
101
# File 'lib/ctioga2/graphics/types/point.rb', line 99

def to_frame_xy(t)
  return [@x.to_frame(t), @y.to_frame(t)]
end