Class: GeometricDistance
- Inherits:
-
Struct
- Object
- Struct
- GeometricDistance
- Defined in:
- lib/flash_math/modules/geometry/geometric_distance.rb
Instance Attribute Summary collapse
-
#point1 ⇒ Object
Returns the value of attribute point1.
-
#point2 ⇒ Object
Returns the value of attribute point2.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#point1 ⇒ Object
Returns the value of attribute point1
1 2 3 |
# File 'lib/flash_math/modules/geometry/geometric_distance.rb', line 1 def point1 @point1 end |
#point2 ⇒ Object
Returns the value of attribute 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
#distance ⇒ Object
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 |
#midpoint ⇒ Object
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_distance ⇒ Object
16 17 18 |
# File 'lib/flash_math/modules/geometry/geometric_distance.rb', line 16 def midpoint_distance distance / 2 end |