Class: PlotStatistics::Circle
- Inherits:
-
Object
- Object
- PlotStatistics::Circle
- Defined in:
- lib/plot_statistics/circle.rb
Instance Attribute Summary collapse
-
#clam ⇒ Object
Returns the value of attribute clam.
-
#distance_from_bound ⇒ Object
Returns the value of attribute distance_from_bound.
-
#proportion_inside_plot ⇒ Object
Returns the value of attribute proportion_inside_plot.
-
#radius ⇒ Object
Returns the value of attribute radius.
Instance Method Summary collapse
- #corners_outside_circle ⇒ Object
- #estimate_proportion_inside_plot ⇒ Object
- #find_distance_from_bounds ⇒ Object
-
#initialize(params = {}) ⇒ Circle
constructor
A new instance of Circle.
- #proportion_for_one_side_out ⇒ Object
- #proportion_for_two_sides_out ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Circle
Returns a new instance of Circle.
5 6 7 8 9 10 |
# File 'lib/plot_statistics/circle.rb', line 5 def initialize(params={}) @clam = params[:clam] @radius = params[:radius].to_f @distance_from_bound = find_distance_from_bounds @proportion_inside_plot = estimate_proportion_inside_plot end |
Instance Attribute Details
#clam ⇒ Object
Returns the value of attribute clam.
3 4 5 |
# File 'lib/plot_statistics/circle.rb', line 3 def clam @clam end |
#distance_from_bound ⇒ Object
Returns the value of attribute distance_from_bound.
3 4 5 |
# File 'lib/plot_statistics/circle.rb', line 3 def distance_from_bound @distance_from_bound end |
#proportion_inside_plot ⇒ Object
Returns the value of attribute proportion_inside_plot.
3 4 5 |
# File 'lib/plot_statistics/circle.rb', line 3 def proportion_inside_plot @proportion_inside_plot end |
#radius ⇒ Object
Returns the value of attribute radius.
3 4 5 |
# File 'lib/plot_statistics/circle.rb', line 3 def radius @radius end |
Instance Method Details
#corners_outside_circle ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/plot_statistics/circle.rb', line 45 def corners_outside_circle ClamPlot::PLOT_CORNERS.map do |corner| distance = Math.sqrt((corner.first - clam.x) ** 2 + (corner.last - clam.y) ** 2) next if distance < radius distance end.compact end |
#estimate_proportion_inside_plot ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/plot_statistics/circle.rb', line 12 def estimate_proportion_inside_plot distance_from_bound.reject! {|distance| distance > radius} case distance_from_bound.size when 1 proportion_for_one_side_out when 2 proportion_for_two_sides_out else 1.0 end end |
#find_distance_from_bounds ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/plot_statistics/circle.rb', line 36 def find_distance_from_bounds [ 100 - clam.y, # distance from top 100 - clam.x, # distance from right clam.x, # distance from left clam.y # distance from bottom ] end |
#proportion_for_one_side_out ⇒ Object
24 25 26 |
# File 'lib/plot_statistics/circle.rb', line 24 def proportion_for_one_side_out 1 - Math.acos( distance_from_bound.pop / radius ) / Math::PI end |
#proportion_for_two_sides_out ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/plot_statistics/circle.rb', line 28 def proportion_for_two_sides_out if corners_outside_circle.size == 3 1 - ( Math.acos( distance_from_bound.pop / radius ) + Math.acos( distance_from_bound.pop / radius ) + Math::PI / 2 ) / (Math::PI * 2) else 1 - ( 2 * Math.acos( distance_from_bound.pop / radius ) + 2 * Math.acos( distance_from_bound.pop / radius ) ) / (Math::PI * 2) end end |