
/*
* 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";
/**
 * Line path for bezier and straight line draw
 */
import * as graphic from '../../util/graphic.js';
// import { ColorString } from '../../util/types.js';
// const straightLineProto = graphic.Line.prototype;
// const bezierCurveProto = graphic.BezierCurve.prototype;
var FillPolyShape = /** @class */function () {
  function FillPolyShape() {
    this.points = [];
  }
  return FillPolyShape;
}();
// function isPointNull(point: number[] | number){
//     if (point instanceof Array) {
//         return isNaN(point[0]) || isNaN(point[1])
//     }
//     return false
// }
var FillPolyPath = /** @class */function (_super) {
  __extends(FillPolyPath, _super);
  function FillPolyPath(opts) {
    var _this = _super.call(this, opts) || this;
    _this.type = 'fillPoly';
    return _this;
  }
  FillPolyPath.prototype.getDefaultStyle = function () {
    return {
      stroke: 'none'
    };
  };
  FillPolyPath.prototype.getDefaultShape = function () {
    return new FillPolyShape();
  };
  FillPolyPath.prototype.buildPath = function (ctx, shape) {
    var points = shape.points,
      isWebviewRender = shape.isWebviewRender,
      fill = shape.fill;
    if (isWebviewRender && typeof fill === 'string') {
      var fillCount = 3;
      for (var index = 0; index < points.length; index++) {
        var polyPoints = points[index];
        var midIndex = polyPoints.length / 2;
        var startIndex = 0;
        for (var i = 0; i < midIndex; i++) {
          var _a = polyPoints[i],
            x = _a[0],
            y = _a[1];
          if (i === 0) {
            ctx.moveTo(x, y);
            continue;
          }
          ctx.lineTo(x, y);
          if (i % fillCount === 0) {
            for (var k = polyPoints.length - i - 1; k < polyPoints.length - startIndex; k++) {
              ctx.lineTo(polyPoints[k][0], polyPoints[k][1]);
            }
            ctx.closePath();
            ctx.fillStyle(fill);
            ctx.beginPathFill();
            ctx.moveTo(x, y);
            startIndex = i;
          } else if (i + 1 === midIndex) {
            for (var k = polyPoints.length - midIndex; k < polyPoints.length - i + (midIndex - startIndex - 1); k++) {
              ctx.lineTo(polyPoints[k][0], polyPoints[k][1]);
            }
            ctx.closePath();
            if (index !== points.length - 1) {
              ctx.fillStyle(fill);
              ctx.beginPathFill();
            }
          }
        }
      }
      return;
    }
    for (var index = 0; index < points.length; index++) {
      // ctx.beginPath();
      var polyPoints = points[index];
      for (var i = 0; i < polyPoints.length; i++) {
        var _b = polyPoints[i],
          x = _b[0],
          y = _b[1];
        if (i === 0) {
          ctx.moveTo(x, y);
          continue;
        }
        ctx.lineTo(x, y);
        if (i + 1 === polyPoints.length) {
          var _c = polyPoints[0],
            fx = _c[0],
            fy = _c[1];
          ctx.lineTo(fx, fy);
        }
      }
      // ctx.closePath();
    }
  };

  return FillPolyPath;
}(graphic.Path);
export default FillPolyPath;