Sha256: 56417f12d0fa4a43915b7129158b440e1a2f8da2a63d9e896802e6e5dfbb3a43
Contents?: true
Size: 1.21 KB
Versions: 6
Compression:
Stored size: 1.21 KB
Contents
require_relative "hypersphere.rb" class Circle < HyperSphere def initialize(radius = 1, center = [0,0], pct_error = 1) super(radius, center, pct_error) end def help Circle.help end def self.help Circle.show_help_message end def area dim_check(2) Math::PI * (@radius ** 2) end def circumference dim_check(2) 2 * Math::PI * @radius end def inspect "Circle: #{equation}" end private def self.show_help_message super Zadt::ADT::show_circle_help_message end def circle_equation dim_check(2) center_point = @center.dup coord_names = ["x", "y"] center_point.coords.each_with_index do |center_coord, index| if center_coord == 0 # coord_name is fine elsif center_coord < 0 coord_names[index] = "(#{coord_names[index]} + #{-center_coord})" else coord_names[index] = "(#{coord_names[index]} - #{center_coord})" end end "#{coord_names[0]}^2 + #{coord_names[1]}^2 = #{@radius ** 2}" end def close_enough(guess, exact) range = Array.new range[0] = exact *(100.0 - @pct_error)/100.0 range[1] = exact * (100.0 + @pct_error)/100.0 guess.between?(range[0], range[1]) end end
Version data entries
6 entries across 6 versions & 1 rubygems