Class: DataPoint
- Inherits:
-
Object
- Object
- DataPoint
- Defined in:
- lib/technical_graph/data_point.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(h = { :x => 0, :y => 0 }) ⇒ DataPoint
constructor
A new instance of DataPoint.
- #x ⇒ Object
- #x=(_x) ⇒ Object
- #x_distance(other_dp) ⇒ Object
- #y ⇒ Object
- #y=(_y) ⇒ Object
- #y_distance(other_dp) ⇒ Object
Constructor Details
#initialize(h = { :x => 0, :y => 0 }) ⇒ DataPoint
Returns a new instance of DataPoint.
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/technical_graph/data_point.rb', line 3 def initialize(h={ :x => 0, :y => 0 }) if h.kind_of? Hash @x = h[:x] @y = h[:y] end if h.kind_of? DataPoint @x = h.x @y = h.y end end |
Class Method Details
.xy(_x, _y) ⇒ Object
14 15 16 |
# File 'lib/technical_graph/data_point.rb', line 14 def self.xy(_x, _y) DataPoint.new({ :x=>_x, :y=>_y }) end |
Instance Method Details
#x ⇒ Object
26 27 28 |
# File 'lib/technical_graph/data_point.rb', line 26 def x @x end |
#x=(_x) ⇒ Object
34 35 36 |
# File 'lib/technical_graph/data_point.rb', line 34 def x=(_x) @x = _x end |
#x_distance(other_dp) ⇒ Object
18 19 20 |
# File 'lib/technical_graph/data_point.rb', line 18 def x_distance(other_dp) return (self.x - other_dp.x).abs end |
#y ⇒ Object
30 31 32 |
# File 'lib/technical_graph/data_point.rb', line 30 def y @y end |
#y=(_y) ⇒ Object
38 39 40 |
# File 'lib/technical_graph/data_point.rb', line 38 def y=(_y) @y = _y end |
#y_distance(other_dp) ⇒ Object
22 23 24 |
# File 'lib/technical_graph/data_point.rb', line 22 def y_distance(other_dp) return (self.y - other_dp.y).abs end |