import '../../globals.js';
// Copyright 2017-2023, University of Colorado Boulder
/**
 * WARNING: PROTOTYPE, see https://github.com/phetsims/twixt/issues/3 before using!
 * Not fully documented or stabilized. May be deleted.
 *
 * Handles a single dimension of damped harmonic-oscillator motion (like a damped spring pulling towards the target).
 *
 * @author Jonathan Olson <jonathan.olson@colorado.edu>
 */
import TinyProperty from '../../axon/js/TinyProperty.js';
import DampedHarmonic from '../../dot/js/DampedHarmonic.js';
import optionize from '../../phet-core/js/optionize.js';
import twixt from './twixt.js';
class DampedAnimation {
    constructor(providedOptions) {
        this.timeElapsed = 0;
        const options = optionize()({
            valueProperty: new TinyProperty(0),
            velocityProperty: new TinyProperty(0),
            damping: 1,
            force: 1,
            targetValue: 0
        }, providedOptions);
        this.valueProperty = options.valueProperty;
        this.velocityProperty = options.velocityProperty;
        this._damping = options.damping;
        this._force = options.force;
        this._targetValue = options.targetValue;
        this.recompute();
    }
    /**
     * Returns the target value
     */
    get targetValue() {
        return this._targetValue;
    }
    /**
     * Change the target value that we are moving toward.
     */
    set targetValue(value) {
        this._targetValue = value;
        this.recompute();
    }
    /**
     * Returns the damping value
     */
    get damping() {
        return this._damping;
    }
    /**
     * Sets the damping value.
     */
    set damping(value) {
        this._damping = value;
        this.recompute();
    }
    /**
     * Returns the force value
     */
    get force() {
        return this._force;
    }
    /**
     * Sets the force value.
     */
    set force(value) {
        this._force = value;
        this.recompute();
    }
    /**
     * On a change, we need to recompute our harmonic (that plots out the motion to the target)
     */
    recompute() {
        this.timeElapsed = 0;
        this.harmonic = new DampedHarmonic(1, Math.sqrt(4 * this._force) * this._damping, this._force, this.valueProperty.value - this._targetValue, this.velocityProperty.value);
    }
    /**
     * Steps the animation forward in time.
     */
    step(dt) {
        this.timeElapsed += dt;
        this.valueProperty.value = this._targetValue + this.harmonic.getValue(this.timeElapsed);
        this.velocityProperty.value = this.harmonic.getDerivative(this.timeElapsed);
    }
}
twixt.register('DampedAnimation', DampedAnimation);
export default DampedAnimation;
//# sourceMappingURL=DampedAnimation.js.map