Class: Dieses::Geometry::Point::Mutable

Inherits:
Dieses::Geometry::Point show all
Defined in:
lib/dieses/geometry/point.rb

Instance Attribute Summary collapse

Attributes inherited from Dieses::Geometry::Point

#x, #y

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Dieses::Geometry::Point

#<=>, #approx, call, #distance, distance, #eql?, origin, #to_a, #to_h, #to_s, #translate

Constructor Details

#initialize(x, y) ⇒ Mutable

rubocop:disable Lint/MissingSuper



77
78
79
# File 'lib/dieses/geometry/point.rb', line 77

def initialize(x, y) # rubocop:disable Lint/MissingSuper
  @x, @y = x.to_f, y.to_f
end

Instance Attribute Details

#x=(value) ⇒ Object (writeonly)

Sets the attribute x

Parameters:

  • value

    the value to set the attribute x to.



75
76
77
# File 'lib/dieses/geometry/point.rb', line 75

def x=(value)
  @x = value
end

#y=(value) ⇒ Object (writeonly)

Sets the attribute y

Parameters:

  • value

    the value to set the attribute y to.



75
76
77
# File 'lib/dieses/geometry/point.rb', line 75

def y=(value)
  @y = value
end

Class Method Details

.cast(immutable_point) ⇒ Object



92
93
94
# File 'lib/dieses/geometry/point.rb', line 92

def self.cast(immutable_point)
  Mutable.new(immutable_point.x, immutable_point.y)
end

Instance Method Details

#hashObject



81
82
83
# File 'lib/dieses/geometry/point.rb', line 81

def hash
  (@hash ||= self.class.hash) ^ to_a.hash
end

#translate!(x: nil, y: nil) ⇒ Object



85
86
87
88
89
90
# File 'lib/dieses/geometry/point.rb', line 85

def translate!(x: nil, y: nil)
  tap do
    self.x += (x || 0)
    self.y += (y || 0)
  end
end