Class: Sunniesnow::Charter::TipPointStart
- Inherits:
-
Object
- Object
- Sunniesnow::Charter::TipPointStart
- Defined in:
- lib/sscharter/charter/tip_point.rb
Overview
Note:
Internal API.
Instance Method Summary collapse
-
#check ⇒ void
Checks that the parameters passed to #initialize is one of the valid overloads.
- #get_start_placeholder(start_event) ⇒ Event
-
#initialize(x, y, relative_time = nil, relative: true, speed: nil, relative_beat: nil, beat_speed: nil) ⇒ TipPointStart
constructor
A new instance of TipPointStart.
Constructor Details
#initialize(x, y, relative_time, relative: true) ⇒ TipPointStart #initialize(x, y, speed:, relative: true) ⇒ TipPointStart #initialize(x, y, relative_beat:, relative: true) ⇒ TipPointStart #initialize(x, y, beat_speed:, relative: true) ⇒ TipPointStart
Returns a new instance of TipPointStart.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sscharter/charter/tip_point.rb', line 26 def initialize x, y, relative_time = nil, relative: true, speed: nil, relative_beat: nil, beat_speed: nil @x = x @y = y @relative_time = relative_time @relative = relative @speed = speed @relative_beat = relative_beat @beat_speed = beat_speed check end |
Instance Method Details
#check ⇒ void
This method returns an undefined value.
Checks that the parameters passed to #initialize is one of the valid overloads.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/sscharter/charter/tip_point.rb', line 40 def check if !@x.is_a?(Numeric) || !@y.is_a?(Numeric) raise ArgumentError, 'x and y must be numbers' end @x = @x.to_f @y = @y.to_f %i[@relative_time @speed @relative_beat @beat_speed].each do |key| value = instance_variable_get key next unless value raise ArgumentError, "cannot specify both #@time_key and #{key}" if @time_key @time_key = key end raise ArgumentError, "must specify one of relative_time, speed, relative_beat, beat_speed" unless @time_key end |
#get_start_placeholder(start_event) ⇒ Event
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/sscharter/charter/tip_point.rb', line 57 def get_start_placeholder start_event raise ArgumentError, "start_event is not tip-pointable" unless start_event.tip_pointable? result = Event.new :placeholder, start_event.beat, start_event.bpm_changes if @relative result[:x] = start_event[:x] + @x result[:y] = start_event[:y] + @y else result[:x] = @x result[:y] = @y end case @time_key when :@relative_time raise ArgumentError, "relative_time must be a number" unless @relative_time.is_a? Numeric raise ArgumentError, "relative_time must be non-negative" if @relative_time < 0 result.offset = -@relative_time.to_f when :@speed raise ArgumentError, "speed must be a number" unless @speed.is_a? Numeric raise ArgumentError, "speed must be positive" if @speed <= 0 result.offset = -Math.hypot(result[:x] - start_event[:x], result[:y] - start_event[:y]) / @speed when :@relative_beat raise ArgumentError, "relative_beat must be a number" unless @relative_beat.is_a? Numeric raise ArgumentError, "relative_beat must be non-negative" if @relative_beat < 0 warn "Rational is recommended over Float for relative_beat" if @relative_beat.is_a? Float result.beat -= @relative_beat.to_r when :@beat_speed raise ArgumentError, "beat_speed must be a number" unless @beat_speed.is_a? Numeric raise ArgumentError, "beat_speed must be positive" if @beat_speed <= 0 delta_beat = Math.hypot(result[:x] - start_event[:x], result[:y] - start_event[:y]) / @beat_speed result.beat -= delta_beat.to_r # a little weird, but fine end result[:tip_point] = start_event[:tip_point] result end |