
/*
* 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 { getArrowPoints, getDrawLine } from './util.js';
// const BOOST_SIZE_THRESHOLD = 4;
var LinesPathShape = /** @class */function () {
  function LinesPathShape() {}
  return LinesPathShape;
}();
function drawArrow(params) {
  var lineStyle = params.lineStyle,
    fromX = params.fromX,
    fromY = params.fromY,
    toX = params.toX,
    toY = params.toY,
    path = params.path;
  switch (lineStyle) {
    case 'style_arrow_left':
      {
        var points = getArrowPoints(toX, toY, fromX, fromY);
        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(fromX, fromY, toX, toY);
        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(toX, toY, fromX, fromY);
        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(fromX, fromY, toX, toY),
          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;
  }
}
// interface LineType {
//     path: PathProxy
//     fromX: number
//     fromY: number
//     toX: number
//     toY: number
//     extend: IExtent;
//     width: number;
//     height: number;
// }
// function drawLine(params: LineType) {
//     const { extend, fromX, fromY, toX, toY, path, height, width } = params;
//     const rect = {
//         left: 0,
//         bottom: 0,
//         top: height,
//         right: width,
//     };
//     switch (extend) {
//         case 'left': {
//             const pointC = findIntersectionPoint([fromX, fromY], [toX, toY], rect);
//             path.moveTo(pointC[0], pointC[1]);
//             path.lineTo(toX, toY);
//             break;
//         }
//         case 'right': {
//             const pointB = findIntersectionPoint([toX, toY], [fromX, fromY], rect);
//             path.moveTo(fromX, fromY);
//             path.lineTo(pointB[0], pointB[1]);
//             break;
//         }
//         case 'both': {
//             const pointC = findIntersectionPoint([fromX, fromY], [toX, toY], rect);
//             const pointB = findIntersectionPoint([toX, toY], [fromX, fromY], rect);
//             path.moveTo(pointC[0], pointC[1]);
//             path.lineTo(pointB[0], pointB[1]);
//             break;
//         }
//         default:
//             path.moveTo(fromX, fromY);
//             path.lineTo(toX, toY);
//             break;
//     }
// }
var LinesPath = /** @class */function (_super) {
  __extends(LinesPath, _super);
  // private _ctx: CanvasRenderingContext2D;
  function LinesPath(opts) {
    return _super.call(this, opts) || this;
  }
  LinesPath.prototype.getDefaultShape = function () {
    return new LinesPathShape();
  };
  LinesPath.prototype.buildPath = function (path, shape) {
    var points = shape.points,
      lineStyle = shape.lineStyle,
      extend = shape.extend,
      rectWidth = shape.rectWidth,
      rectHeight = shape.rectHeight,
      stroke = shape.stroke,
      isWebviewRender = shape.isWebviewRender;
    for (var i = 0; i < points.length;) {
      var x1 = points[i++];
      var y1 = points[i++];
      var x2 = points[i++];
      var y2 = points[i++];
      // path.moveTo(x1, y1);
      // path.lineTo(x2, y2);
      drawArrow({
        lineStyle: lineStyle,
        fromX: x1,
        fromY: y1,
        toX: x2,
        toY: y2,
        path: path
      });
      // drawLine({
      //     extend,
      //     fromX: x1,
      //     fromY: y1,
      //     toX: x2,
      //     toY: y2,
      //     path,
      //     width: rectWidth,
      //     height: rectHeight,
      //  });
      var _a = getDrawLine({
          extend: extend,
          startPoint: [x1, y1],
          endPoint: [x2, y2],
          width: rectWidth,
          height: rectHeight
        }),
        startPoint = _a[0],
        endPoint = _a[1];
      path.moveTo(startPoint[0], startPoint[1]);
      path.lineTo(endPoint[0], endPoint[1]);
      if (isWebviewRender && i % 5 === 0 && stroke) {
        path.strokeStyle(stroke);
        path.beginPathFill();
      }
    }
  };
  return LinesPath;
}(graphic.Path);
export default LinesPath;