import Quaternion from "../../../../../core/geom/Quaternion.js";
import Vector3 from "../../../../../core/geom/Vector3.js";

class ClingToTerrain {
    /**
     * @type {boolean}
     */
    normalAlign = false;
    /**
     * Used internally for caching updates
     * @type {Vector3}
     */
    __lastPosition = new Vector3(0, 0, 0);
    /**
     *
     * @type {Quaternion}
     */
    __lastRotation = new Quaternion(0, 0, 0, 1);

    /**
     * Speed in Rad/s (Radians/second) by which rotation can change
     * @type {number}
     */
    rotationSpeed = 3;

    /**
     *
     * @param {ClingToTerrain} other
     * @returns {boolean}
     */
    equals(other) {
        return this.normalAlign === other.normalAlign
            && this.rotationSpeed === other.rotationSpeed;
    }

    /**
     *
     * @returns {number}
     */
    hash() {
        return this.normalAlign ? 1 : 0;
    }

    toJSON() {
        return {
            normalAlign: this.normalAlign,
            rotationSpeed: this.rotationSpeed
        };
    }

    fromJSON(
        {
            normalAlign = false,
            rotationSpeed = Number.POSITIVE_INFINITY
        }
    ) {
        this.normalAlign = normalAlign;
        this.rotationSpeed = rotationSpeed;
    }

    /**
     *
     * @param json
     * @returns {ClingToTerrain}
     */
    static fromJSON(json) {
        const r = new ClingToTerrain();

        r.fromJSON(json);

        return r;
    }
}

ClingToTerrain.typeName = "ClingToTerrain";


export default ClingToTerrain;


