"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const AttributeMatcher_1 = __importDefault(require("./AttributeMatcher"));
class RectAttributeMatcher extends AttributeMatcher_1.default {
    initialWeight;
    constructor(initialWeight) {
        super(initialWeight, 'rect');
        this.initialWeight = initialWeight;
    }
    calculateMatchScore(originalSelector, candidateSelector, _preferences) {
        if (!originalSelector.rect || !candidateSelector.rect) {
            return 0;
        }
        if (!originalSelector.screenSize || !candidateSelector.screenSize) {
            return originalSelector.rect.x === candidateSelector.rect.x &&
                originalSelector.rect.y === candidateSelector.rect.y &&
                originalSelector.rect.height === candidateSelector.rect.height &&
                originalSelector.rect.width === candidateSelector.rect.width
                ? this.weight
                : 0;
        }
        const originalTranslatedCenterX = ((originalSelector.rect.x + originalSelector.rect.width / 2) /
            originalSelector.screenSize.width) *
            candidateSelector.screenSize.width;
        const originalTranslatedCenterY = ((originalSelector.rect.y + originalSelector.rect.height / 2) /
            originalSelector.screenSize.height) *
            candidateSelector.screenSize.height;
        const candidateCenterX = candidateSelector.rect.x + candidateSelector.rect.width / 2;
        const candidateCenterY = candidateSelector.rect.y + candidateSelector.rect.height / 2;
        const distanceOnCandidateCoordinates = Math.sqrt(Math.pow(originalTranslatedCenterX - candidateCenterX, 2) +
            Math.pow(originalTranslatedCenterY - candidateCenterY, 2));
        const maxDistance = Math.sqrt(Math.pow(candidateSelector.screenSize.width, 2) +
            Math.pow(candidateSelector.screenSize.height, 2));
        const normalizedDistance = distanceOnCandidateCoordinates / maxDistance;
        const widthNormalizedDifference = Math.abs(originalSelector.rect.width / originalSelector.screenSize.width -
            candidateSelector.rect.width / candidateSelector.screenSize.width);
        const heightNormalizedDifference = Math.abs(originalSelector.rect.height / originalSelector.screenSize.height -
            candidateSelector.rect.height / candidateSelector.screenSize.height);
        const weightModifier = (1 - normalizedDistance) * 0.5 +
            (1 - widthNormalizedDifference) * 0.25 +
            (1 - heightNormalizedDifference) * 0.25;
        return this.weight * weightModifier;
    }
    adjustWeightBySpecificity(_findCandidates, _selector, _preferences) {
    }
}
exports.default = RectAttributeMatcher;
