var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
export var buildPolygonFromVertices = function (vertices, options) {
    return new google.maps.Polygon(__assign({ paths: __spreadArray([], vertices, true), map: null }, options));
};
export var serializeRing = function (vertices) {
    return vertices.map(function (v) { return [v.lat(), v.lng()]; });
};
export var validateRing = function (vertices) {
    var _a;
    return ((_a = vertices === null || vertices === void 0 ? void 0 : vertices.length) !== null && _a !== void 0 ? _a : 0) >= 3;
};
/** Drops the last vertex when it duplicates the previous (e.g. double-click emits an extra click at the same lat/lng). */
export var dedupeTrailingDuplicateVertex = function (vertices) {
    var out = __spreadArray([], vertices, true);
    if (out.length < 2) {
        return out;
    }
    var last = out[out.length - 1];
    var prev = out[out.length - 2];
    if (last && prev && last.equals(prev)) {
        out.pop();
    }
    return out;
};
