'use strict';

var BoundingRect = require('../../../../../../zrender@6.0.0/node_modules/zrender/lib/core/BoundingRect.js');
var cursorHelper = require('./cursorHelper.js');
var graphic = require('../../util/graphic.js');

function makeRectPanelClipPath(rect) {
  rect = normalizeRect(rect);
  return function (localPoints) {
    return graphic.clipPointsByRect(localPoints, rect);
  };
}
function makeLinearBrushOtherExtent(rect, specifiedXYIndex) {
  rect = normalizeRect(rect);
  return function (xyIndex) {
    var idx = specifiedXYIndex != null ? specifiedXYIndex : xyIndex;
    var brushWidth = idx ? rect.width : rect.height;
    var base = idx ? rect.x : rect.y;
    return [base, base + (brushWidth || 0)];
  };
}
function makeRectIsTargetByCursor(rect, api, targetModel) {
  var boundingRect = normalizeRect(rect);
  return function (e, localCursorPoint) {
    return boundingRect.contain(localCursorPoint[0], localCursorPoint[1]) && !cursorHelper.onIrrelevantElement(e, api, targetModel);
  };
}
// Consider width/height is negative.
function normalizeRect(rect) {
  return BoundingRect.default.create(rect);
}

exports.makeLinearBrushOtherExtent = makeLinearBrushOtherExtent;
exports.makeRectIsTargetByCursor = makeRectIsTargetByCursor;
exports.makeRectPanelClipPath = makeRectPanelClipPath;
