Class: GeometricDistance

Inherits:
Struct
  • Object
show all
Defined in:
lib/flash_math/modules/geometry/geometric_distance.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#point1Object

Returns the value of attribute point1

Returns:

  • (Object)

    the current value of point1



1
2
3
# File 'lib/flash_math/modules/geometry/geometric_distance.rb', line 1

def point1
  @point1
end

#point2Object

Returns the value of attribute point2

Returns:

  • (Object)

    the current value of point2



1
2
3
# File 'lib/flash_math/modules/geometry/geometric_distance.rb', line 1

def point2
  @point2
end

Class Method Details

.new_by_arrays(point1_coordinates, point2_coordinates) ⇒ Object



3
4
5
6
# File 'lib/flash_math/modules/geometry/geometric_distance.rb', line 3

def self.new_by_arrays(point1_coordinates, point2_coordinates)
  self.new(GeometricPoint.new_by_array(point1_coordinates),
           GeometricPoint.new_by_array(point2_coordinates))
end

Instance Method Details

#distanceObject



8
9
10
# File 'lib/flash_math/modules/geometry/geometric_distance.rb', line 8

def distance
  Math.hypot(point1.x - point2.x, point1.y - point2.y)
end

#midpointObject



12
13
14
# File 'lib/flash_math/modules/geometry/geometric_distance.rb', line 12

def midpoint
  [((point2.x + point1.x) / 2), ((point2.y + point1.y) / 2)]
end

#midpoint_distanceObject



16
17
18
# File 'lib/flash_math/modules/geometry/geometric_distance.rb', line 16

def midpoint_distance
  distance / 2
end