<commit_before>
Utils = require "../Utils"

{Defaults}   = require "../Defaults"
{Simulator} = require "../Simulator"

{SpringSimulator} = require "./SpringSimulator"
{FrictionSimulator} = require "./FrictionSimulator"

class exports.MomentumBounceSimulator extends Simulator

	setup: (options) ->

		@options = Defaults.getDefaults("MomentumBounceSimulator", options)
		@options = _.defaults options,
			velocity: 0
			position: 0
			min: 0
			max: 0

		@_frictionSimulator = new FrictionSimulator
			friction: @options.momentum.friction
			tolerance: @options.momentum.tolerance
			velocity: @options.velocity
			position: @options.position

		@_springSimulator = new SpringSimulator
			tension: @options.bounce.tension
			friction: @options.bounce.friction
			tolerance: @options.bounce.tolerance
			velocity: @options.velocity
			position: @options.position

		@_state =
			x: @options.position
			v: @options.velocity

		@_useSpring = false

	next: (delta) ->

		if @_useSpring
			@_state = @_springSimulator.next(delta)
		else
			@_state = @_frictionSimulator.next(delta)
			@_tryTransitionToSpring(@_state)

		return @_state

	finished: =>

		if @_useSpring
		  @_springSimulator.finished()
		else
		  @_frictionSimulator.finished()

	setState: (state) ->

		@_state = 
			x: state.x
			v: state.v

		@_frictionSimulator.setState(@_state)
		
		if @_isValidState()
			@_tryTransitionToSpring()
		else
			bound = @options.min if @_state.x <= @options.min
			bound = @options.max if @_state.x >= @options.max
			@_transitionToSpring(bound)

	# If the position is outside the min and max bounds, and traveling
	# further away, then transition from friction to spring simulation
	_tryTransitionToSpring: (force) ->

		belowMinWithVelocity = @_state.x < @options.min && @_state.v <= 0
		aboveMaxWithVelocity = @_state.x > @options.max && @_state.v >= 0
		<commit_msg>Cleanup<commit_after>
Utils = require "../Utils"

{Defaults}   = require "../Defaults"
{Simulator} = require "../Simulator"

{SpringSimulator} = require "./SpringSimulator"
{FrictionSimulator} = require "./FrictionSimulator"

class exports.MomentumBounceSimulator extends Simulator

	setup: (options) ->

		@options = Defaults.getDefaults("MomentumBounceSimulator", options)
		@options = _.defaults options,
			velocity: 0
			position: 0
			min: 0
			max: 0

		@_frictionSimulator = new FrictionSimulator
			friction: @options.momentum.friction
			tolerance: @options.momentum.tolerance
			velocity: @options.velocity
			position: @options.position

		@_springSimulator = new SpringSimulator
			tension: @options.bounce.tension
			friction: @options.bounce.friction
			tolerance: @options.bounce.tolerance
			velocity: @options.velocity
			position: @options.position

		@_state =
			x: @options.position
			v: @options.velocity

		@_useSpring = false

	next: (delta) ->

		if @_useSpring
			@_state = @_springSimulator.next(delta)
		else
			@_state = @_frictionSimulator.next(delta)
			@_tryTransitionToSpring(@_state)

		return @_state

	finished: =>
		return @_springSimulator.finished() if @_useSpring
		return @_frictionSimulator.finished()

	setState: (state) ->

		@_state = 
			x: state.x
			v: state.v

		@_frictionSimulator.setState(@_state)
		
		if @_isValidState()
			@_tryTransitionToSpring()
		else
			bound = @options.min if @_state.x <= @options.min
			bound = @options.max if @_state.x >= @options.max
			@_transitionToSpring(bound)

	# If the position is outside the min and max bounds, and traveling
	# further away, then transition from friction to spring simulation
	_tryTransitionToSpring: (force) ->

		belowMinWithVelocity = @_state.x < @options.min && @_state.v <= 0
		aboveMaxWithVelocity = @_state.x > @options.max && @_state.v >= 0
		
{'fraction_non_alphanumeric': 0.11689008042895442, 'fraction_numerical': 0.0032171581769436996, 'mean_word_length': 3.994645247657296, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4256838', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1205, 'n_words': 283}