Flash Math

Flash Validators is a collection of advance math modules.
Currently supported calculations: geometry and statistics.
Installation
Add this line to your application's Gemfile:
gem 'flash_math'
And then execute:
$ bundle
Or install it yourself as:
$ gem install flash_math
Usage
Geometry
####Geometrical Point:####
Use the following methods to generate geometical point:
GeometricPoint.new(x, y)
and GeometricPoint.new_by_array(array)
Use the following methods to generate geometical point data:
advance_by(vector)
and to_vector
geo_point = GeometricPoint.new(1, 2)
geo_vector = GeometricVector.new(2, -1)
geo_point.x
geo_point.2
geo_point.advance_by(geo_vector)
####Geometrical Vector:####
Use the following methods to generate geometical vector:
GeometricVector.new(x, y)
and GeometricVector.new_by_array(array)
Use the following methods to generate geometical vector data:
modulus
, collinear_with?(vector)
, cross_product(vector)
, and scalar_product(vector)
geo_vector1 = GeometricVector.new(1, 2)
geo_vector2 = GeometricVector.new(2, 4)
geo_vector1.x
geo_vector1.y
geo_vector1.modulus
geo_vector1.collinear_with?(geo_vector2)
geo_vector1.cross_product(geo_vector2)
geo_vector1.scalar_product(geo_vector2)
####Geometrical Distance:####
Use the following method to generate geometical distance:
GeometricDistance.new(x, y)
and GeometricDistance.new_by_arrays(array)
Use the following methods to generate geometical distance data:
distance
, midpoint
, and midpoint_distance
geo_distance = GeometricalDistance.new_by_array([1, 1], [2, 4])
geo_distance.distance
geo_distance.midpoint_distance
geo_distance.midpoint
####Geometrical Line:####
Use the following method to generate geometical line:
GeometricLine.new(point1, point2)
and GeometricLine.new_by_arrays(point1, point2)
Use the following methods to generate geometical line data:
angel_to
, distance_to
, horizontal?
, vertical?
, intersect_x
, parallel_to?
, slope
, x_intercept
, and y_intercept
geo_line1 = GeometricLine.new_by_arrays([0, 0], [1, 1])
geo_line2 = GeometricLine.new_by_arrays([0, 0], [1, -1])
point = GeometricPoint.new(3, 4)
geo_line1.angle_to(geo_line2)
geo_line1.distance_to(point)
geo_line1.horizontal?
geo_line1.vertical?
geo_line1.intersect_x(geo_line2)
geo_line1.parallel_to?(geo_line2)
geo_line1.slope
geo_line1.x_intercept
geo_line1.y_intercept
####Geometrical Segment:####
Use the following method to generate geometical segment:
GeometricSegment.new(point1, point2)
and GeometricSegment.new_by_arrays(point1, point2)
Use the following methods to generate geometical segment data:
bottommost_endpoint
, leftmost_endpoint
, rightmost_endpoint
, topmost_endpoint
, contains_point?
, distance_to?
, intersection_point_with
, intersects_with?
, length
, lies_on_one_line_with?
, overlaps?
, parallel_to?
, and to_vector
geo_segment1 = GeometricSegment.new_by_arrays([0, 0], [1, 1])
geo_segment2 = GeometricSegment.new_by_arrays([2, 2], [3, 3])
point = GeometricPoint.new(0, 1)
geo_segment1.bottommost_endpoint
geo_segment1.leftmost_endpoint
geo_segment1.rightmost_endpoint
geo_segment1.topmost_endpoint
geo_segment1.contains_point?(point)
geo_segment1.distance_to?(point)
geo_segment1.intersection_point_with(geo_segment2)
geo_segment1.intersects_with?(geo_segment2)
geo_segment1.length
geo_segment1.lies_on_one_line_with?(geo_segment2)
geo_segment1.overlaps?(geo_segment2)
geo_segment1.parallel_to?(geo_segment2)
geo_segment1.to_vector
####Geometrical Bounding Box:####
Use the following method to generate geometical bounding box:
GeometricBoundingBox.new(point1, point2)
and GeometricBoundingBox.new_by_arrays(point1, point2)
Use the following methods to generate geometical segment data:
contains?
and diagonal
geo_bounding_box = GeometricBoundingBox.new_by_arrays([-1, -1], [1, 1])
geo_bounding_box.contains?(GeometricPoint.new(0, 0))
####Geometrical Polygon:####
Use the following method to generate geometical polygon:
GeometricBoundingBox.new(vertices)
Use the following methods to generate geometical polygon data:
area
, bounding_box
, contains
, and edges
geo_polygon = GeometricPolygon.new([GeometricPoint.new(0,0), GeometricPoint.new(1,1), GeometricPoint.new(0,1)]).area
geo_polygon.area
geo_polygon.contains?(GeometricPoint.new(0.5, 0.5))
Statistics
####Statistical Spread:####
Use the following methods to generate the statistical spreads of an array:
mean
, median
, mean
, range
, min
, max
, percentile_from_value
, value_from_percentile
, variance
, standard_deviation
, relative_standard_deviation
, skewness
, and kurtosis
stats_spread = StatisticalSpread.new([1,1,2,3,10])
stats_spread.mean
stats_spread.median
stats_spread.mode
stats_spread.range
stats_spread.min
stats_spread.max
stats_spread.percentile_from_value(10)
stats_spread.value_from_percentile(60)
stats_spread.variance
stats_spread.standard_deviation
stats_spread.relative_standard_deviation
stats_spread.skewness
stats_spread.kurtosis
Contributing
- Fork it ( http://github.com//flash_math/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request