import { __extends } from "tslib";
import { SnapMode } from "../../Types";
import { SnapMatch } from "./SnapMatch";
/** Class that implements the weak snap match behaviour */
var WeakSnapMatch = /** @class */ (function (_super) {
    __extends(WeakSnapMatch, _super);
    /**
     * The constructor of the Weak Snap Match class. Determine if the two points are a core match
     * @param first the first point
     * @param second the second point
     * @param firstId the first id
     * @param secondId the second id
     */
    function WeakSnapMatch(first, second, firstId, secondId) {
        var _this = _super.call(this, first, second, firstId, secondId) || this;
        _this.snapMode = SnapMode.Weak;
        _this.isCoreMatch = WeakSnapMatch.isCoreMatch(first, second);
        _this.adaptRotationDifference();
        return _this;
    }
    /** Adapts the rotation difference. Because we are looking for a weak snap, the rotations of the objects do not have to match.
     *  The possible rotation differences (after the snap transformation has been applied to the first point) at the end are :
     *  0, PI/2, PI, 3* PI / 2
     */
    WeakSnapMatch.prototype.adaptRotationDifference = function () {
        // if this.rotationDifference is negative, the modulus operator will return a negative number.
        // to get the positive remainder of the division, add the dividend and take the modulus again
        this.rotationDifference =
            ((this.rotationDifference % (0.5 * Math.PI)) + 0.5 * Math.PI) %
                (0.5 * Math.PI);
        // make sure that rotation occurs between -0.25 * PI and 0.25 * PI
        if (this.rotationDifference > 0.25 * Math.PI) {
            this.rotationDifference -= 0.5 * Math.PI;
        }
    };
    /**
     * @returns true if the points are a core match and the distance constraints are met
     */
    WeakSnapMatch.prototype.isValid = function () {
        if (!this.isCoreMatch) {
            return false;
        }
        if (this.distance > SnapMatch.maxDistance) {
            return false;
        }
        return true;
    };
    /**
     * Check if the two points are a core match, e.g. snap <-> snap
     * @param first the first point
     * @param second the second point
     */
    WeakSnapMatch.isCoreMatch = function (first, second) {
        return first.type === "Snap" && second.type === "Snap";
    };
    return WeakSnapMatch;
}(SnapMatch));
export { WeakSnapMatch };
