/**
 * DevExtreme (cjs/viz/utils.js)
 * Version: 23.1.10 (build 24175-0109)
 * Build date: Sun Jun 23 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";
exports.prepareSegmentRectPoints = exports.floorCanvasDimensions = exports.areCanvasesDifferent = void 0;
Object.defineProperty(exports, "refreshPaths", {
    enumerable: true,
    get: function() {
        return _renderer.refreshPaths
    }
});
var _renderer = require("./core/renderers/renderer");
var _iterator = require("../core/utils/iterator");

function _extends() {
    _extends = Object.assign ? Object.assign.bind() : function(target) {
        for (var i = 1; i < arguments.length; i++) {
            var source = arguments[i];
            for (var key in source) {
                if (Object.prototype.hasOwnProperty.call(source, key)) {
                    target[key] = source[key]
                }
            }
        }
        return target
    };
    return _extends.apply(this, arguments)
}
var floor = Math.floor;
var prepareSegmentRectPoints = function(left, top, width, height, borderOptions) {
    var maxSW = ~~((width < height ? width : height) / 2);
    var sw = borderOptions.width || 0;
    var newSW = sw < maxSW ? sw : maxSW;
    left += newSW / 2;
    top += newSW / 2;
    width -= newSW;
    height -= newSW;
    var right = left + width;
    var bottom = top + height;
    var points = [];
    var segments = [];
    var segmentSequence;
    var visiblyOpt = 0;
    var prevSegmentVisibility = 0;
    var allSegment = {
        top: [
            [left, top],
            [right, top]
        ],
        right: [
            [right, top],
            [right, bottom]
        ],
        bottom: [
            [right, bottom],
            [left, bottom]
        ],
        left: [
            [left, bottom],
            [left, top]
        ]
    };
    (0, _iterator.each)(allSegment, (function(seg) {
        var visibility = !!borderOptions[seg];
        visiblyOpt = 2 * visiblyOpt + ~~visibility
    }));
    switch (visiblyOpt) {
        case 13:
        case 9:
            segmentSequence = ["left", "top", "right", "bottom"];
            break;
        case 11:
            segmentSequence = ["bottom", "left", "top", "right"];
            break;
        default:
            segmentSequence = ["top", "right", "bottom", "left"]
    }(0, _iterator.each)(segmentSequence, (function(_, seg) {
        var segmentVisibility = !!borderOptions[seg];
        if (!prevSegmentVisibility && segments.length) {
            points.push(segments);
            segments = []
        }
        if (segmentVisibility) {
            (0, _iterator.each)(allSegment[seg].slice(prevSegmentVisibility), (function(_, segment) {
                segments = segments.concat(segment)
            }))
        }
        prevSegmentVisibility = ~~segmentVisibility
    }));
    segments.length && points.push(segments);
    1 === points.length && (points = points[0]);
    return {
        points: points,
        pathType: 15 === visiblyOpt ? "area" : "line"
    }
};
exports.prepareSegmentRectPoints = prepareSegmentRectPoints;
var areCanvasesDifferent = function(canvas1, canvas2) {
    var sizeLessThreshold = ["width", "height"].every((function(key) {
        return Math.abs(canvas1[key] - canvas2[key]) < 1
    }));
    var canvasCoordsIsEqual = ["left", "right", "top", "bottom"].every((function(key) {
        return canvas1[key] === canvas2[key]
    }));
    return !(sizeLessThreshold && canvasCoordsIsEqual)
};
exports.areCanvasesDifferent = areCanvasesDifferent;
var floorCanvasDimensions = function(canvas) {
    return _extends({}, canvas, {
        height: floor(canvas.height),
        width: floor(canvas.width)
    })
};
exports.floorCanvasDimensions = floorCanvasDimensions;
