
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/


/**
 * AUTO-GENERATED FILE. DO NOT MODIFY.
 */

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { __extends } from "tslib";
/* global Float32Array */
// TODO Batch by color
import * as graphic from '../../util/graphic.js';
import smoothBezier from 'tvrender/lib/graphic/helper/smoothBezier.js';
import { getArrowPoints } from '../mineLines/util.js';
// const BOOST_SIZE_THRESHOLD = 4;
var PolyLinesPathShape = /** @class */function () {
  function PolyLinesPathShape() {}
  return PolyLinesPathShape;
}();
function drawArrow(params) {
  var lineStyle = params.lineStyle,
    path = params.path,
    polyPoints = params.polyPoints;
  if (polyPoints.length < 2) {
    return;
  }
  var lastIndex = polyPoints.length - 1;
  switch (lineStyle) {
    case 'style_arrow_left':
      {
        var points = getArrowPoints(polyPoints[1][0], polyPoints[1][1], polyPoints[0][0], polyPoints[0][1]);
        if (!points) {
          return;
        }
        var x1 = points[0],
          y1 = points[1],
          x2 = points[2],
          y2 = points[3],
          x3 = points[4],
          y3 = points[5];
        path.moveTo(x1, y1);
        path.lineTo(x2, y2);
        path.lineTo(x3, y3);
        break;
      }
    case 'style_arrow_right':
      {
        var points = getArrowPoints(polyPoints[lastIndex - 1][0], polyPoints[lastIndex - 1][1], polyPoints[lastIndex][0], polyPoints[lastIndex][1]);
        if (!points) {
          return;
        }
        var x1 = points[0],
          y1 = points[1],
          x2 = points[2],
          y2 = points[3],
          x3 = points[4],
          y3 = points[5];
        path.moveTo(x1, y1);
        path.lineTo(x2, y2);
        path.lineTo(x3, y3);
        break;
      }
    case 'style_arrow_both':
      {
        var points = getArrowPoints(polyPoints[1][0], polyPoints[1][1], polyPoints[0][0], polyPoints[0][1]);
        if (!points) {
          return;
        }
        var lx1 = points[0],
          ly1 = points[1],
          lx2 = points[2],
          ly2 = points[3],
          lx3 = points[4],
          ly3 = points[5];
        path.moveTo(lx1, ly1);
        path.lineTo(lx2, ly2);
        path.lineTo(lx3, ly3);
        var _a = getArrowPoints(polyPoints[lastIndex - 1][0], polyPoints[lastIndex - 1][1], polyPoints[lastIndex][0], polyPoints[lastIndex][1]),
          x1 = _a[0],
          y1 = _a[1],
          x2 = _a[2],
          y2 = _a[3],
          x3 = _a[4],
          y3 = _a[5];
        path.moveTo(x1, y1);
        path.lineTo(x2, y2);
        path.lineTo(x3, y3);
        break;
      }
    default:
      break;
  }
}
var PolyLinesPath = /** @class */function (_super) {
  __extends(PolyLinesPath, _super);
  // private _ctx: CanvasRenderingContext2D;
  function PolyLinesPath(opts) {
    return _super.call(this, opts) || this;
  }
  PolyLinesPath.prototype.getDefaultShape = function () {
    return new PolyLinesPathShape();
  };
  PolyLinesPath.prototype.buildPath = function (ctx, shape) {
    var points = shape.points,
      closed = shape.closed,
      curved = shape.curved,
      lineStyle = shape.lineStyle;
    var polyPoints = points;
    if (curved) {
      var controlPoints = smoothBezier(polyPoints, 0.8, closed);
      ctx.moveTo(polyPoints[0][0], polyPoints[0][1]);
      var len = polyPoints.length;
      for (var i = 0; i < (closed ? len : len - 1); i++) {
        var cp1 = controlPoints[i * 2];
        var cp2 = controlPoints[i * 2 + 1];
        var p = polyPoints[(i + 1) % len];
        ctx.bezierCurveTo(cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]);
      }
    } else {
      ctx.moveTo(polyPoints[0][0], polyPoints[0][1]);
      for (var i = 1, l = polyPoints.length; i < l; i++) {
        ctx.lineTo(polyPoints[i][0], polyPoints[i][1]);
      }
    }
    closed && ctx.closePath();
    drawArrow({
      lineStyle: lineStyle,
      path: ctx,
      polyPoints: polyPoints
    });
  };
  return PolyLinesPath;
}(graphic.Path);
export default PolyLinesPath;